Skip to content

Commit

Permalink
Fixed invalid read (heap-buffer-overflow) when parsing an XFF spec vi…
Browse files Browse the repository at this point in the history
…a JSON.

This explicitly checks that p is less than the address of the null terminator,
which ensures that the loop terminates before p can point beyond the end of the
string.

See allinurl#2492 using a JSON format. e.g.,
--log-format='{ "accessIpList": "~h{, }", "cookie": "%e", "httpHost": "%v",
"timestamp": "%dT%t+%^", "method": "%m", "url": "%U", "status": "%s",
"httpReferer": "%R", "bodyBytesSent": "%b", "requestTime": "%T", "ua": "%u" }'
--date-format='%Y-%m-%d' --time-format=%T
  • Loading branch information
allinurl committed Mar 29, 2023
1 parent 156aea4 commit be1d51a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,14 +1481,15 @@ special_specifier (GLogItem * logitem, char **str, char **p) {
static int
parse_format (GLogItem * logitem, char *str, char *lfmt) {
char end[2 + 1] = { 0 };
char *p = NULL;
char *p = NULL, *last = NULL;
int perc = 0, tilde = 0, ret = 0;

if (str == NULL || *str == '\0')
return 1;

/* iterate over the log format */
for (p = lfmt; *p; p++) {
last = lfmt + strlen (lfmt);
for (p = lfmt; p < last; p++) {
if (*p == '%') {
perc++;
continue;
Expand Down

0 comments on commit be1d51a

Please sign in to comment.