You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Segmentation fault is thrown in the code when test_free tried to deallocate the memory allocated by strdup.
Below is the Call stack when run through GDB
#0 strlen () at ../sysdeps/i386/strlen.S:35
#1 0xf7bc3166 in _IO_vfprintf_internal (s=0xffffc7d0, format=0xf7d2c21e "%s:%u: error: Guard block of %p size=%lu is corrupt\n%s:%u: note: allocated here at %p\n", ap=0xffffcd58 "e-4c") at vfprintf.c:1643
#2 0xf7be5baf in _IO_vsnprintf (string=0xffffc8fc "src/config.c:49: error: Guard block of 0x8063010 size=943077171 is corrupt\n", maxlen=<optimized out>,
format=0xf7d2c21e "%s:%u: error: Guard block of %p size=%lu is corrupt\n%s:%u: note: allocated here at %p\n", args=0xffffcd44 "\377\204\005\b1") at vsnprintf.c:114
#3 0xf7d28421 in vcm_print_error (format=0xf7d2c21e "%s:%u: error: Guard block of %p size=%lu is corrupt\n%s:%u: note: allocated here at %p\n", args=0xffffcd44 "\377\204\005\b1")
at /home/sowri/cmocka-1.0.1_32/src/cmocka.c:1535
#4 0xf7d28957 in cm_print_error (format=0xf7d2c21e "%s:%u: error: Guard block of %p size=%lu is corrupt\n%s:%u: note: allocated here at %p\n")
at /home/sowri/cmocka-1.0.1_32/src/cmocka.c:1825
#5 0xf7d2a75b in _test_free (ptr=0x8063010, file=0x80584ff "src/config.c", line=49) at /home/sowri/cmocka-1.0.1_32/src/cmocka.c:1643
#6 0x0804a2b3 in config_reset (cfg=0x8060e20 <g_config>) at src/config.c:49
#7 0x0804cd0c in config_load (config_file=0x8058feb "/cfg/fwcm-updaterd.conf") at src/config.c:352
#8 0x0804f9e4 in test_config_load (state=0x80621a0) at unittest/config_ut.c:323
#9 0xf7d2aa9f in cmocka_run_one_test_or_fixture (function_name=0x805948b "test_config_load", test_func=0x804ee80 <test_config_load>, setup_func=setup_func@entry=0x0, teardown_func=0x0, state=<optimized out>, heap_check_point=0x0)
at /home/sowri/omc/cmocka-1.0.1_32/src/cmocka.c:2305
#10 0xf7d2b2c3 in cmocka_run_one_tests (test_state=0x8062198) at /home/sowri/omc/cmocka-1.0.1_32/src/cmocka.c:2413
#11 _cmocka_run_group_tests (group_name=0x805949c "tests", tests=0xffffd040, num_tests=3, group_setup=0x0, group_teardown=0x0) at /home/sowri//cmocka-1.0.1_32/src/cmocka.c:2518
#12 0x08052818 in main () at unittest/config_ut.c:85
But when i have replaced strdup with custom strdup to do the same, its working perfectly, No SEG-FAULT been observed. It seems Cmocka is not tracking the memory block allocated by the strdup.
Work-Around:
I can mock strdup with Custom implementation while running the Test case but looking for straight Forward solution.
Is there any mocking i missed or is it not yet supported by Cmocka ?
The text was updated successfully, but these errors were encountered:
Just hit this issue myself. I sort of understand why it happens (as the allocation is done inside a separate shared library) but it doesn't make it any less irritating.
This is a known issue in cmocka (see
clibs/cmocka#17) where cmocka does not
recognise memory allocation happening inside strdup, and then later
throws an error when the memory is freed. If the issue is fixed at
some point, this workaround can be removed.
Given that cmocka already overrides malloc, calloc, realloc, free,
adding strdup there seems fine.
Existing tests now can (and have to) free the memory they allocated
by strdup, and this is in the same patch.
BUG=b:193584590
TEST=ninja test
Change-Id: I56aef6b342752d80995c36ab075b12198fc101d9
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56323
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
While checking memory leaks, buffer overflows using test_free, test_malloc, etc getting segmentation fault in the following case.
But when i have replaced strdup with custom strdup to do the same, its working perfectly, No SEG-FAULT been observed. It seems Cmocka is not tracking the memory block allocated by the strdup.
Work-Around:
Is there any mocking i missed or is it not yet supported by Cmocka ?
The text was updated successfully, but these errors were encountered: