Hello,

I just created a patch for this that seems to fix the crash, but I have no idea 
if I'm doing it in the correct way. Basically, the idea is to leave cpu_hz_max 
uninitialized if we can't find the information.

So, could somebody comment on this patch:

diff --git a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c 
b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
index 2ef49e4..3d186d2 100644
--- a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
+++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
@@ -24,10 +24,13 @@ int odp_cpuinfo_parser(FILE *file, odp_system_info_t 
*sysinfo)
                                sizeof(sysinfo->model_str[id]) - 1);
                        pos = strchr(sysinfo->model_str[id], '@');
-                       *(pos - 1) = '\0';
-                       if (sscanf(pos, "@ %lfGHz", &ghz) == 1) {
-                               hz = (uint64_t)(ghz * 1000000000.0);
-                               sysinfo->cpu_hz_max[id] = hz;
+                       if (pos)
+                       {
+                               *(pos - 1) = '\0';
+                               if (sscanf(pos, "@ %lfGHz", &ghz) == 1) {
+                                       hz = (uint64_t)(ghz * 1000000000.0);
+                                       sysinfo->cpu_hz_max[id] = hz;
+                               }
                        }
                        id++;
                }

I found that the code has been originally written by Hongbo Zhang. I can 
prepare a patch suitable for "git am", if people agree that my way is the right 
way of doing this.

From: lng-odp [mailto:[email protected]] On Behalf Of EXT Tilli, 
Juha-Matti (Nokia - FI/Espoo)
Sent: Tuesday, March 29, 2016 2:23 PM
To: [email protected]
Subject: [lng-odp] No "@" in CPU string causes ODP to crash

Hi,

My coworker recently had an ODP crash (he used the most recent api-next), 
apparently related to not having "@" in CPU string. The CPU string is:

$ cat /proc/cpuinfo |grep Xeon|uniq -c
      8 model name      : Intel Xeon E312xx (Sandy Bridge)

This is a virtualized environment (KVM running on CentOS).

The segfault happens at the second of these two lines in odp_cpuinfo_parser:

                        pos = strchr(sysinfo->model_str[id], '@');
                        *(pos - 1) = '\0';

So, should this odp_cpuinfo_parser be modified to work even in cases that there 
is no "@" in the CPU string?

I would submit a patch, but I'm not entirely sure how the code should be fixed. 
It seems incorrect in assuming that strchr always finds a match.

_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to