Most common security flaws with C programs

You should read Secure Programming HOWTO. Here's the most common problems with non-suid/sgid programs:

Some examples

Signedness

char *buf;
int i, len;

read(fd, &len, sizeof(len));

/* we forgot to check for < 0 */
if (len > 8000) { error("too large length"); return; }

buf = malloc(len);
read(fd, buf, len); /* len casted to unsigned and overflows */

Integer truncating

For 64bit architectures:

void *mymalloc(unsigned int size) { return malloc(size); }

char *buf;
size_t len;

read(fd, &len, sizeof(len));

/* we forgot to check the maximum length */

/* 64bit size_t gets truncated to 32bit unsigned int */
buf = mymalloc(len);
read(fd, buf, len);

Integer overflow

char *buf;
size_t len;

read(fd, &len, sizeof(len));

/* we forgot to check the maximum length */

buf = malloc(len+1); /* +1 can overflow to malloc(0) */
read(fd, buf, len);
buf[len] = '\0';