dovecot-2.2: log: Don't crash if master sends a negative service...

dovecot at dovecot.org dovecot at dovecot.org
Mon Oct 27 18:15:45 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/c77d602d4be4
changeset: 18030:c77d602d4be4
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Oct 27 20:14:47 2014 +0200
description:
log: Don't crash if master sends a negative service_fd number.

diffstat:

 src/log/log-connection.c |  12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diffs (36 lines):

diff -r f97ca2bde414 -r c77d602d4be4 src/log/log-connection.c
--- a/src/log/log-connection.c	Mon Oct 27 20:10:19 2014 +0200
+++ b/src/log/log-connection.c	Mon Oct 27 20:14:47 2014 +0200
@@ -143,26 +143,26 @@
 	struct log_client *client;
 	const char *p, *p2, *cmd;
 	unsigned int count;
-	int service_fd;
+	unsigned int service_fd;
 	pid_t pid;
 
 	p = strchr(line, ' ');
-	if (p == NULL || (p2 = strchr(++p, ' ')) == NULL) {
+	if (p == NULL || (p2 = strchr(++p, ' ')) == NULL ||
+	    str_to_uint(t_strcut(line, ' '), &service_fd) < 0) {
 		i_error("Received invalid input from master: %s", line);
 		return;
 	}
-	service_fd = atoi(t_strcut(line, ' '));
 	pid = strtol(t_strcut(p, ' '), NULL, 10);
 	cmd = p2 + 1;
 
 	logs = array_get(&logs_by_fd, &count);
-	if (service_fd >= (int)count || logs[service_fd] == NULL) {
-		if (strcmp(cmd, "BYE") == 0 && service_fd < (int)count) {
+	if (service_fd >= count || logs[service_fd] == NULL) {
+		if (strcmp(cmd, "BYE") == 0 && service_fd < count) {
 			/* master is probably shutting down and we already
 			   noticed the log fd closing */
 			return;
 		}
-		i_error("Received master input for invalid service_fd %d: %s",
+		i_error("Received master input for invalid service_fd %u: %s",
 			service_fd, line);
 		return;
 	}


More information about the dovecot-cvs mailing list