dovecot-2.2: doveadm who: Don't crash if server happens to send ...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jun 12 23:20:35 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/beb44a468a73
changeset: 17456:beb44a468a73
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jun 12 23:47:55 2014 +0300
description:
doveadm who: Don't crash if server happens to send broken input.
Found by Coverity.

diffstat:

 src/doveadm/doveadm-who.c |  11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diffs (38 lines):

diff -r 0d2824d5088d -r beb44a468a73 src/doveadm/doveadm-who.c
--- 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)


More information about the dovecot-cvs mailing list