[erlang-questions] R13B01: erts_cpu_info_update() "int mib[0];" + sysctl call trashes stack
Mikael Pettersson
mikpe@REDACTED
Tue Jul 28 18:00:04 CEST 2009
Michael Turner writes:
> I'm trying to build R13B01. I was getting seg faults on erlexec.
> Bringing it up in gdb just gave me "No stack."
>
> Hours (and *hours*) later: I've traced it to the following in
> erl_misc_utils.c
>
> {
> int mib[0];
> size_t len;
> ....
>
> Yes, that's legal (according to gcc, anyway). Even useful for some
> things.
>
> http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Zero-Length.html
>
> In this context, however, it should be "int mib[2];" The problem is
> that there are assignments to mib[0] and mib[1] immediately following,
> clobbering some context.
>
> So, uh . . . this is the questions list, so I have a question after all:
> where do I report this as a bug? And suggest this fix? And all that?
> I'm pretty new to this.
On what platform does this code get compiled? I would have expected
recent GCCs to complain about the out-of-bounds indexing, but perhaps
it doesn't get compiled on Linux.
Anyway, you have indeed found a real bug. The code in question is
utterly wrong.
Proper bug reporting procedure is to send an email to the erlang-bugs
mailing list, together with Erlang version information, platform information
(in case the bug is platform specific), and whatever analysis you've done
or test cases you've written. Suggested code changes should be in `patch -p1'
form as produced by `diff -up` or its equivalent. For this particular case,
it should look as follows:
--- otp_src_R13B01/erts/lib_src/common/erl_misc_utils.c.~1~ 2009-06-05 14:53:41.000000000 +0200
+++ otp_src_R13B01/erts/lib_src/common/erl_misc_utils.c 2009-07-28 17:53:03.000000000 +0200
@@ -172,7 +172,7 @@ erts_cpu_info_update(erts_cpu_info_t *cp
#elif defined(HAVE_SYS_SYSCTL_H) && defined(CTL_HW) && (defined(HW_NCPU) \
|| defined(HW_AVAILCPU))
{
- int mib[0];
+ int mib[2];
size_t len;
#ifdef HW_NCPU
/Mikael
More information about the erlang-questions
mailing list