Bug 53690 - Calls to semctl() trigger "uninitialized memory" warning from valgrind
Summary: Calls to semctl() trigger "uninitialized memory" warning from valgrind
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Core (show other bugs)
Version: 2.4.2
Hardware: All Linux
: P3 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Keywords: FixedInTrunk, PatchAvailable
Depends on:
Reported: 2012-08-09 22:51 UTC by Mikhail T.
Modified: 2013-02-04 20:15 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Mikhail T. 2012-08-09 22:51:05 UTC
The warnings looks like this:
==977== Syscall param semctl(IPC_SET, arg.buf) points to uninitialised byte(s)
==977==    at 0x62FA8EA: semctl (in /lib64/libc-2.5.so)
==977==    by 0x18705C: ap_unixd_set_proc_mutex_perms (unixd.c:251)
==977==    by 0x1870E0: ap_unixd_set_global_mutex_perms (unixd.c:284)
==977==    by 0x16FC19: ap_global_mutex_create (util_mutex.c:444)
==977==    by 0xAE3D17A: rewritelock_create (mod_rewrite.c:2594)
==977==    by 0xAE41730: post_config (mod_rewrite.c:4316)
==977==    by 0x15F4B3: ap_run_post_config (config.c:105)
==977==    by 0x1365C5: main (main.c:696)
==977==  Address 0x7ff000430 is on thread 1's stack
==977==  Uninitialised value was created by a stack allocation
==977==    at 0x186FB1: ap_unixd_set_proc_mutex_perms (unixd.c:227)

Because the semid_ds structure on Linux (as well as FreeBSD and, likely, other Unixes) contains some undocumented fields (such as __unused1 or sem_pad2), explicitly setting each one is not portable -- far simpler to just request, that the entire structure be zeroed at the declaration time:

--- os/unix/unixd.c        2011-12-18 13:02:21.000000000 -0500
+++ os/unix/unixd.c     2012-08-09 18:40:55.000000000 -0400
@@ -242,5 +242,5 @@
             union semun ick;
-            struct semid_ds buf;
+            struct semid_ds buf = { 0 };
             apr_os_proc_mutex_get(&ospmutex, pmutex);

While the warning is benign, it is better to suppress it, then to needlessly worry people attempting to use valgrind to debug some other problem -- the fewer such false alarms, the better.

Earlier releases of httpd have the same issue (I've seen it in 2.2.22 myself).
Comment 1 Jeff Trawick 2012-08-09 23:19:09 UTC
with that I get 

unixd.c: In function ‘ap_unixd_set_proc_mutex_perms’:
unixd.c:244:20: warning: missing braces around initializer [-Wmissing-braces]
unixd.c:244:20: warning: (near initialization for ‘buf.sem_perm’) [-Wmissing-braces]
Comment 2 Mikhail T. 2012-08-10 02:16:20 UTC
(In reply to comment #1)
> unixd.c: In function ‘ap_unixd_set_proc_mutex_perms’:
> unixd.c:244:20: warning: missing braces around initializer [-Wmissing-braces]

Yeah, the first field of the semid_ds-structure is also a structure (at least on Linux and FreeBSD), so using two layers of braces should work:

     struct semid_ds buf = {{ 0 }};

If that's not portable enough, then bzero() might be in order:

     bzero(&buf, sizeof(buf));

however annoying it might be to have a function-call (even if compiler will optimize it away) just to zero-out an automatic variable :-(
Comment 3 Stefan Fritsch 2013-02-04 20:15:27 UTC
committed to trunk as r1442326