From: Karel Zak Date: Tue, 4 Sep 2018 11:12:34 +0000 (+0200) Subject: lscpu: make xasprintf call more robust X-Git-Tag: v2.33-rc1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0b75b03bca36ed8a548655bba74297996cd69a6;p=thirdparty%2Futil-linux.git lscpu: make xasprintf call more robust Signed-off-by: Karel Zak --- diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 122acca1ac..57f097dae8 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -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 == ' ')