dovecot-2.2: imap-stats: Fixed truncation of command args.

dovecot at dovecot.org dovecot at dovecot.org
Thu Nov 13 00:49:37 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/6c69fe41d553
changeset: 18073:6c69fe41d553
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Nov 13 02:48:22 2014 +0200
description:
imap-stats: Fixed truncation of command args.

diffstat:

 src/plugins/imap-stats/imap-stats-plugin.c |  11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diffs (36 lines):

diff -r 0694bfec140a -r 6c69fe41d553 src/plugins/imap-stats/imap-stats-plugin.c
--- a/src/plugins/imap-stats/imap-stats-plugin.c	Thu Nov 13 02:39:51 2014 +0200
+++ b/src/plugins/imap-stats/imap-stats-plugin.c	Thu Nov 13 02:48:22 2014 +0200
@@ -54,7 +54,7 @@
 	struct stats_user *suser = STATS_USER_CONTEXT(cmd->client->user);
 	struct stats_client_command *scmd = IMAP_STATS_IMAP_CONTEXT(cmd);
 	struct mail_stats stats, pre_trans_stats, trans_stats;
-	unsigned int args_pos = 0;
+	unsigned int args_pos = 0, args_len = 0;
 	string_t *str;
 
 	if (scmd == NULL)
@@ -87,6 +87,7 @@
 		args_pos = str_len(str);
 		if (cmd->args != NULL)
 			str_append(str, cmd->args);
+		args_len = str_len(str) - args_pos;
 		scmd->continued = TRUE;
 	}
 
@@ -95,9 +96,13 @@
 
 	if (str_len(str) > PIPE_BUF) {
 		/* truncate the args so it fits */
+		unsigned int delete_count = str_len(str) - PIPE_BUF;
+
 		i_assert(args_pos != 0);
-		str_delete(str, args_pos, str_len(str) - PIPE_BUF);
-		i_assert(str_len(str) == PIPE_BUF);
+		if (delete_count > args_len)
+			delete_count = args_len;
+		str_delete(str, args_pos + args_len - delete_count,
+			   delete_count);
 	}
 
 	stats_connection_send(suser->stats_conn, str);


More information about the dovecot-cvs mailing list