Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Feb 2025 15:12:19 GMT
From:      Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= <des@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 1aaec1978a29 - releng/13.5 - unifdef: Fix collision check when adding symbols.
Message-ID:  <202502131512.51DFCJXw071062@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch releng/13.5 has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=1aaec1978a29410ec50124454ad80317b44ab2d6

commit 1aaec1978a29410ec50124454ad80317b44ab2d6
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-01-30 21:10:29 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-02-13 15:12:02 +0000

    unifdef: Fix collision check when adding symbols.
    
    findsym() is intended for use while parsing input, so it should not be
    called from addsym2() or indirectsym(), which are called before any
    input is processed.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Reviewed by:    kevans
    Differential Revision:  https://reviews.freebsd.org/D48733
    Approved by:    re (cperciva)
    
    (cherry picked from commit c63af363c2458aebc30c01cd0b93b4b902580019)
    (cherry picked from commit 931b0990297e2c6307b41bda95c5225cdf48403c)
---
 contrib/unifdef/unifdef.c             | 11 +++++------
 usr.bin/unifdef/tests/unifdef_test.sh | 10 ++++++++++
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/contrib/unifdef/unifdef.c b/contrib/unifdef/unifdef.c
index 3dd4ace7b81e..ce8a1367adc2 100644
--- a/contrib/unifdef/unifdef.c
+++ b/contrib/unifdef/unifdef.c
@@ -1488,7 +1488,7 @@ findsym(const char **strp)
 static void
 indirectsym(void)
 {
-	const char *cp;
+	struct macro key = { 0 };
 	int changed;
 	struct macro *sym, *ind;
 
@@ -1497,10 +1497,9 @@ indirectsym(void)
 		RB_FOREACH(sym, MACROMAP, &macro_tree) {
 			if (sym->value == NULL)
 				continue;
-			cp = sym->value;
-			ind = findsym(&cp);
+			key.name = sym->value;
+			ind = RB_FIND(MACROMAP, &macro_tree, &key);
 			if (ind == NULL || ind == sym ||
-			    *cp != '\0' ||
 			    ind->value == NULL ||
 			    ind->value == sym->value)
 				continue;
@@ -1539,10 +1538,10 @@ addsym1(bool ignorethis, bool definethis, char *symval)
 static void
 addsym2(bool ignorethis, const char *symname, const char *val)
 {
-	const char *cp = symname;
+	struct macro key = { .name = symname };
 	struct macro *sym, *r;
 
-	sym = findsym(&cp);
+	sym = RB_FIND(MACROMAP, &macro_tree, &key);
 	if (sym == NULL) {
 		sym = calloc(1, sizeof(*sym));
 		sym->ignore = ignorethis;
diff --git a/usr.bin/unifdef/tests/unifdef_test.sh b/usr.bin/unifdef/tests/unifdef_test.sh
index dfb08c187724..97a1b1aa6310 100644
--- a/usr.bin/unifdef/tests/unifdef_test.sh
+++ b/usr.bin/unifdef/tests/unifdef_test.sh
@@ -37,7 +37,17 @@ EOF
 	atf_check -s exit:1 -o inline:"b\n" unifdef -DFOO -DFOO=0 <file
 }
 
+atf_test_case sDU
+sDU_head() {
+	atf_set descr "simultaneous use of -s and -D or -U"
+}
+sDU_body() {
+	atf_check unifdef -s -DFOO -UFOO /dev/null
+	atf_check unifdef -s -DFOO -DBAR=FOO /dev/null
+}
+
 atf_init_test_cases() {
 	atf_add_test_case hash_comment
 	atf_add_test_case redefine
+	atf_add_test_case sDU
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502131512.51DFCJXw071062>