I have this code and run it with Flawinder, and i get this output on the read() functions:
Check buffer boundaries if used in a loop including recursive loops
Can anyone see the problem?
#include <stdlib.h>
void func(int fd)
{
char *buf;
size_t len;
read(fd, &len, sizeof(len));
if (len > 1024)
return;
buf = malloc(len+1);
read(fd, buf, len);
buf[len] = '\0';
}
you should check the return value of
read()to know whether call toread()was success or failure or ifread()was interrupted by a signal then set theerrno. For e.gMost importantly here
read()returns the number of bytes read, so instead of thisuse
Sample Code