Fix a use-after-free. Found by Don North.

Also adjust test case to include this code.
Fixes #2.
This commit is contained in:
Olaf Seibert 2017-04-23 13:54:13 +02:00
parent 433e8ecda6
commit c771c875cb
3 changed files with 13 additions and 2 deletions

View File

@ -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);

View File

@ -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

View File

@ -15,3 +15,7 @@
.include <incl.mac<
.include =incl.mac= ; looks like assignment
.include :incl.mac: ; looks like a label
; this is an error: file does not existst
.include "does-not-exist.mac"