Make sure cmdline string always is null terminated, even if it is very long (Coverity...
authorPetter Reinholdtsen <pere@hungry.com>
Sun, 26 Jan 2014 13:29:43 +0000 (13:29 +0000)
committerPetter Reinholdtsen <pere@hungry.com>
Sun, 26 Jan 2014 13:29:43 +0000 (13:29 +0000)
git-svn-id: svn://svn.sv.gnu.org/sysvinit/sysvinit/trunk@132 456724a4-4300-0410-8514-c89748c515a2

src/bootlogd.c

index 9343997d5fe3a92d1a54be93afe5640ac8d2bb80..f6c8716d00fa672290d32e8bc7751d3f14f188e4 100644 (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);
        }