From 9a20db4b5257d56d2d6030a20ad42f5e0dc9f25b Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 28 Nov 2022 06:05:48 +0300 Subject: fixed a number of crashes due to empty string arguments or uninitialized registers * An empty but valid teco_string_t can contain NULL pointers. More precisely, a state's done_cb() can be invoked with such empty strings in case of empty string arguments. Also a registers get_string() can return the NULL pointer for existing registers with uninitialized string parts. * In all of these cases, the language should treat "uninitialized" strings exactly like empty strings. * Not doing so, resulted in a number of vulnerabilities. * EN$$ crashed if "_" was uninitialized * The ^E@q and ^ENq string building constructs would crash for existing but uninitialized registers q. * ?$ would crash * ESSETILEXER$$ would crash * This is now fixed. Test cases have been added. * I cannot guarantee that I have found all such cases. Generally, it might be wise to change our definitions and make sure that every teco_string_t must have an associated heap object to be valid. All functions returning pointer+length pairs should consequently also never return NULL pointers. --- src/core-commands.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core-commands.c') diff --git a/src/core-commands.c b/src/core-commands.c index bceb644..5f6ec53 100644 --- a/src/core-commands.c +++ b/src/core-commands.c @@ -1418,6 +1418,7 @@ teco_state_changedir_done(teco_machine_main_t *ctx, const teco_string_t *str, GE "Null-character not allowed in filenames"); return NULL; } + g_assert(home.data != NULL); g_free(dir); dir = home.data; -- cgit v1.2.3