From: Stephen Seo Date: Mon, 23 Sep 2024 06:10:39 +0000 (+0900) Subject: Fix use-after-free in path-to-filename function X-Git-Tag: 1.0~24^2~12 X-Git-Url: https://git.seodisparate.com/stephenseo/static/annotated.html?a=commitdiff_plain;h=7cc0d624bef892000b8c4f81c0a54733f29eda0a;p=c_simple_http Fix use-after-free in path-to-filename function --- diff --git a/src/html_cache.c b/src/html_cache.c index cbf5f17..f851c09 100644 --- a/src/html_cache.c +++ b/src/html_cache.c @@ -77,7 +77,10 @@ char *c_simple_http_path_to_cache_filename(const char *path) { } if (prev_idx == 0) { - return stripped_path; + // Prevent string from being free'd by moving it to another variable. + char *temp = stripped_path; + stripped_path = NULL; + return temp; } else { return c_simple_http_combine_string_parts(parts); }