Skip to content

mk_lib causes invalid read #360

@nokute78

Description

@nokute78

I tested monkey API and this commit may cause invalid read.

I tested current master and its api_test.

Testing

git clone https://github.com/monkey/monkey.git
cd monkey
git checkout 4ddc8b0865ba403422519fa5412b8258946824be
mkdir build
cd build
cmake .. && make
valgrind --leak-check=full bin/api_test

Output

$ valgrind --leak-check=full bin/api_test 
==11554== Memcheck, a memory error detector
==11554== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==11554== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==11554== Command: bin/api_test
==11554== 
[2022/02/12 08:27:18] [   Info] Service: http://127.0.0.1:8080/test_chunks
[2022/02/12 08:27:19] [   Info] [api test] test worker callback; data=0x4a79040
^C[engine] caught signal
==11554== Invalid read of size 4
==11554==    at 0x112649: mk_stop (in /home/taka/tmp/monkey/build/bin/api_test)
==11554==    by 0x1116C9: signal_handler (in /home/taka/tmp/monkey/build/bin/api_test)
==11554==    by 0x48CB20F: ??? (in /usr/lib/x86_64-linux-gnu/libc-2.31.so)
==11554==    by 0x49653BE: clock_nanosleep@@GLIBC_2.17 (clock_nanosleep.c:78)
==11554==    by 0x496B046: nanosleep (nanosleep.c:27)
==11554==    by 0x496AF7D: sleep (sleep.c:55)
==11554==    by 0x111A4B: main (in /home/taka/tmp/monkey/build/bin/api_test)
==11554==  Address 0x4a7922c is 396 bytes inside a block of size 720 free'd
==11554==    at 0x483CA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==11554==    by 0x117226: mk_mem_free (in /home/taka/tmp/monkey/build/bin/api_test)
==11554==    by 0x1175B0: mk_config_free_all (in /home/taka/tmp/monkey/build/bin/api_test)
==11554==    by 0x127B7D: mk_exit_all (in /home/taka/tmp/monkey/build/bin/api_test)
==11554==    by 0x112464: mk_lib_worker (in /home/taka/tmp/monkey/build/bin/api_test)
==11554==    by 0x4865608: start_thread (pthread_create.c:477)
==11554==    by 0x49A7292: clone (clone.S:95)
==11554==  Block was alloc'd at
==11554==    at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==11554==    by 0x127395: mk_mem_alloc_z (in /home/taka/tmp/monkey/build/bin/api_test)
==11554==    by 0x127847: mk_server_create (in /home/taka/tmp/monkey/build/bin/api_test)
==11554==    by 0x112186: mk_create (in /home/taka/tmp/monkey/build/bin/api_test)
==11554==    by 0x111801: main (in /home/taka/tmp/monkey/build/bin/api_test)
==11554== 
==11554== 
==11554== HEAP SUMMARY:
==11554==     in use at exit: 0 bytes in 0 blocks
==11554==   total heap usage: 84 allocs, 84 frees, 102,342 bytes allocated
==11554== 
==11554== All heap blocks were freed -- no leaks are possible
==11554== 
==11554== For lists of detected and suppressed errors, rerun with: -s
==11554== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions