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

Don't bail on PCRE2 match errors. Better debug info.

This commit is contained in:
dmiller
2024-09-27 19:20:42 +00:00
parent 01ccce00c0
commit e263e64820

View File

@@ -535,16 +535,19 @@ const struct MatchDetails *ServiceProbeMatch::testMatch(const u8 *buf, int bufle
rc = pcre2_match(regex_compiled, (PCRE2_SPTR8)bufc, buflen, 0, 0, match_data, match_context); rc = pcre2_match(regex_compiled, (PCRE2_SPTR8)bufc, buflen, 0, 0, match_data, match_context);
if (rc < 0) { if (rc < 0) {
if (rc == PCRE2_ERROR_MATCHLIMIT) { // Probably just didn't match. However, PCRE2 errors may happen with bad
if (o.debugging || o.verbose > 1) // patterns. We want to know, but don't abandon the whole scan.
error("Warning: Hit PCRE_ERROR_MATCHLIMIT when probing for service %s with the regex '%s'", servicename, matchstr);
} else
if (rc == PCRE2_ERROR_RECURSIONLIMIT) {
if (o.debugging || o.verbose > 1)
error("Warning: Hit PCRE_ERROR_RECURSIONLIMIT when probing for service %s with the regex '%s'", servicename, matchstr);
} else
if (rc != PCRE2_ERROR_NOMATCH) { if (rc != PCRE2_ERROR_NOMATCH) {
fatal("Unexpected PCRE error (%d) when probing for service %s with the regex '%s'", rc, servicename, matchstr); if (o.verbose || o.debugging) {
error("Warning: PCRE2 error %d when probing for service %s with the regex '%s'", rc, servicename, matchstr);
}
if (o.debugging) {
pcre2_get_error_message(rc, (unsigned char *)info, SERVICE_EXTRA_LEN);
error("PCRE2 error message: %s", info);
if (o.debugging > 1) {
error("Service data: \n%s", hexdump(buf, buflen));
}
}
} }
} else { } else {
// Yeah! Match apparently succeeded. // Yeah! Match apparently succeeded.