Re: memcmp() checker: memory access errors



"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.

[..snip..]

P.S. Dangerous usage of `assert' is addressed in the reply by Richard Bos.
And excessive reading of 256 bytes where you really need 4 should be
self evident.

--
vale
.



Relevant Pages