From 8968e8490313e5d63601d48fb679f73dbc16344f Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 30 Apr 2025 15:13:11 +0200 Subject: [PATCH] common: Fix logic for certain recsel conditions. * common/recsel.c (recsel_select): Change processing of NULL values. * common/t-recsel.c (run_test_2): Adjust for this change. Also a type fix for s/"letter"/"letters"/. -- The getval function may return NULL which indicates that there is no useful value available. For example because the propertyname is not defined for some external context (e.g. in gpg the packet type). This also required to fix the test for boolean tests of a non existing property name. Reported-by: shniubobo at gnupg-users on 2025-04-18. --- common/recsel.c | 6 +++++- common/t-recsel.c | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/common/recsel.c b/common/recsel.c index 36aa01476..a778419db 100644 --- a/common/recsel.c +++ b/common/recsel.c @@ -527,7 +527,11 @@ recsel_select (recsel_expr_t selector, if (recsel_debug) log_debug ("%s: name=%s got value '%s'\n", __func__, se->name, value); if (!value) - value = ""; + { + se = se->next; + result = 0; + continue; + } if (!*value) { diff --git a/common/t-recsel.c b/common/t-recsel.c index ff68e54c3..679ea7aff 100644 --- a/common/t-recsel.c +++ b/common/t-recsel.c @@ -324,7 +324,7 @@ run_test_2 (void) FREEEXPR(); ADDEXPR ("nothing -z"); - if (!recsel_select (se, test_2_getval, NULL)) + if (recsel_select (se, test_2_getval, NULL)) fail (0, 0); FREEEXPR(); ADDEXPR ("nothing -n"); @@ -352,7 +352,7 @@ run_test_2 (void) FREEEXPR(); ADDEXPR ("nothing -f"); - if (!recsel_select (se, test_2_getval, NULL)) + if (recsel_select (se, test_2_getval, NULL)) fail (0, 0); FREEEXPR(); ADDEXPR ("nothing -t"); @@ -387,7 +387,8 @@ run_test_2 (void) fail (0, 0); FREEEXPR(); - ADDEXPR ("letter -f"); + ADDEXPR ("letters -f"); + recsel_dump (se); if (!recsel_select (se, test_2_getval, NULL)) fail (0, 0); FREEEXPR();