The readlink()
function reads where a link points to. It is unusual, as makes no effort to null terminate its second argument, buffer
. Instead, it just returns the number of characters it has written.
...
Code Block | ||
---|---|---|
| ||
char buf[256]; ssizet_t len; if ((len = readlink("/usr/bin/perl", buf, sizeof(buf)-1)) != -1) buf[len] = '\0'; else { /* handle error condition */ } |
Risk Analysis
This is a fairly easy mistake to make. Fortunately the consequences are not that harsh, most likely resulting Failing to properly terminate the result of readlink()
can result in abnormal program termination.
...