1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Fix another case for expr_match

This commit is contained in:
dmiller
2024-02-29 20:02:01 +00:00
parent f999182d0f
commit 63f82dded0
2 changed files with 23 additions and 4 deletions

View File

@@ -301,10 +301,7 @@ bool expr_match(const char *val, size_t vlen, const char *expr, size_t explen, b
explen = strlen(expr); explen = strlen(expr);
// If both are empty, match; else if either is empty, no match. // If both are empty, match; else if either is empty, no match.
if (vlen == 0) { if (explen == 0) {
return explen == 0;
}
else if (explen == 0) {
return vlen == 0; return vlen == 0;
} }
@@ -318,6 +315,20 @@ bool expr_match(const char *val, size_t vlen, const char *expr, size_t explen, b
q = strchr_p(p, p_end, '|'); q = strchr_p(p, p_end, '|');
nest = strchr_p(p, q ? q : p_end, '['); nest = strchr_p(p, q ? q : p_end, '[');
if (vlen == 0) {
// value is empty, so can only match an empty expression
if (q == p || p == p_end ) {
// expression is also empty, match
return true;
}
else if (!nest) {
// simple expression before '|', no match.
goto next_expr;
}
// other short-circuit may be possible here, but drop to nesting logic
// below to avoid confusion/bugs
}
// if we're already in a nested expr, we skip this and just match as usual. // if we're already in a nested expr, we skip this and just match as usual.
if (do_nested && nest) { if (do_nested && nest) {
// As long as we keep finding nested portions, e.g. M[>500]ST11W[1-5] // As long as we keep finding nested portions, e.g. M[>500]ST11W[1-5]

View File

@@ -182,6 +182,14 @@ const struct expr_test tests[] = {
{"001", "A", false}, {"001", "A", false},
{"0001", "A", false}, {"0001", "A", false},
{"M5B4NNSNW5|M5B4NNSNW7|M5B4NNSNWA", "M5B4NNSNW7", true}, {"M5B4NNSNW5|M5B4NNSNW7|M5B4NNSNWA", "M5B4NNSNW7", true},
{"|U", "U", true},
{"|U", "", true},
{"|1", "1", true},
{"|1", "", true},
{"U|", "U", true},
{"U|", "", true},
{"1|", "1", true},
{"1|", "", true},
{"", "", true} {"", "", true}
}; };