Fix Out of bounds compilation warning in OCTET8

The code in OCTET8 implementation assumes the len is placed inside the
byte preceding the memory buffer, which is true for the defined cases.
However, it creates a compilation warning. Better pass the value
directly from the struct field rather than playing addr games. this way
we also assert we require to explicitly pass the len.

Fixes lots of warning like the one below:
/home/pespin/dev/sysmocom/bin/../git/libsmpp34/src/smpp34_unpack.c: In function ‘smpp34_u
npack’:
/home/pespin/dev/sysmocom/bin/../git/libsmpp34/src/smpp34_unpack.c:147:14: warning: array
 subscript is above array bounds [-Warray-bounds]
     lenval = *((inst par) - 1);\
              ^~~~~~~~~~~~~~~~~
/home/pespin/dev/sysmocom/bin/../git/libsmpp34/def_frame/submit_sm.frame:18:2: note: in e
xpansion of macro ‘OCTET8’
  OCTET8( instancia, short_message, 254 );
  ^~~~~~

Change-Id: Id110f4e977c3becdb44cf5492c372e530ea51551
This commit is contained in:
Pau Espin 2017-09-15 20:09:19 +02:00
parent cbdde82aca
commit c63971fab0
8 changed files with 8 additions and 11 deletions

View File

@ -15,5 +15,5 @@ C_OCTET( instancia, validity_period, 1 );
U08( instancia, data_coding, valueDec_08 );
U08( instancia, sm_default_msg_id, valueDec_08 );
U08( instancia, sm_length, valueDec_08 );
OCTET8( instancia, short_message, 254 );
OCTET8( instancia, short_message, 254, instancia sm_length );
TLV( instancia, tlv, do_tlv_deliver_sm );

View File

@ -7,4 +7,4 @@ C_OCTET( instancia, validity_period, 17 );
U08( instancia, registered_delivery, valueDec_08 );
U08( instancia, sm_default_msg_id, valueDec_08 );
U08( instancia, sm_length, valueDec_08 );
OCTET8( instancia, short_message, 254 );
OCTET8( instancia, short_message, 254, instancia sm_length );

View File

@ -14,5 +14,5 @@ C_OCTET( instancia, validity_period, 17 );
U08( instancia, data_coding, valueDec_08 );
U08( instancia, sm_default_msg_id, valueDec_08 );
U08( instancia, sm_length, valueDec_08 );
OCTET8( instancia, short_message, 254 );
OCTET8( instancia, short_message, 254, instancia sm_length );
TLV( instancia, tlv, do_tlv_submit_multi );

View File

@ -15,5 +15,5 @@ C_OCTET( instancia, validity_period, 17 );
U08( instancia, data_coding, valueDec_08 );
U08( instancia, sm_default_msg_id, valueDec_08 );
U08( instancia, sm_length, valueDec_08 );
OCTET8( instancia, short_message, 254 );
OCTET8( instancia, short_message, 254, instancia sm_length );
TLV( instancia, tlv, do_tlv_submit_sm );

View File

@ -136,11 +136,10 @@ smpp34_dumpPdu(uint32_t type, uint8_t *dest, int size_dest, void* tt)
_op(inst, par, size )\
}
#define OCTET8( inst, par, size ){\
#define OCTET8( inst, par, size, lenval ){\
int i = 0;\
uint8_t *p = l_dest;\
int dummy = 0;\
lenval = *((inst par) - 1);\
if( (lenval + 33) >= left ){\
PUTLOG("[%s:%s(%s)]", par, inst par, \
"Value length exceed buffer length");\

View File

@ -139,8 +139,7 @@ smpp34_pack(uint32_t type, uint8_t *ptrBuf, int ptrSize, int *ptrLen, void* tt)
}\
};
#define OCTET8( inst, par, sizeval ){\
lenval = *((inst par) - 1);\
#define OCTET8( inst, par, sizeval, lenval ){\
if( lenval >= left ){\
PUTLOG("[leng %s:%d(%s)]", par, lenval,\
"Value length exceed buffer length");\

View File

@ -75,7 +75,7 @@ typedef struct alert_notification_t alert_notification_t;
#define O_C_OCTET( inst, par, size ) uint8_t par[ size ];
#define C_OCTET( inst, par, size ) uint8_t par[ size ];
#define OCTET8( inst, par, size ) uint8_t par[ size ];
#define OCTET8( inst, par, size, lenval ) uint8_t par[ size ];
#define OCTET16( inst, par, size ) uint8_t par[ size ];
#define TLV( inst, par, do_tlv ) tlv_t *par;

View File

@ -143,8 +143,7 @@ smpp34_unpack(uint32_t type, void* tt, const uint8_t *ptrBuf, int ptrLen)
};\
}
#define OCTET8( inst, par, size ){\
lenval = *((inst par) - 1);\
#define OCTET8( inst, par, size, lenval ){\
if( lenval > left ){\
PUTLOG("[leng %s:%d(%s)]", par, lenval,\
"Value length exceed buffer length");\