[nasm:nasm-2.15.xx] parser: when flattening an eop, must preserve any data buffer
nasm-bot for H. Peter Anvin (Intel)
hpa at zytor.com
Thu Jul 30 15:51:03 PDT 2020
Commit-ID: 6ac6ac57e3d01ea8ed4ea47706eb724b59176461
Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=6ac6ac57e3d01ea8ed4ea47706eb724b59176461
Author: H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Thu, 30 Jul 2020 15:46:12 -0700
Committer: H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Thu, 30 Jul 2020 15:48:45 -0700
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 at gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa at zytor.com>
---
asm/parser.c | 16 +++++++++++-----
test/{dup.asm => br3392707.asm} | 21 +++------------------
2 files changed, 14 insertions(+), 23 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/dup.asm b/test/br3392707.asm
similarity index 54%
copy from test/dup.asm
copy to test/br3392707.asm
index 62785628..6e84c5b4 100644
--- a/test/dup.asm
+++ b/test/br3392707.asm
@@ -3,7 +3,7 @@
db 33
db (44)
; db (44,55) -- error
- db %(44,55)
+ db %(44.55)
db %('XX','YY')
db ('AA')
db %('BB')
@@ -12,25 +12,10 @@
db 6 dup (33, 34)
db 6 dup (33, 34), 35
db 7 dup (99)
- db 7 dup dword (?, word ?,?)
+ db 7 dup (?,?)
dw byte (?,44)
- dw 3 dup (0xcc, 4 dup byte ('PQR'), ?), 0xabcd
+ dw 0xcc, 4 dup byte ('PQR'), ?, 0xabcd
dd 16 dup (0xaaaa, ?, 0xbbbbbb)
dd 64 dup (?)
-
- resb 1
- resb 2
- resb 4
- resb 8
-
- resw 1
- resw 2
- resw 4
- resw 8
-
- resq 1
- resq 2
- resq 4
- resq 8
More information about the Nasm-commits
mailing list