]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: make min/max freq arrays usage more robust
authorKarel Zak <kzak@redhat.com>
Thu, 1 Jun 2017 10:15:23 +0000 (12:15 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 1 Jun 2017 10:15:23 +0000 (12:15 +0200)
The array members may be NULL on some architectures (e.g. AMD). Let's
be paranoid and check for the NULL independently on present/online
masks.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1457744
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu.c

index dc998267a83e70449a2f744927e42d55b49c303e..3b549a7a0c25832be0c54cd38bd87ef97993a816 100644 (file)
@@ -1264,7 +1264,8 @@ cpu_max_mhz(struct lscpu_desc *desc, char *buf, size_t bufsz)
 
        if (desc->present) {
                for (i = 1; i < desc->ncpuspos; i++) {
-                       if (CPU_ISSET(real_cpu_num(desc, i), desc->present)) {
+                       if (CPU_ISSET(real_cpu_num(desc, i), desc->present)
+                           && desc->maxmhz[i]) {
                                float freq = atof(desc->maxmhz[i]);
 
                                if (freq > cpu_freq)
@@ -1285,7 +1286,8 @@ cpu_min_mhz(struct lscpu_desc *desc, char *buf, size_t bufsz)
 
        if (desc->present) {
                for (i = 1; i < desc->ncpuspos; i++) {
-                       if (CPU_ISSET(real_cpu_num(desc, i), desc->present)) {
+                       if (CPU_ISSET(real_cpu_num(desc, i), desc->present)
+                           && desc->minmhz[i]) {
                                float freq = atof(desc->minmhz[i]);
 
                                if (freq < cpu_freq)
@@ -1597,11 +1599,11 @@ get_cell_data(struct lscpu_desc *desc, int idx, int col,
                                 is_cpu_online(desc, cpu) ? _("yes") : _("no"));
                break;
        case COL_MAXMHZ:
-               if (desc->maxmhz)
+               if (desc->maxmhz && desc->maxmhz[idx])
                        xstrncpy(buf, desc->maxmhz[idx], bufsz);
                break;
        case COL_MINMHZ:
-               if (desc->minmhz)
+               if (desc->minmhz && desc->minmhz[idx])
                        xstrncpy(buf, desc->minmhz[idx], bufsz);
                break;
        }