eclipse-iceoryx / iceoryx

Eclipse iceoryx™ - true zero-copy inter-process-communication
https://iceoryx.io
Apache License 2.0
1.65k stars 384 forks source link

Mocks can cause segfaults/undefined behavior #427

Closed marthtz closed 3 years ago

marthtz commented 3 years ago

Required information

Operating system: Ubuntu 18.04 LTS

crash_patch.zip

Compiler version: GCC 7.4.0

Observed result or behaviour: A segfault occurred when trying to load OpenCV lib was used. After some digging the problem could be isolated and is now reproducible with the attached patch file. The problem is the time mock in iceoryx, which implements a mock of getTime(). On one hand, getTime mock has the same signature as the system function and on the other hand OpenCV is doing a static init using getTime. As the order of initialization for static variables is undefined OpenCV was sometimes using the real system function and sometimes the mock (which wasn't fully initialized and resulting in a nullptr segfault) .

Expected result or behaviour: No segfault.

Conditions where it occurred / Performed steps:

  1. Apply attached crash patch (patch -p1 < crash.patch).
  2. Run ./build/posh/test/posh_moduletests --gtest_filter="MqMessage_test*"

Fix: A fix is ready and basically routing the functions "on demand" and not in initialization.

elBoberido commented 3 years ago

so this is similar to #327 and there is another static initialization order fiasco ... I fear we have more of these in our codebase