]> 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:44:32 +0000 (14:44 +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 80fc50d3f04b4655451cb56ae2be1d4197242175..e4dfe19f0844ac38d8316072ddeea01610af9e3f 100644 (file)
@@ -561,7 +561,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 b5cde272302e6ea29a5034eb06632a0c8a12ee8b..8829098aa4e153756e3ebe56ab977db1e70d32f3 100644 (file)
@@ -966,7 +966,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");
@@ -1008,9 +1008,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++)