From 94ead27971de001aea5b403130b2a94cf152ebd4 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 27 Sep 2017 15:22:23 -0700 Subject: BR 3392437: Fix diagnostic for negative value in TIMES Issue a diagnostic and don't panic for invalid TIMES values. Reported-by: C. Masloch Signed-off-by: H. Peter Anvin --- asm/assemble.c | 3 +++ asm/parser.c | 5 ++--- test/timesneg.asm | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 test/timesneg.asm diff --git a/asm/assemble.c b/asm/assemble.c index 851ea822..7869f8c1 100644 --- a/asm/assemble.c +++ b/asm/assemble.c @@ -603,6 +603,9 @@ int64_t assemble(int32_t segment, int64_t start, int bits, insn *instruction) size_t blk = 0; /* Buffered I/O block size */ size_t m = 0; /* Bytes last read */ + if (!t) + goto done; + fp = nasm_open_read(fname, NF_BINARY|NF_FORMAP); if (!fp) { nasm_error(ERR_NONFATAL, "`incbin': unable to open file `%s'", diff --git a/asm/parser.c b/asm/parser.c index d701d7fd..bbe3e588 100644 --- a/asm/parser.c +++ b/asm/parser.c @@ -515,9 +515,8 @@ restart_parse: result->times = 1L; } else { result->times = value->value; - if (value->value < 0 && pass0 == 2) { - nasm_error(ERR_NONFATAL, "TIMES value %"PRId64" is negative", - value->value); + if (value->value < 0) { + nasm_error(ERR_NONFATAL|ERR_PASS2, "TIMES value %"PRId64" is negative", value->value); result->times = 0; } } diff --git a/test/timesneg.asm b/test/timesneg.asm new file mode 100644 index 00000000..9f16dbaa --- /dev/null +++ b/test/timesneg.asm @@ -0,0 +1,3 @@ + bits 32 + times -1 db 0 + times -1 incbin "timesneg.asm" -- cgit v1.2.1