Re: memcmp() checker: memory access errors



malc <malc@xxxxxxxxxxxxx> wrote:

"kolmogolov@xxxxxxxxx" <kolmogolov@xxxxxxxxx> writes:

[..snip..]

int probe_img(FILE *fp)
{
unsigned char *data;
unsigned char KDF_header[4]={0x01, 0x03, 0x13, 0x5E};
int probe_len = 256;
int type=-1;

data = malloc( probe_len );
assert ( NULL != data );
assert ( 1 == fread(data, probe_len, 1, fp) );

if ( !memcmp(data, KDF_header, 4) )
{
type = 3;
}

return type;
}

There's a memory leak here. But as far as i can see that's not what
checker complains about.

Doesn't even get there. I'm beginning to suspect that what Checker
checked is not the posted code.

And excessive reading of 256 bytes where you really need 4 should be
self evident.

Not necessarily; if the rest of the header is needed by the rest of the
function, which just happens not to be written yet, it may be the right
size to read for the (as yet to be) completed code.

Richard
.



Relevant Pages