diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2025-07-31 21:21:44 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-07-31 21:22:44 +0530 |
commit | 3d05ff0a84308d44a60e9793906722c3e8e07030 (patch) | |
tree | 7675073cefe77d6cc275c2e7595f23c48f048795 | |
parent | 20325d989a55525494986c316b7c18848f31a5f8 (diff) |
engine: fix use-after-free on content_headers
-rw-r--r-- | CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/engine.c | 10 |
2 files changed, 13 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 88bc17e..db3fe17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,15 +17,15 @@ set(SRC ) set(C_COMPILE_OPTIONS - -O3 - # -Og + # -O3 + -Og -Wall -Wextra -Werror - # -g3 - # -glldb + -g3 + -glldb -std=c99 diff --git a/src/engine.c b/src/engine.c index 5d49e07..5e91b7d 100644 --- a/src/engine.c +++ b/src/engine.c @@ -72,7 +72,10 @@ handle_contentfor(char **buffer, list_t *content_headers) { contentfor_operand_t *operand = directive->operands; - list_add(content_headers, operand); + contentfor_operand_t new_operand = { .content = strdup(operand->content), + .key = strdup(operand->key), + .length = operand->length }; + list_add(content_headers, &new_operand); #ifdef DEBUG printf("CONTENTFOR: %s\n", operand->key); @@ -286,6 +289,11 @@ engine_delete(engine_t *engine) if (engine->config != NULL) config_delete(engine->config); + for (size_t i = 0; i < engine->content_headers->size; i++) { + contentfor_operand_t *operand = list_get(engine->content_headers, i); + free(operand->content); + free(operand->key); + } list_delete(engine->content_headers); free(engine); } |