[nasm:master] preproc: fix memory leak in %[...] processing

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


Commit-ID:  488d7c7bee8853cf5c55522303e537064968d168
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=488d7c7bee8853cf5c55522303e537064968d168
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Mon, 21 Nov 2022 12:08:07 -0800
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Mon, 21 Nov 2022 12:08:07 -0800

preproc: fix memory leak in %[...] processing

"Why dup_tlist() here? We should own it."

Yes, we own it, but we still need to advance the tail pointer. Create
steal_tlist() for this purpose.

Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392774
Reported-and-Debugged-by: C. Masloch <pushbx at ulukai.org>
Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 asm/preproc.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/asm/preproc.c b/asm/preproc.c
index fa2e9425..ac42131e 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -962,6 +962,21 @@ static Token *dup_tlist_reverse(const Token *list, Token *tail)
     return tail;
 }
 
+/*
+ * Append an existing tlist to a tail pointer and returns the
+ * updated tail pointer.
+ */
+static Token **steal_tlist(Token *tlist, Token **tailp)
+{
+    *tailp = tlist;
+
+    if (!tlist)
+        return tailp;
+
+    list_last(tlist, tlist);
+    return &tlist->next;
+}
+
 /*
  * Free an MMacro
  */
@@ -5517,8 +5532,7 @@ static Token *expand_mmac_params(Token * tline)
             tt = tokenize(tok_text(t));
             tt = expand_mmac_params(tt);
             tt = expand_smacro(tt);
-            /* Why dup_tlist() here? We should own tt... */
-            dup_tlist(tt, &tail);
+            tail = steal_tlist(tt, tail);
             text = NULL;
             change = true;
             break;


More information about the Nasm-commits mailing list