]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: make xasprintf call more robust
authorKarel Zak <kzak@redhat.com>
Tue, 4 Sep 2018 11:12:34 +0000 (13:12 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 4 Sep 2018 11:12:34 +0000 (13:12 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu.c

index 122acca1ac84402246c7d6979b18140287c05888..57f097dae8f9579934fef4be8b557da28b9ec48a 100644 (file)
@@ -837,7 +837,7 @@ read_hypervisor(struct lscpu_desc *desc, struct lscpu_modifier *mod)
                desc->hypervisor = "PR/SM";
                desc->virtype = VIRT_FULL;
                while (fgets(buf, sizeof(buf), fd) != NULL) {
-                       char *str;
+                       char *str, *p;
 
                        if (!strstr(buf, "Control Program:"))
                                continue;
@@ -845,10 +845,10 @@ read_hypervisor(struct lscpu_desc *desc, struct lscpu_modifier *mod)
                                desc->hyper = HYPER_IBM;
                        else
                                desc->hyper = HYPER_KVM;
-                       str = strchr(buf, ':');
-                       if (!str)
+                       p = strchr(buf, ':');
+                       if (!p)
                                continue;
-                       xasprintf(&str, "%s", str + 1);
+                       xasprintf(&str, "%s", p + 1);
 
                        /* remove leading, trailing and repeating whitespace */
                        while (*str == ' ')