From 3aa746b2461c09adfa32853bbef6f746cdefad75 Mon Sep 17 00:00:00 2001 From: Christian Marangi Date: Thu, 9 May 2024 19:17:38 +0200 Subject: [PATCH] nginx-util: fix SEGFAULT from regex_search In converting nginx-util to PCRE2, it was wrongly dropped saving the results of the regex match causing segmentation fault when used. Add the missing code to correctly store the vector of the results from the regex. Fixes: b738e42c4de8 ("nginx-util: move to pcre2") Signed-off-by: Christian Marangi --- net/nginx-util/Makefile | 2 +- net/nginx-util/src/regex-pcre.hpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/net/nginx-util/Makefile b/net/nginx-util/Makefile index b4f06aaae0..8b189aeda0 100644 --- a/net/nginx-util/Makefile +++ b/net/nginx-util/Makefile @@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=nginx-util PKG_VERSION:=1.6 -PKG_RELEASE:=20 +PKG_RELEASE:=21 PKG_MAINTAINER:=Peter Stadler include $(INCLUDE_DIR)/package.mk diff --git a/net/nginx-util/src/regex-pcre.hpp b/net/nginx-util/src/regex-pcre.hpp index ab255542b3..f8713e82a4 100644 --- a/net/nginx-util/src/regex-pcre.hpp +++ b/net/nginx-util/src/regex-pcre.hpp @@ -132,7 +132,7 @@ class smatch { std::string::const_iterator end; - std::vector vec{}; + std::vector vec{}; int n = 0; @@ -227,13 +227,21 @@ auto regex_search(const std::string::const_iterator begin, match.vec.reserve(sz); const char* subj = &*begin; - int len = static_cast(&*end - subj); + int n, len = static_cast(&*end - subj); + unsigned int ov_count; + PCRE2_SIZE *ov; match.begin = begin; match.end = end; pcre2_match_data *match_data = pcre2_match_data_create(sz, NULL); - match.n = pcre2_match(rgx(), (PCRE2_SPTR)subj, len, 0, 0, match_data, NULL); + n = pcre2_match(rgx(), (PCRE2_SPTR)subj, len, 0, 0, match_data, NULL); + ov = pcre2_get_ovector_pointer(match_data); + ov_count = pcre2_get_ovector_count(match_data); + + match.vec.assign(ov, ov + ov_count); + match.n = n; + pcre2_match_data_free(match_data); if (match.n < 0) { -- 2.30.2