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:
19
osscan.cc
19
osscan.cc
@@ -301,10 +301,7 @@ bool expr_match(const char *val, size_t vlen, const char *expr, size_t explen, b
|
||||
explen = strlen(expr);
|
||||
|
||||
// If both are empty, match; else if either is empty, no match.
|
||||
if (vlen == 0) {
|
||||
return explen == 0;
|
||||
}
|
||||
else if (explen == 0) {
|
||||
if (explen == 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, '|');
|
||||
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 (do_nested && nest) {
|
||||
// As long as we keep finding nested portions, e.g. M[>500]ST11W[1-5]
|
||||
|
||||
@@ -182,6 +182,14 @@ const struct expr_test tests[] = {
|
||||
{"001", "A", false},
|
||||
{"0001", "A", false},
|
||||
{"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}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user