cppregex regex_error_desc()
Address sanitizer caught a use after free. cppregex.cpp regex_error_desc() was not returning a pointer to a static buffer, yet the posixregex was. Follow suit.
This commit is contained in:
@@ -12,6 +12,7 @@ extern "C" {
|
|||||||
#include <hack.h>
|
#include <hack.h>
|
||||||
|
|
||||||
extern const char regex_id[] = "cppregex";
|
extern const char regex_id[] = "cppregex";
|
||||||
|
static char cppregex_static_buffer[BUFSZ];
|
||||||
|
|
||||||
struct nhregex {
|
struct nhregex {
|
||||||
std::unique_ptr<std::regex> re;
|
std::unique_ptr<std::regex> re;
|
||||||
@@ -39,10 +40,12 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *regex_error_desc(struct nhregex *re) {
|
const char *regex_error_desc(struct nhregex *re) {
|
||||||
if (re->err)
|
if (re->err) {
|
||||||
return re->err->what();
|
Snprintf(cppregex_static_buffer, sizeof cppregex_static_buffer,
|
||||||
else
|
"%s", re->err->what());
|
||||||
return nullptr;
|
return cppregex_static_buffer;
|
||||||
|
} else
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean regex_match(const char *s, struct nhregex *re) {
|
boolean regex_match(const char *s, struct nhregex *re) {
|
||||||
|
|||||||
Reference in New Issue
Block a user