From 0c70e694cf1a703798c0778a3236079e1b25c91d Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Fri, 29 Jan 2021 16:34:27 +0000 Subject: Lookups: fix $local_part_data for a match on a filename list element. Bug 2691 --- src/src/match.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/src/match.c b/src/src/match.c index 597b633fe..73cdab012 100644 --- a/src/src/match.c +++ b/src/src/match.c @@ -809,19 +809,19 @@ while ((sss = string_nextinlist(&list, &sep, NULL, 0))) sss = ss + 1; } - ss = filebuffer + Ustrlen(filebuffer); /* trailing space */ + ss = filebuffer + Ustrlen(filebuffer); /* trailing space */ while (ss > filebuffer && isspace(ss[-1])) ss--; *ss = 0; ss = filebuffer; - while (isspace(*ss)) ss++; /* leading space */ + while (isspace(*ss)) ss++; /* leading space */ - if (*ss == 0) continue; /* ignore empty */ + if (!*ss) continue; /* ignore empty */ - file_yield = yield; /* positive yield */ - sss = ss; /* for debugging */ + file_yield = yield; /* positive yield */ + sss = ss; /* for debugging */ - if (*ss == '!') /* negation */ + if (*ss == '!') /* negation */ { file_yield = (file_yield == OK)? FAIL : OK; while (isspace((*(++ss)))); @@ -833,6 +833,11 @@ while ((sss = string_nextinlist(&list, &sep, NULL, 0))) (void)fclose(f); HDEBUG(D_lists) debug_printf("%s %s (matched \"%s\" in %s)\n", ot, yield == OK ? "yes" : "no", sss, filename); + + /* The "pattern" being matched came from the file; we use a stack-local. + Copy it to allocated memory now we know it matched. */ + + if (valueptr) *valueptr = string_copy(ss); return file_yield; case DEFER: -- cgit v1.2.3