ECCC-MSC / libecbufr

libecbufr is a general purpose, template-oriented BUFR encoding/decoding library
Other
10 stars 7 forks source link

memory leaks in bufr_seek_msg_start() #26

Closed vsouvan closed 4 years ago

vsouvan commented 4 years ago

Any attempt to read an invalid BUFR message will cause the function to return without freeing the allocated memory first.

Here is the Bug report from Dan Shea:

Vanh or Chris, I was performing some tests on my libncawos. If I pass a char

static int bufr_seek_msg_start( bufr_read_callback readcb, void *cd, char *tagstr ) { unsigned char c; int notfound=1; char str; int i, tagsize;

tagsize = 64; str = (char )malloc( (tagsize+1) sizeof(char) ); i = 0;

    if( bufr_read_octet( readcb, cd, &c ) != 1 ) return -1; 

if ( c != '\004' ) append_char_to_string( &str, &tagsize, &i, c ); while ( notfound ) { while ( (c != 'B') ) { if( bufr_read_octet( readcb, cd, &c ) != 1 ) return - 1;

What valgrind is reporting.

==21330== 65 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==21330== at 0x401C38B: malloc (vg_replace_malloc.c:149) ==21330== by 0x4033375: bufr_seek_msg_start (in /home/shead/ncawosBufrDecoder/lib/libecbufr.so.0.7.3) ==21330== by 0x403377A: bufr_callback_read_message (in /home/shead/ncawosBufrDecoder/lib/libecbufr.so.0.7.3) ==21330== by 0x4034B18: bufr_memread_message (in /home/shead/ncawosBufrDecoder/lib/libecbufr.so.0.7.3) ==21330== by 0x804AC9B: getMessage (ParseBufr.c:172) ==21330== by 0x804D90C: bufrDecode (BufrDecoder.c:59) ==21330== by 0x804A60F: main (testDecoder.c:73)


Imported from Launchpad using lp2gh.

vsouvan commented 4 years ago

(by vanh-souvanlasy) All return from function will free allocated memory first before exiting