Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocks can cause segfaults/undefined behavior #427

Closed
marthtz opened this issue Dec 14, 2020 · 1 comment · Fixed by #429
Closed

Mocks can cause segfaults/undefined behavior #427

marthtz opened this issue Dec 14, 2020 · 1 comment · Fixed by #429
Assignees
Labels
bug Something isn't working

Comments

@marthtz
Copy link
Contributor

marthtz commented Dec 14, 2020

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.

@marthtz marthtz added the bug Something isn't working label Dec 14, 2020
@marthtz marthtz self-assigned this Dec 14, 2020
@elBoberido
Copy link
Member

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

marthtz added a commit to marthtz/iceoryx that referenced this issue Dec 14, 2020
marthtz added a commit that referenced this issue Dec 18, 2020
iox-#427 Add on demand function loader for system function mocks
elBoberido pushed a commit to ApexAI/iceoryx that referenced this issue Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants