Sasha,

This patch is based on a code inspection of ibsysstat.c due to the buffer overflow observed with more than 2 CPUs. It fixes a couple of latent bugs although won't improve that particular issue.

-- Hal
infiniband-diags/ibsysstat.c: Fix latent bugs related to build_cpuinfo
(exceeding MAX_CPUS and not being able to open /proc/cpuinfo)
Also, issue warning when cpuinfo is truncated due to lack of room

Signed-off-by: Hal Rosenstock <[EMAIL PROTECTED]>

diff --git a/infiniband-diags/src/ibsysstat.c b/infiniband-diags/src/ibsysstat.c
index 2418c9e..299e293 100644
--- a/infiniband-diags/src/ibsysstat.c
+++ b/infiniband-diags/src/ibsysstat.c
@@ -100,8 +100,10 @@ mk_reply(int attr, void *data, int sz)
                for (i = 0; i < host_ncpu && sz > 0; i++) {
                        n = snprintf(s, sz, "cpu %d: model %s MHZ %s\n",
                                     i, cpus[i].model, cpus[i].mhz);
-                       if (n >= sz)
+                       if (n >= sz) {
+                               IBWARN("cpuinfo truncated");
                                break;
+                       }
                        sz -= n;
                        s += n;
                }
@@ -187,14 +189,16 @@ build_cpuinfo(void)
        FILE *f;
        int ncpu = 0;
 
-       if (!(f = fopen("/proc/cpuinfo", "r")))
-               return -1;
+       if (!(f = fopen("/proc/cpuinfo", "r"))) {
+               IBWARN("couldn't open /proc/cpuinfo");
+               return 0;
+       }
 
        while (fgets(line, sizeof(line) - 1, f)) {
                if (!strncmp(line, "processor\t", 10)) {
                        ncpu++;
                        if (ncpu > MAX_CPUS)
-                               return ncpu;
+                               return MAX_CPUS;
                        continue;
                }
 
_______________________________________________
general mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to