]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: theoretical buffer overflow
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 26 Oct 2014 17:41:24 +0000 (18:41 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 18 Nov 2014 10:38:21 +0000 (11:38 +0100)
there is a theoretical buffer overflow possible in the hypervisor
parsing code of lscpu.  It would require a proc entry to return way more
than expected so it's no high priority.  But better be safe than sorry.

At first I thought about switching to fgets but there is another
code file that adds a format specifier.  The diff is less intrusive
that way, too.

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu.c

index ef594108833fa94c36c7e3907640daea68f386fb..c272dc238ac58fa9c0d90d75fcfa719c6d53a8f4 100644 (file)
@@ -621,7 +621,7 @@ read_hypervisor_powerpc(struct lscpu_desc *desc)
                fd = path_fopen("r", 0, _PATH_PROC_DEVICETREE "/ibm,partition-name");
                if (fd) {
                        char buf[256];
-                       if (fscanf(fd, "%s", buf) == 1 && !strcmp(buf, "full"))
+                       if (fscanf(fd, "%255s", buf) == 1 && !strcmp(buf, "full"))
                                desc->virtype = VIRT_NONE;
                        fclose(fd);
                }
@@ -757,7 +757,7 @@ read_hypervisor(struct lscpu_desc *desc, struct lscpu_modifier *mod)
                if (fd) {
                        char buf[256];
 
-                       if (fscanf(fd, "%s", buf) == 1 &&
+                       if (fscanf(fd, "%255s", buf) == 1 &&
                            !strcmp(buf, "control_d"))
                                dom0 = 1;
                        fclose(fd);