Skip to content

Commit ccea728

Browse files
authored
ESP8266WebServer - UriRegex runtime logic within assert() (#9185)
1 parent bb3360d commit ccea728

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

libraries/ESP8266WebServer/src/uri/UriRegex.h

+18-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#define URI_REGEX_H
33

44
#include "Uri.h"
5+
6+
#include <cassert>
57
#include <regex.h>
6-
#include <assert.h>
78

89
#ifndef REGEX_MAX_GROUPS
910
#define REGEX_MAX_GROUPS 10
@@ -12,29 +13,38 @@
1213
class UriRegex : public Uri {
1314

1415
private:
15-
regex_t _regexCompiled;
16+
regex_t _regexCompiled{};
17+
int _regexErr{REG_EMPTY};
1618

1719
public:
18-
explicit UriRegex(const char *uri) : Uri(uri) {
19-
assert(regcomp(&_regexCompiled, uri, REG_EXTENDED) == 0);
20-
};
21-
explicit UriRegex(const String &uri) : UriRegex(uri.c_str()) {};
20+
UriRegex() = delete;
21+
22+
explicit UriRegex(const char *uri) :
23+
Uri(uri),
24+
_regexErr(regcomp(&_regexCompiled, uri, REG_EXTENDED))
25+
{
26+
assert(_regexErr == 0);
27+
}
28+
29+
explicit UriRegex(const String &uri) : UriRegex(uri.c_str()) {}
2230

2331
~UriRegex() {
2432
regfree(&_regexCompiled);
2533
}
2634

2735
Uri* clone() const override final {
2836
return new UriRegex(_uri);
29-
};
37+
}
3038

3139
bool canHandle(const String &requestUri, std::vector<String> &pathArgs) override final {
3240
if (Uri::canHandle(requestUri, pathArgs))
3341
return true;
3442

43+
if (_regexErr != 0)
44+
return false;
45+
3546
regmatch_t groupArray[REGEX_MAX_GROUPS];
3647
if (regexec(&_regexCompiled, requestUri.c_str(), REGEX_MAX_GROUPS, groupArray, 0) == 0) {
37-
// matches
3848
pathArgs.clear();
3949

4050
unsigned int g = 1;

0 commit comments

Comments
 (0)