[CDRIVER-2328] "member access within misaligned address" in _mongoc_rpc_scatter for OP_MSG Created: 14/Oct/17  Updated: 28/Oct/23  Resolved: 25/Oct/17

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 1.9.0
Fix Version/s: 1.9.0

Type: Bug Priority: Minor - P4
Reporter: A. Jesse Jiryu Davis Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

After implementing OP_MSG in the mock server we now do _mongoc_rpc_scatter on OP_MSG. (That's for parsing OP_MSG; before, we had only generated OP_MSG.) This has triggered a warning when executing with clang's undefined behavior sanitizer:

 [2017/10/14 12:07:53.085] Begin /Cluster/cluster_time/query/, seed 3682232949
 [2017/10/14 12:07:53.085] src/mongoc/op-msg.def:1:1: runtime error: member access within misaligned address 0x7fd2b4000e94 for type 'mongoc_rpc_section_t' (aka 'struct _mongoc_rpc_section_t'), which requires 8 byte alignment
 [2017/10/14 12:07:53.085] 0x7fd2b4000e94: note: pointer points here
 [2017/10/14 12:07:53.086]   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00

The error occurs on the second of these two lines (part of the macro that defines _mongoc_rpc_scatter_msg):

      mongoc_rpc_section_t *section = &rpc->_name[rpc->n_##_name]; \
      section->payload_type = buf[0];                              \

The mongoc_rpc_section_t struct is defined with pragma pack(1) which seems unnecessary, and the cause of this warning. Can we just not override the default packing when defining this struct and the other wire protocol structs?

https://evergreen.mongodb.com/task_log_raw/mongo_c_driver_clang38_debug_compile_sanitizer_undefined_506e36a96b713822214eda939ff31df90f1aa615_17_10_14_13_31_38/0?type=T



 Comments   
Comment by Githook User [ 04/Jan/18 ]

Author:

{'name': 'A. Jesse Jiryu Davis', 'username': 'ajdavis', 'email': 'jesse@mongodb.com'}

Message: CDRIVER-2328 restore UBSAN test
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/681f3f7722bed018a486ccbc4a8246d9e7f38561

Comment by Githook User [ 25/Oct/17 ]

Author:

{'email': 'jesse@mongodb.com', 'name': 'A. Jesse Jiryu Davis', 'username': 'ajdavis'}

Message: CDRIVER-2328 default packing for OP_MSG struct
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/c21b8863db1a521a82c5e1076a69450bee36efc1

Comment by Githook User [ 15/Oct/17 ]

Author:

{'email': 'jesse@mongodb.com', 'name': 'A. Jesse Jiryu Davis', 'username': 'ajdavis'}

Message: CDRIVER-2328 disable clang undefined sanitizer
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/365ab96360cf98c25fa5f619713e118cbb88e03c

Comment by Githook User [ 14/Oct/17 ]

Author:

{'email': 'jesse@mongodb.com', 'name': 'A. Jesse Jiryu Davis', 'username': 'ajdavis'}

Message: CDRIVER-2328 disable USBSan test for now
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/e4f9bea90cc990459636dbb1b3e28201aed75500

Generated at Wed Feb 07 21:14:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.