Skip to content

Commit 3bf203a

Browse files
slusarzgoogle-labs-jules[bot]
authored andcommitted
security: fix uncontrolled memory allocation in test parser
Enforce a hardcoded limit of 100 connections in the test parser to prevent unbounded memory allocation in test files. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 091b82e commit 3bf203a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/test-parser.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <sys/stat.h>
1616

1717
#define DEFAULT_MBOX_FNAME "default.mbox"
18+
#define MAX_TEST_CONNECTIONS 100
1819

1920
struct ifenv {
2021
unsigned int linenum;
@@ -60,6 +61,11 @@ test_parse_header_line(struct test_parser *parser, struct test *test,
6061
if (strcmp(key, "connections") == 0) {
6162
test->connection_count = strcmp(value, "n") == 0 ? 2 :
6263
strtoul(value, NULL, 10);
64+
if (test->connection_count == 0 ||
65+
test->connection_count > MAX_TEST_CONNECTIONS) {
66+
*error_r = "Too many connections";
67+
return FALSE;
68+
}
6369
return TRUE;
6470
}
6571
if (strcmp(key, "ignore_extra_untagged") == 0) {
@@ -68,6 +74,10 @@ test_parse_header_line(struct test_parser *parser, struct test *test,
6874
}
6975
if (strncmp(key, "user ", 5) == 0 &&
7076
str_to_uint(key+5, &idx) == 0 && idx != 0) {
77+
if (idx > MAX_TEST_CONNECTIONS) {
78+
*error_r = "Too many connections";
79+
return FALSE;
80+
}
7181
/* FIXME: kludgy kludgy */
7282
if (strcmp(value, "$user2") == 0 ||
7383
strcmp(value, "${user2}") == 0) {
@@ -657,6 +667,10 @@ test_parse_command_line(struct test_parser *parser, struct test *test,
657667
*error_r = "Missing client index";
658668
return FALSE;
659669
}
670+
if (connection_idx > MAX_TEST_CONNECTIONS) {
671+
*error_r = "Too many connections";
672+
return FALSE;
673+
}
660674
if (array_count(&group->commands) > 0 &&
661675
group->connection_idx != connection_idx-1) {
662676
*error_r = "All pipelined commands must use the same connection";

0 commit comments

Comments
 (0)