[SERVER-8091] uninitialised value in OID object due to bad struct alignment Created: 07/Jan/13  Updated: 15/Feb/13  Resolved: 08/Jan/13

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: 2.2.0
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Eric Nashil Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

gcc 4.4.5, boost 1.42, debian 6 64bits


Operating System: ALL
Steps To Reproduce:

All details and a simple minimalist program to exhibit the problem can be found here:
http://stackoverflow.com/questions/14186246/valgrind-reports-uninitialised-value-in-bsonobjtostring-with-a-simple-bson-obj

Try using a "sizeof" operator on the union types to see the alignment problem.

Participants:

 Description   

The union used in the definition of the OID object (oid.h) is not properly aligned and leads to "uninitialized value" in valgrind and not expected behavior. This is critical because mongodb C++ driver OID data is broken.

More on data alignment here: http://en.wikipedia.org/wiki/Data_structure_alignment



 Comments   
Comment by Eric Nashil [ 07/Jan/13 ]

The valgrind report is nevertheless here, so I would think it might be a false positive of valgrind due to the complex nature of the packed union of structs. I think the issue can be closed, there is not much that can be done and it is not a bug from mongodb.

Comment by Eric Nashil [ 07/Jan/13 ]

Update: it seems gcc says that #pragma pack is indeed supported, my bad: http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html

Comment by Eric Nashil [ 07/Jan/13 ]

the #pragma directive is specific to Visual C++ and would be ignored on linux with gcc. You should use use _attribute_((packed)) in that case. More here:
http://grok2.tripod.com/structure_packing.html

NB: the code sample in the stackoverflow link above is standalone and reproduces the problem with gcc 4.4.5, boost 1.42 on a debian 6 64bits.
http://stackoverflow.com/questions/14186246/valgrind-reports-uninitialised-value-in-bsonobjtostring-with-a-simple-bson-obj

Comment by Eliot Horowitz (Inactive) [ 07/Jan/13 ]

The OID class has a #pragma pack(1), so it is 12 bytes.

I tried the example you gave, but didn't give any valgrind errors.

Can you send the full source code?

Generated at Thu Feb 08 03:16:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.