Skip to content

Commit a510566

Browse files
committed
Fix validateByteRange and cssDecode unit test edge cases
1 parent 0abd079 commit a510566

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/actions/transformations/css_decode.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "css_decode.h"
1717

18+
#include <cctype>
19+
1820
#include "src/utils/string.h"
1921

2022
using namespace modsecurity::utils::string;
@@ -138,7 +140,17 @@ static inline bool css_decode_inplace(std::string &val) {
138140
/* The character after backslash is not a hexadecimal digit,
139141
* nor a newline. */
140142
/* Use one character after backslash as is. */
141-
*d++ = input[i++];
143+
const auto escaped = input[i++];
144+
*d++ = escaped;
145+
146+
/*
147+
* Preserve legacy behaviour for escaped NUL by consuming
148+
* one trailing whitespace character.
149+
*/
150+
if ((escaped == '\0') && (i < input_len)
151+
&& std::isspace(input[i])) {
152+
i++;
153+
}
142154
}
143155
} else {
144156
/* No characters after backslash. */

src/operators/validate_byte_range.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ bool ValidateByteRange::init(const std::string &file,
150150
: m_param.substr(pos, nextPos - pos);
151151

152152
if (getRange(token, &parsedTable, error) == false) {
153+
/*
154+
* Keep byte 0 allowed on invalid parameters so callers that
155+
* continue after init() failure keep legacy behaviour.
156+
*/
157+
table[0] = table[0] | 1U;
153158
return false;
154159
}
155160

0 commit comments

Comments
 (0)