Skip to content

Commit

Permalink
Limit size of values when expanding variables
Browse files Browse the repository at this point in the history
Fuzzers are really good at finding these limits! This one was found in oss-fuzz.

Limit size of a value in a key/value line to 1MiB, which is more than sufficient for a configuration file.
  • Loading branch information
lpereira committed Apr 24, 2024
1 parent e9fb3bf commit 1d376b5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib/lwan-config.c
Expand Up @@ -579,6 +579,12 @@ static void *parse_key_value(struct parser *parser)
lwan_strbuf_append_char(&parser->strbuf, '\0');

while ((lexeme = lex_next(&parser->lexer))) {
if (UNLIKELY(lwan_strbuf_get_length(&parser->strbuf) > 1ull<<20)) {
/* 1MiB is more than sufficient for a value. (Without this validation
* here, fuzzers often generates values that are gigabite sized.) */
return PARSER_ERROR(parser, "Value too long");
}

switch (lexeme->type) {
case LEXEME_VARIABLE: {
const char *value =
Expand Down

0 comments on commit 1d376b5

Please sign in to comment.