From 18be45f69ec987e7ed0c2a2cdc7ab22cb56a9519 Mon Sep 17 00:00:00 2001 From: Paul Annesley Date: Fri, 8 Nov 2019 23:51:05 +1100 Subject: [PATCH] modes/run: don't segfault on invalid cache lines Cache lines without a forward-slash resulted in a segfault attempting strlen(NULL + 1), the NULL coming from strrchr(). This patch handles the NULL and displays that cache line varbatim, and without modifying its search_text. --- modes/run.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modes/run.c b/modes/run.c index 98c97fd..089c8ce 100644 --- a/modes/run.c +++ b/modes/run.c @@ -23,8 +23,17 @@ void wofi_run_init() { struct cache_line* node, *tmp; wl_list_for_each_safe(node, tmp, cache, link) { - char* text = strrchr(node->line, '/') + 1; - char* search_text = utils_concat(2, text, node->line); + char* text; + char* search_prefix; + char* final_slash = strrchr(node->line, '/'); + if(final_slash == NULL) { + text = node->line; + search_prefix = ""; + } else { + text = final_slash + 1; + search_prefix = text; + } + char* search_text = utils_concat(2, search_prefix, node->line); wofi_insert_widget("run", text, search_text, node->line); map_put(cached, node->line, "true"); free(search_text);