From c771c875cbc1ddd347a001ba9912aac6cfc6dd7b Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Sun, 23 Apr 2017 13:54:13 +0200 Subject: [PATCH] Fix a use-after-free. Found by Don North. Also adjust test case to include this code. Fixes #2. --- assemble.c | 4 +++- tests/test-include.lst.ok | 7 ++++++- tests/test-include.mac | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/assemble.c b/assemble.c index b162147..a4df153 100644 --- a/assemble.c +++ b/assemble.c @@ -469,13 +469,15 @@ static int assemble( } my_searchenv(name, "INCLUDE", hitfile, sizeof(hitfile)); - free(name); if (hitfile[0] == '\0') { report(stack->top, "Unable to find .INCLUDE file \"%s\"\n", name); + free(name); return 0; } + free(name); + incl = new_file_stream(hitfile); if (incl == NULL) { report(stack->top, "Unable to open .INCLUDE file \"%s\"\n", hitfile); diff --git a/tests/test-include.lst.ok b/tests/test-include.lst.ok index a5b991f..2a1f6cf 100644 --- a/tests/test-include.lst.ok +++ b/tests/test-include.lst.ok @@ -48,7 +48,12 @@ test-include.mac:15: ***ERROR Bad .INCLUDE file name 16 .include =incl.mac= ; looks like assignment test-include.mac:17: ***ERROR Invalid expression 17 000012 000000G 000000 .include :incl.mac: ; looks like a label - 17 + 18 + 19 ; this is an error: file does not existst + 20 +test-include.mac:21: ***ERROR Unable to find .INCLUDE file "does-not-exist.mac" + 21 .include "does-not-exist.mac" + 21 Symbol table diff --git a/tests/test-include.mac b/tests/test-include.mac index 0cf5393..6b4a203 100644 --- a/tests/test-include.mac +++ b/tests/test-include.mac @@ -15,3 +15,7 @@ .include