libosmocore/tests/vty
Neels Hofmeyr 5314c513f2 vty: fix use-after-free and memleaks in is_cmd_ambiguous()
vty_test: add test against ambiguous cmd causing use-after-free and memory
leaks. Add this test along with the fix, because the new test triggers the
memory use-after-free and leaks, causing build failures.

Add cmd_deopt_with_ctx() to allow passing a specific talloc ctx.

is_cmd_ambiguous(): keep all cmd_deopt() allocations until the function exits.
Add a comment explaining why. Before this, if a command matched an optional
"[arg]" with square brackets, we would keep it in local var 'matched', but we
would free the string it points to at the end of that loop iteration; upon
encountering another match, we would attempt to strcmp against the freed
'matched'. Instead of adding hard-to-read and -verify free/alloc dances to keep
the 'matched' accurately freed/non-freed/..., just keep all cmd_deopt() string
allocated until done.

Needless to say that this should have been implemented on a lower level upon
inventing optional args, but at least this is fixing a program crash.

Related: OS#33903390
Change-Id: Ia71ba742108b5ff020997bfb612ad5eb30d04fcd
2018-07-11 15:47:08 +02:00
..
fail_not_de-indented.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
fail_tabs_and_spaces.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
fail_too_much_indent.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_empty_parent.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_ignore_blank.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_ignore_comment.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_indented_root.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_more_spaces.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_tabs.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_tabs_and_spaces.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
vty_test.c vty: fix use-after-free and memleaks in is_cmd_ambiguous() 2018-07-11 15:47:08 +02:00
vty_test.ok vty: fix use-after-free and memleaks in is_cmd_ambiguous() 2018-07-11 15:47:08 +02:00