[dovecot-cvs] dovecot/src/imap client.c,1.14,1.15 cmd-append.c,1.15,1.16 cmd-search.c,1.7,1.8 cmd-sort.c,1.3,1.4

cras at procontrol.fi cras at procontrol.fi
Mon Dec 9 17:25:22 EET 2002


Update of /home/cvs/dovecot/src/imap
In directory danu:/tmp/cvs-serv24518/imap

Modified Files:
	client.c cmd-append.c cmd-search.c cmd-sort.c 
Log Message:
Limited max. command argument elements to 128. Added more verbose error
messages to IMAP parser.



Index: client.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/client.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- client.c	6 Dec 2002 01:09:22 -0000	1.14
+++ client.c	9 Dec 2002 15:25:20 -0000	1.15
@@ -12,6 +12,10 @@
 /* max. size of one parameter in line */
 #define MAX_INBUF_SIZE 8192
 
+/* max. number of IMAP argument elements to accept. The maximum memory usage
+   for command from user is around MAX_INBUF_SIZE * MAX_IMAP_ARG_ELEMENTS */
+#define MAX_IMAP_ARG_ELEMENTS 128
+
 /* If we can't send a buffer in a minute, disconnect the client */
 #define CLIENT_OUTPUT_TIMEOUT (60*1000)
 
@@ -74,7 +78,8 @@
 
 	client->io = io_add(hin, IO_READ, (IOFunc) client_input, client);
 	client->parser = imap_parser_create(client->input, client->output,
-					    MAX_INBUF_SIZE);
+					    MAX_INBUF_SIZE,
+					    MAX_IMAP_ARG_ELEMENTS);
         client->last_input = ioloop_time;
 
 	client->storage = storage;
@@ -144,9 +149,8 @@
 	const char *error;
 
 	if (msg == NULL)
-		error = "BAD Error in IMAP command.";
-	else
-		error = t_strconcat("BAD Error in IMAP command: ", msg, NULL);
+                msg = imap_parser_get_error(client->parser);
+	error = t_strconcat("BAD Error in IMAP command: ", msg, NULL);
 
 	client->cmd_error = TRUE;
 	client_send_tagline(client, error);
@@ -172,8 +176,7 @@
 		return FALSE;
 	} else {
 		/* error, or missing arguments */
-		client_send_command_error(client,
-					  "Missing or invalid arguments.");
+		client_send_command_error(client, NULL);
 		return FALSE;
 	}
 }

Index: cmd-append.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-append.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- cmd-append.c	6 Dec 2002 01:09:22 -0000	1.15
+++ cmd-append.c	9 Dec 2002 15:25:20 -0000	1.16
@@ -87,7 +87,7 @@
 			      &internal_date_str, &msg_size, 2)) {
 	case -1:
 		/* error */
-		client_send_command_error(client, "Invalid APPEND arguments.");
+		client_send_command_error(client, NULL);
 		return TRUE;
 	case 0:
 		/* need more data */

Index: cmd-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-search.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- cmd-search.c	6 Dec 2002 01:09:22 -0000	1.7
+++ cmd-search.c	9 Dec 2002 15:25:20 -0000	1.8
@@ -13,12 +13,12 @@
 	const char *error, *charset;
 
 	args_count = imap_parser_read_args(client->parser, 0, 0, &args);
-	if (args_count == -2)
-		return FALSE;
-
 	if (args_count < 1) {
-		client_send_command_error(client,
-					  "Missing or invalid arguments.");
+		if (args_count == -2)
+			return FALSE;
+
+		client_send_command_error(client, args_count < 0 ? NULL :
+					  "Missing SEARCH arguments.");
 		return TRUE;
 	}
 

Index: cmd-sort.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-sort.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cmd-sort.c	8 Dec 2002 05:23:07 -0000	1.3
+++ cmd-sort.c	9 Dec 2002 15:25:20 -0000	1.4
@@ -77,7 +77,7 @@
 		return FALSE;
 
 	if (args_count < 3) {
-		client_send_command_error(client,
+		client_send_command_error(client, args_count < 0 ? NULL :
 					  "Missing or invalid arguments.");
 		return TRUE;
 	}




More information about the dovecot-cvs mailing list