Mercurial > dovecot > core-2.2
changeset 17456:beb44a468a73
doveadm who: Don't crash if server happens to send broken input.
Found by Coverity.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 12 Jun 2014 23:47:55 +0300 |
parents | 0d2824d5088d |
children | 362ad646e37a |
files | src/doveadm/doveadm-who.c |
diffstat | 1 files changed, 8 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/doveadm/doveadm-who.c Thu Jun 12 23:16:40 2014 +0300 +++ b/src/doveadm/doveadm-who.c Thu Jun 12 23:47:55 2014 +0300 @@ -50,7 +50,7 @@ return FALSE; } -static void who_parse_line(const char *line, struct who_line *line_r) +static int who_parse_line(const char *line, struct who_line *line_r) { const char *const *args = t_strsplit_tab(line); const char *ident = args[0]; @@ -64,9 +64,12 @@ line_r->pid = strtoul(pid_str, NULL, 10); line_r->service = t_strdup_until(ident, p++); line_r->username = strchr(p, '/'); + if (line_r->username == NULL) + return -1; line_r->refcount = atoi(refcount_str); ip_str = t_strdup_until(p, line_r->username++); (void)net_addr2ip(ip_str, &line_r->ip); + return 0; } static bool who_user_has_pid(struct who_user *user, pid_t pid) @@ -146,8 +149,10 @@ T_BEGIN { struct who_line who_line; - who_parse_line(line, &who_line); - callback(ctx, &who_line); + if (who_parse_line(line, &who_line) < 0) + i_error("Invalid input: %s", line); + else + callback(ctx, &who_line); } T_END; } if (input->stream_errno != 0)