From c06ea4e44caee74486e2931154021a0d0e6c8066 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 10 Sep 2025 11:08:52 +0200 Subject: check_curl: pre compile regex for string matching --- plugins/check_curl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'plugins/check_curl.c') diff --git a/plugins/check_curl.c b/plugins/check_curl.c index f28bcdfc..ba38854a 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -1261,9 +1261,8 @@ mp_state_enum check_http(const check_curl_config config, check_curl_working_stat } if (strlen(config.regexp)) { - regex_t preg; regmatch_t pmatch[REGS]; - int errcode = regexec(&preg, global_state.body_buf.buf, REGS, pmatch, 0); + int errcode = regexec(&config.compiled_regex, global_state.body_buf.buf, REGS, pmatch, 0); if ((errcode == 0 && !config.invert_regex) || (errcode == REG_NOMATCH && config.invert_regex)) { /* OK - No-op to avoid changing the logic around it */ @@ -1284,7 +1283,7 @@ mp_state_enum check_http(const check_curl_config config, check_curl_working_stat } result = config.state_regex; } else { - regerror(errcode, &preg, errbuf, MAX_INPUT_BUFFER); + regerror(errcode, &config.compiled_regex, errbuf, MAX_INPUT_BUFFER); char tmp[DEFAULT_BUFFER_SIZE]; @@ -1969,6 +1968,8 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) { result.errorcode = ERROR; return result; } + + result.config.compiled_regex = preg; break; case INVERT_REGEX: result.config.invert_regex = true; -- cgit v1.2.3-74-g34f1