Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

readlink() never 0-terminates by itself, so you have to do it by yourself. People often seem to forget this, leading to infoleaks or sometimes memory corruption. Another thing people like to do is

Code Block
bgColor#FFcccc
len = readlink(link, buf, sizeof(buf));
buf[len] = '\0';

...

Compliant Solution

Code Block
bgColor#ccccff
#include <unistd.h>

char buf[1024];
ssizet_t len;
...
if ((len = readlink("/modules/pass1", buf, sizeof(buf)-1)) != -1)
    buf[len] = '\0';

...