[nasm:master] preproc: avoid crashing on %exitmacro in broken nesting

nasm-bot for H. Peter Anvin hpa at zytor.com
Mon Nov 21 11:54:03 PST 2022


Commit-ID:  ae0d289123d68ae37f05c446d7dbbe7652d132b6
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=ae0d289123d68ae37f05c446d7dbbe7652d132b6
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Mon, 21 Nov 2022 11:48:00 -0800
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Mon, 21 Nov 2022 11:51:15 -0800

preproc: avoid crashing on %exitmacro in broken nesting

Broken %if, %rep and %macro nesting can result in the %exitmacro
unwind overrunning the condition stack. Fix.

Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392796
Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 asm/preproc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/asm/preproc.c b/asm/preproc.c
index 687431d9..fa2e9425 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -4570,6 +4570,10 @@ issue_error:
              */
             for ( ; l->finishes->condcnt > 0; l->finishes->condcnt --) {
                 cond = istk->conds;
+                if (!cond) {
+                    l->finishes->condcnt = 0;
+                    break;      /* Possible in case of invalid nesting */
+                }
                 istk->conds = cond->next;
                 nasm_free(cond);
             }


More information about the Nasm-commits mailing list