From: Todd C. Miller Date: Mon, 9 Apr 2012 13:14:53 +0000 (-0400) Subject: Plug memory leak in parse_logfile() in the error path. X-Git-Tag: SUDO_1_8_5~1^2~71 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5029c3cdcebc14f2a35c5f6d72ba2659c2eac017;p=sudo Plug memory leak in parse_logfile() in the error path. --- diff --git a/plugins/sudoers/sudoreplay.c b/plugins/sudoers/sudoreplay.c index 02a08e604..3ff07b662 100644 --- a/plugins/sudoers/sudoreplay.c +++ b/plugins/sudoers/sudoreplay.c @@ -721,11 +721,18 @@ parse_logfile(char *logfile, struct log_info *li) goto done; } + memset(li, 0, sizeof(*li)); + + /* Strip the newline from the cwd and command. */ + cwd[strcspn(cwd, "\n")] = '\0'; + li->cwd = cwd; + cmd[strcspn(cmd, "\n")] = '\0'; + li->cmd = cmd; + /* * Crack the log line (rows and cols not present in old versions). * timestamp:user:runas_user:runas_group:tty:rows:cols */ - memset(li, 0, sizeof(*li)); buf[strcspn(buf, "\n")] = '\0'; /* timestamp */ @@ -767,21 +774,13 @@ parse_logfile(char *logfile, struct log_info *li) } } - cwd[strcspn(cwd, "\n")] = '\0'; - li->cwd = cwd; - - cmd[strcspn(cmd, "\n")] = '\0'; - li->cmd = cmd; - rval = 0; done: fclose(fp); efree(buf); - if (rval != 0) { - efree(cwd); - efree(cmd); - } + if (rval != 0) + free_log_info(li); debug_return_int(rval); }