1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-26 14:04:03 +03:00

remove buffer-overrun risk in readlink call

readlink does not write a nul character to the end of the
string it returns. Therefore ask for one fewer character
than the buffer size so there's always room for an extra \0.

Signed-off-by: Mathias Nyman <mathias.nyman@nokia.com>
Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
This commit is contained in:
Mathias Nyman 2010-04-21 13:52:52 +03:00 committed by Martin Pitt
parent c51d2f2746
commit e925018786

View File

@ -163,7 +163,7 @@ static int node_symlink(struct udev *udev, const char *node, const char *slink)
int len; int len;
dbg(udev, "found existing symlink '%s'\n", slink); dbg(udev, "found existing symlink '%s'\n", slink);
len = readlink(slink, buf, sizeof(buf)); len = readlink(slink, buf, sizeof(buf) - 1);
if (len > 0) { if (len > 0) {
buf[len] = '\0'; buf[len] = '\0';
if (strcmp(target, buf) == 0) { if (strcmp(target, buf) == 0) {