Make sure cmdline string always is null terminated, even if it is very long (Coverity CID 1164484).

This commit is contained in:
Petter Reinholdtsen 2014-01-26 13:29:43 +00:00
parent 1c9808ec42
commit ae7c73ec7f

View File

@ -303,9 +303,10 @@ int consolename(char *res, size_t rlen)
perror("bootlogd: /proc/cmdline");
} else {
buf[0] = 0;
if ((n = read(fd, buf, sizeof(buf) - 1)) >= 0)
if ((n = read(fd, buf, sizeof(buf) - 1)) >= 0) {
r = 0;
else
buf[sizeof(buf)-1] = 0; /* enforce null termination */
} else
perror("bootlogd: /proc/cmdline");
close(fd);
}