-
Notifications
You must be signed in to change notification settings - Fork 892
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
Issue in automata release #1506
Comments
Try to apply this patch vel21ripn@06e2967 . If it helps, I'll do a PR. |
Thanks @vel21ripn , I will try. It seems the patch is from 2021, why is this not part of the latest 4.2 stable? |
Yes, 2021. |
No it didn't solve the crash. It's coming while calling ac_automata_release(). |
Got another segfault in the same code segment Program terminated with signal SIGSEGV, Segmentation fault. 771 third_party/src/ahocorasick.c: No such file or directory. |
There are two options: build with clang and options "-fsanitize=memory -fsanitize=fuzzer-no-link" or run via valgrind It must be remembered that libahocorasick does not allocate memory for the string when adding a string. |
Yes @vel21ripn . I have used ndpi_alloc . I was using Ndpi 3.4 with ac_automata_release(,1) after applying this patch in Ndpi 3.4 stable (it was not initially in the release of Ndpi 3.4) . This issue never comes. Also I can see the unitTest funcs are commented in ndpiReader, it has an automata test case I think . I will have to dig further to check the difference between 3.4 and 4.2 in this part of the code/func. Please let me if you need any other info to debug this issue . Thanks |
Hi @vel21ripn The issue has been resolved. I was using strdupa() instead of strdup(). Now I am confused why this issue was never reported with ndpi-3.4. ndpi-3.4 should also generate SIGABRT or SEGV in case of double free. ( added below patch in ndpi-3.4, [4aefbe0c7a665ee077b3ddbfc0c7738cd7333558] . However, can you please tell if there is any limit on the number of patterns/strings which can be added into a single automata? I can see the length is MAX 256 for a string. |
There is no limit on the number of lines (there must be enough RAM). |
Hi @vel21ripn , typedef struct { I was checking node_resize_mp() and mp_data_size() where the max is initialized with 8 at first and each time incremented with 8 when a new string added to automata. Can you please elaborate this logic? Is it optimized for performance? |
Statistics can be obtained to evaluate the need to increase REALLOC_CHUNK_MATCHSTR. |
@vel21ripn, do you think this patch is still needed in current master (i.e. should we merge it)? |
Kind reminder, @vel21ripn :) |
Sorry. |
Porting of vel21ripn@06e2967 Close ntop#1506
Porting of vel21ripn@06e2967 Close #1506
Program terminated with signal SIGABRT, Aborted. #0 0x00007fba2dc187bb in raise () from /lib/x86_64-linux-gnu/libc.so.6 [Current thread is 1 (Thread 0x7fba2d4be400 (LWP 2275))] (gdb) bt #0 0x00007fba2dc187bb in raise () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007fba2dc03535 in abort () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x00007fba2dc5a508 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #3 0x00007fba2dc60c1a in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #4 0x00007fba2dc6242c in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #5 0x00007fba2e999e7d in node_release_pattern (thiz=0x563e360ab600) at third_party/src/ahocorasick.c:771 #6 node_release (thiz=0x563e360ab600, free_pattern=<optimized out>) at third_party/src/ahocorasick.c:786 #7 0x00007fba2e999eff in ac_automata_release_node (thiz=thiz@entry=0x563e360b0380, n=n@entry=0x563e360ab600, idx=idx@entry=0, data=data@entry=0x1) at third_party/src/ahocorasick.c:544 #8 0x00007fba2e99aa98 in ac_automata_walk (thiz=0x563e360b0380, node_cb=node_cb@entry=0x7fba2e999ed0 <ac_automata_release_node>, alpha_cb=alpha_cb@entry=0x0, data=data@entry=0x1) at third_party/src/ahocorasick.c:288 #9 0x00007fba2e99b3ab in ac_automata_release (thiz=0x563e360b0380, free_pattern=<optimized out>) at third_party/src/ahocorasick.c:556
(gdb) frame 5 #5 0x00007fba2e999e7d in node_release_pattern (thiz=0x563e360ab600) at third_party/src/ahocorasick.c:771 771 third_party/src/ahocorasick.c: No such file or directory.
(gdb) p *thiz $1 = {id = 10, one_alpha = 0 '\000', one = 0 '\000', range = 0 '\000', root = 0 '\000', final = -1 '\377', use = 0 '\000', ff = -1 '\377', depth = 9, matched_patterns = 0x563e360b1480, outgoing = 0x0, failure_node = 0x563e360a1340, a_ptr = 0x0} (gdb) p *thiz->matched_patterns $2 = {num = 1, max = 8, patterns = 0x563e360b1488}
(gdb) p *thiz->matched_patterns->patterns $3 = {astring = 0x7ffe7074c40e "apple.com", length = 9, is_existing = 0, rep = {number = 1, number64 = 0, breed = 0, category = 0, level = 0, from_start = 0, at_end = 0, dot = 0}}
The text was updated successfully, but these errors were encountered: