aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin (Intel) <hpa@zytor.com>2020-07-30 15:46:12 -0700
committerH. Peter Anvin (Intel) <hpa@zytor.com>2020-07-30 15:48:45 -0700
commit6ac6ac57e3d01ea8ed4ea47706eb724b59176461 (patch)
tree255ca9d06508bcdfd3e29c404ea8d6490d7c91c5
parent0e6e0138136dd3201f55fccd5fb149051f68d7e1 (diff)
downloadnasm-6ac6ac57e3d01ea8ed4ea47706eb724b59176461.tar.gz
nasm-6ac6ac57e3d01ea8ed4ea47706eb724b59176461.tar.xz
nasm-6ac6ac57e3d01ea8ed4ea47706eb724b59176461.zip
parser: when flattening an eop, must preserve any data buffer
An eop may have a data buffer associated with it as part of the same memory allocation. Therefore, we need to move "subexpr" up instead of merging it into "eop". This *partially* resolves BR 3392707, but that test case still triggers a violation when using -gcv8. Reported-by: Suhwan <prada960808@gmail.com> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
-rw-r--r--asm/parser.c16
-rw-r--r--test/br3392707.asm21
2 files changed, 32 insertions, 5 deletions
diff --git a/asm/parser.c b/asm/parser.c
index dbd2240c..584e40c9 100644
--- a/asm/parser.c
+++ b/asm/parser.c
@@ -458,11 +458,17 @@ static int parse_eops(extop **result, bool critical, int elem)
/* Subexpression is empty */
eop->type = EOT_NOTHING;
} else if (!subexpr->next) {
- /* Subexpression is a single element, flatten */
- eop->val = subexpr->val;
- eop->type = subexpr->type;
- eop->dup *= subexpr->dup;
- nasm_free(subexpr);
+ /*
+ * Subexpression is a single element, flatten.
+ * Note that if subexpr has an allocated buffer associated
+ * with it, freeing it would free the buffer, too, so
+ * we need to move subexpr up, not eop down.
+ */
+ if (!subexpr->elem)
+ subexpr->elem = eop->elem;
+ subexpr->dup *= eop->dup;
+ nasm_free(eop);
+ eop = subexpr;
} else {
eop->type = EOT_EXTOP;
}
diff --git a/test/br3392707.asm b/test/br3392707.asm
new file mode 100644
index 00000000..6e84c5b4
--- /dev/null
+++ b/test/br3392707.asm
@@ -0,0 +1,21 @@
+ bits 32
+
+ db 33
+ db (44)
+; db (44,55) -- error
+ db %(44.55)
+ db %('XX','YY')
+ db ('AA')
+ db %('BB')
+ db ?
+ db 6 dup (33)
+ db 6 dup (33, 34)
+ db 6 dup (33, 34), 35
+ db 7 dup (99)
+ db 7 dup (?,?)
+ dw byte (?,44)
+
+ dw 0xcc, 4 dup byte ('PQR'), ?, 0xabcd
+
+ dd 16 dup (0xaaaa, ?, 0xbbbbbb)
+ dd 64 dup (?)