aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-11-10 01:31:46 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-11-10 01:31:46 +0300
commit282914669483405a34000ed24b541201f8d29c4b (patch)
treeb613f8f4844beed5e8109d5c86e80ba872670260
parent8a5405629f7dcbc2504ac55f57775180a011b846 (diff)
downloadunja-282914669483405a34000ed24b541201f8d29c4b.tar.gz
unja-282914669483405a34000ed24b541201f8d29c4b.zip
hashmap_remove: fix potential use-after-free
prev should be assigned before node is reassigned.
-rw-r--r--Makefile7
-rw-r--r--src/hashmap.c2
2 files changed, 6 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 79fd0e6..12944fe 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,12 @@
-CFLAGS= -g -Wall -std=c99 -I.
+CFLAGS= -O0 -g -Wall -std=c99 -I.
LDLIBS=
TESTFLAGS= $(CFLAGS) -Isrc/
ifdef debug
CFLAGS+=-DDEBUG
endif
+ifdef ASAN
+CFLAGS+= -fsanitize=address
+endif
all: check
bin:; mkdir -p bin/
@@ -19,4 +22,4 @@ check: bin/test_hashmap bin/test_template
for test in $^; do $$test || exit 1; done
.PHONY: clean
-clean:; rm -r bin/ \ No newline at end of file
+clean:; rm -r bin/
diff --git a/src/hashmap.c b/src/hashmap.c
index 2522907..2787435 100644
--- a/src/hashmap.c
+++ b/src/hashmap.c
@@ -208,8 +208,8 @@ hashmap_remove(struct hashmap *hm, const char *key)
return old_value;
}
- node = node->next;
prev = node;
+ node = node->next;
}
return NULL;