diff options
| author | Hauke Mehrtens | 2026-05-03 22:16:29 +0000 |
|---|---|---|
| committer | Hauke Mehrtens | 2026-05-15 00:29:10 +0000 |
| commit | 4221eb8b33ea90d6a09a6048e3280907263604a6 (patch) | |
| tree | 9c8d6802f35f1726cf3ce17bc6c943babd4843f7 | |
| parent | 1781b6dec414a4e284aacf09a544d58fac374289 (diff) | |
| download | uhttpd-4221eb8b33ea90d6a09a6048e3280907263604a6.tar.gz | |
file: respond 500 on uh_handle_alias OOM
realloc(new_url, new_len) returning NULL was overwriting new_url with
NULL and then dereferencing it via *new_url = '\0' for an immediate
segfault on out-of-memory.
Keep the previous allocation by going through a tmp pointer, return
NULL from uh_handle_alias on failure, and have the caller surface a
proper 500 Internal Server Error to the client instead of silently
dispatching the un-rewritten URL through static-file lookup -- which
in some configurations could route to a different resource than the
alias intended.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
| -rw-r--r-- | file.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -912,7 +912,10 @@ static char *uh_handle_alias(char *old_url) new_len = old_len + MAX(conf.cgi_prefix_len, path_len); if (new_len > url_len) { - new_url = realloc(new_url, new_len); + char *tmp = realloc(new_url, new_len); + if (!tmp) + return NULL; + new_url = tmp; url_len = new_len; } @@ -938,6 +941,10 @@ void uh_handle_request(struct client *cl) blob_buf_init(&cl->hdr_response, 0); url = uh_handle_alias(url); + if (!url) { + uh_client_error(cl, 500, "Internal Server Error", "Out of memory"); + return; + } uh_handler_run(cl, &url, false); if (!url) |