libcruft/sysconf_cpus.c patch
Bela Lubkin <[email protected]> Mon, 22 Nov 2010 18:59:05 -0800
| Newsgroups | gmane.linux.lib.dietlibc |
|---|---|
| Message-ID | <[email protected]> |
__sc_nr_cpus() [ == sysconf(_SC_NPROCESSORS_ONLN) ] can run off the end
of its /proc/cpuid buffer and (depending on process memory layout) dump
core. This caused an intermittent dump in diet `x86info`.
This will still get a wrong answer if "processor" or one of the
other-arch strings happens to get cut by the buffer end. Not important
for my application. I would suggest a malloc'd buffer the full stat'd
size of /proc/cpuid, but that seems a bit scary with 160-core x86 boxes
running around out there this year...
>Bela<
--- libcruft/sysconf_cpus.c.orig 2007-08-24 14:19:33.000000000 -0700
+++ libcruft/sysconf_cpus.c 2010-11-22 18:46:44.831735537 -0800
@@ -50,7 +50,7 @@ int __sc_nr_cpus() {
i+=9;
}
#endif
- while(buf[i++]!='\n'); /* skip rest of line */
+ while(i<n && buf[i++]!='\n'); /* skip rest of line */
}
}
close(fd);