[dovecot-cvs] dovecot/src/imap cmd-list.c,1.7,1.8 cmd-sort.c,1.2,1.3 cmd-uid.c,1.1.1.1,1.2 main.c,1.15,1.16 rawlog.c,1.5,1.6

cras at procontrol.fi cras at procontrol.fi
Sun Dec 8 07:23:10 EET 2002


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

Modified Files:
	cmd-list.c cmd-sort.c cmd-uid.c main.c rawlog.c 
Log Message:
Added buffer API. Point is to hide all buffer writing behind this API which
verifies that nothing overflows. Much better than doing the same checks all
around the code, even if it is slightly slower.

Buffer reading is still mostly done directly, that isn't such a big security
risk and I can't think of a reasonable API for it anyway.



Index: cmd-list.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-list.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- cmd-list.c	4 Dec 2002 00:27:09 -0000	1.7
+++ cmd-list.c	8 Dec 2002 05:23:07 -0000	1.8
@@ -40,11 +40,12 @@
 
 	parent = NULL;
 
-	t_push();
 	for (name = path;; path++) {
 		if (*path != separator && *path != '\0')
 			continue;
 
+		t_push();
+
 		/* escaping is done here to make sure we don't try to escape
 		   the separator char */
 		name = imap_escape(t_strdup_until(name, path));
@@ -64,6 +65,8 @@
 			(*node)->flags = MAILBOX_NOSELECT;
 		}
 
+		t_pop();
+
 		if (*path == '\0')
 			break;
 
@@ -71,7 +74,6 @@
 		parent = (*node)->name;
 		node = &(*node)->children;
 	}
-	t_pop();
 
 	return *node;
 }
@@ -93,7 +95,7 @@
 static void list_send(Client *client, ListNode *node, const char *cmd,
 		      const char *path, const char *sep, ImapMatchGlob *glob)
 {
-	const char *name;
+	const char *name, *str;
 
 	for (; node != NULL; node = node->next) {
 		t_push();
@@ -109,18 +111,14 @@
 		if (node->children != NULL)
 			list_send(client, node->children, cmd, name, sep, glob);
 
-		if ((node->flags & MAILBOX_NOSELECT) &&
-		    imap_match(glob, name) <= 0) {
-			/* doesn't match the mask */
-			t_pop();
-			continue;
+		if ((node->flags & MAILBOX_NOSELECT) == 0 ||
+		    imap_match(glob, name) > 0) {
+			/* node->name should already be escaped */
+			str = t_strdup_printf("* %s (%s) \"%s\" \"%s\"", cmd,
+					      mailbox_flags2str(node->flags),
+					      sep, name);
+			client_send_line(client, str);
 		}
-
-		/* node->name should already be escaped */
-		client_send_line(client,
-				 t_strdup_printf("* %s (%s) \"%s\" \"%s\"", cmd,
-						 mailbox_flags2str(node->flags),
-						 sep, name));
 		t_pop();
 	}
 }
@@ -162,7 +160,7 @@
 			pattern = t_strconcat(ref, pattern, NULL);
 		}
 
-		ctx.pool = pool_create("ListCtx", 10240, FALSE);
+		ctx.pool = pool_create("ListContext", 10240, FALSE);
 		ctx.nodes = NULL;
 		ctx.storage = client->storage;
 

Index: cmd-sort.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-sort.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cmd-sort.c	6 Dec 2002 01:09:22 -0000	1.2
+++ cmd-sort.c	8 Dec 2002 05:23:07 -0000	1.3
@@ -1,6 +1,7 @@
 /* Copyright (C) 2002 Timo Sirainen */
 
 #include "common.h"
+#include "buffer.h"
 #include "commands.h"
 #include "mail-search.h"
 #include "mail-sort.h"
@@ -25,12 +26,12 @@
 
 static MailSortType *get_sort_program(Client *client, ImapArg *args)
 {
-	MailSortType *program, *temp_prog;
-	size_t program_alloc, program_size;
+	MailSortType type;
+	Buffer *buf;
 	int i;
 
-	program_alloc = 32; program_size = 0;
-	program = t_new(MailSortType, program_alloc+1);
+	buf = buffer_create_dynamic(data_stack_pool, 32 * sizeof(MailSortType),
+				    (size_t)-1);
 
 	while (args->type == IMAP_ARG_ATOM || args->type == IMAP_ARG_STRING) {
 		const char *arg = args->data.str;
@@ -46,20 +47,12 @@
 			return NULL;
 		}
 
-		if (program_size == program_alloc) {
-			program_alloc *= 2;
-			if (!t_try_realloc(program, program_alloc+1)) {
-				temp_prog = t_new(MailSortType, program_alloc);
-				memcpy(temp_prog, program,
-				       sizeof(MailSortType) * program_size);
-				program = temp_prog;
-			}
-		}
-		program[program_size++] = sort_names[i].type;
+		buffer_append(buf, &sort_names[i].type, sizeof(MailSortType));
 		args++;
 	}
 
-	program[program_size] = MAIL_SORT_END;
+	type = MAIL_SORT_END;
+	buffer_append(buf, &type, sizeof(type));
 
 	if (args->type != IMAP_ARG_EOL) {
 		client_send_command_error(client,
@@ -67,7 +60,7 @@
 		return NULL;
 	}
 
-	return program;
+	return buffer_free_without_data(buf);
 }
 
 int cmd_sort(Client *client)

Index: cmd-uid.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-uid.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- cmd-uid.c	9 Aug 2002 09:15:53 -0000	1.1.1.1
+++ cmd-uid.c	8 Dec 2002 05:23:07 -0000	1.2
@@ -30,6 +30,8 @@
 			client->cmd_func = cmd_store;
 		else if (strcasecmp(cmd, "SEARCH") == 0)
 			client->cmd_func = cmd_search;
+		else if (strcasecmp(cmd, "SORT") == 0)
+			client->cmd_func = cmd_sort;
 		break;
 	}
 

Index: main.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/main.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- main.c	3 Dec 2002 00:59:10 -0000	1.15
+++ main.c	8 Dec 2002 05:23:07 -0000	1.16
@@ -12,7 +12,7 @@
 #include <syslog.h>
 
 IOLoop ioloop;
-static char log_prefix[64];
+static char log_prefix[128];
 
 static void sig_quit(int signo __attr_unused__)
 {

Index: rawlog.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/rawlog.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- rawlog.c	3 Dec 2002 00:27:32 -0000	1.5
+++ rawlog.c	8 Dec 2002 05:23:07 -0000	1.6
@@ -113,14 +113,14 @@
 	if (strftime(timestamp, sizeof(timestamp), "%Y%m%d-%H%M%S", tm) <= 0)
 		i_fatal("strftime() failed");
 
-	fname = t_strdup_printf("%s/%s-%d.in", path, timestamp, getpid());
+	fname = t_strdup_printf("%s/%s-%d.in", path, timestamp, (int)getpid());
 	log_in = open(fname, O_CREAT|O_EXCL|O_WRONLY, 0600);
 	if (log_in == -1) {
 		i_warning("rawlog_open: open() failed for %s: %m", fname);
 		return;
 	}
 
-	fname = t_strdup_printf("%s/%s-%d.out", path, timestamp, getpid());
+	fname = t_strdup_printf("%s/%s-%d.out", path, timestamp, (int)getpid());
 	log_out = open(fname, O_CREAT|O_EXCL|O_WRONLY, 0600);
 	if (log_out == -1) {
 		i_warning("rawlog_open: open() failed for %s: %m", fname);




More information about the dovecot-cvs mailing list