1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-08 05:31:31 +00:00

Fix an incorrect match case

This commit is contained in:
dmiller
2023-12-01 23:38:19 +00:00
parent b4404ad5dd
commit ee1d570b4e
2 changed files with 31 additions and 24 deletions

View File

@@ -355,17 +355,20 @@ bool expr_match(const char *val, size_t vlen, const char *expr, size_t explen, b
} }
} }
sublen = q ? q - p : explen - (p - expr); sublen = q ? q - p : explen - (p - expr);
if (isxdigit(*subval)) {
if (*p == '>') { if (*p == '>') {
if ((vlen > sublen - 1) if ((vlen > sublen - 1)
|| (vlen == sublen - 1 && strncmp(subval, p + 1, vlen) > 0)) { || (vlen == sublen - 1 && strncmp(subval, p + 1, vlen) > 0)) {
return true; return true;
} }
goto next_expr;
} }
else if (*p == '<') { else if (*p == '<') {
if ((vlen < sublen - 1) if ((vlen < sublen - 1)
|| (vlen == sublen - 1 && strncmp(subval, p + 1, vlen) < 0)) { || (vlen == sublen - 1 && strncmp(subval, p + 1, vlen) < 0)) {
return true; return true;
} }
goto next_expr;
} else { } else {
q1 = strchr(p, '-'); q1 = strchr(p, '-');
if (q1 != NULL) { if (q1 != NULL) {
@@ -379,11 +382,13 @@ bool expr_match(const char *val, size_t vlen, const char *expr, size_t explen, b
return true; return true;
} }
} }
goto next_expr;
} }
else if (vlen == sublen && !strncmp(p, subval, vlen)) { }
}
if (vlen == sublen && !strncmp(p, subval, vlen)) {
return true; return true;
} }
}
next_expr: next_expr:
if (q) if (q)
p = q + 1; p = q + 1;

View File

@@ -115,6 +115,8 @@ const struct expr_test tests[] = {
{"[<5]S", "2B", false}, {"[<5]S", "2B", false},
{"[>A7]S", "FS", false}, {"[>A7]S", "FS", false},
{"[>A7]S", "A6S", false}, {"[>A7]S", "A6S", false},
{"G", "0", false},
{"0-FFFF", "G", false},
{"", "", true} {"", "", true}
}; };