]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: fix NULL dereference
authorKarel Zak <kzak@redhat.com>
Fri, 30 Jul 2021 12:35:25 +0000 (14:35 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 30 Jul 2021 12:35:25 +0000 (14:35 +0200)
Fixes: https://github.com/karelzak/util-linux/issues/1401
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu-cputype.c
sys-utils/lscpu.c

index 795a4acf5d52dfa61871177a7e9a7f61513bdc0f..be16199e06fa1374722baaca8a8fa4fff3caacdf 100644 (file)
@@ -569,7 +569,7 @@ int lscpu_read_cpuinfo(struct lscpu_cxt *cxt)
        /* Set the default type to CPUs which are missing (or not parsed)
         * in cpuinfo */
        ct = lscpu_cputype_get_default(cxt);
-       for (i = 0; i < cxt->npossibles; i++) {
+       for (i = 0; ct && i < cxt->npossibles; i++) {
                struct lscpu_cpu *cpu = cxt->cpus[i];
 
                if (cpu && !cpu->type)
index 827e84a6d1fa2a60d9b1212eab26212f778a0782..e11b2f42f08e5881bb48d81a7c4358560e76abe7 100644 (file)
@@ -991,7 +991,7 @@ static void print_summary(struct lscpu_cxt *cxt)
                *(p - 2) = '\0';
                add_summary_s(tb, sec, _("CPU op-mode(s):"), buf);
        }
-       if (ct->addrsz)
+       if (ct && ct->addrsz)
                add_summary_s(tb, sec, _("Address sizes:"), ct->addrsz);
 #if !defined(WORDS_BIGENDIAN)
        add_summary_s(tb, sec, _("Byte Order:"), "Little Endian");
@@ -1033,9 +1033,9 @@ static void print_summary(struct lscpu_cxt *cxt)
        sec = NULL;
 
        /* Section: cpu type description */
-       if (ct->vendor)
+       if (ct && ct->vendor)
                sec = add_summary_s(tb, NULL, _("Vendor ID:"), ct->vendor);
-       if (ct->bios_vendor)
+       if (ct && ct->bios_vendor)
                add_summary_s(tb, sec, _("BIOS Vendor ID:"), ct->bios_vendor);
 
        for (i = 0; i < cxt->ncputypes; i++)