[dovecot-cvs] dovecot/src/lib-index/maildir maildir-build.c,1.16,1.17 maildir-sync.c,1.19,1.20

cras at procontrol.fi cras at procontrol.fi
Thu Dec 19 03:02:37 EET 2002


Update of /home/cvs/dovecot/src/lib-index/maildir
In directory danu:/tmp/cvs-serv11467/lib-index/maildir

Modified Files:
	maildir-build.c maildir-sync.c 
Log Message:
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Added str_path() and str_ppath() functions. i_snprintf() now returns only -1
or 0 depending on if buffer got full. dec2str() returns the string allocated
from data stack. Instead of just casting to (long) or (int), we now use
dec2str() with printf-like functions. Added o_stream_send_str(). Added
strocpy() and replaced all strcpy()s and strncpy()s with it.

Pretty much untested, hope it doesn't break too badly :)



Index: maildir-build.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-build.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- maildir-build.c	28 Oct 2002 09:40:15 -0000	1.16
+++ maildir-build.c	19 Dec 2002 01:02:35 -0000	1.17
@@ -107,7 +107,7 @@
 	const char *final_dir;
 	struct dirent *d;
 	struct stat st;
-	char sourcepath[1024], destpath[1024];
+	char sourcepath[PATH_MAX], destpath[PATH_MAX];
 	int failed;
 
 	i_assert(index->lock_type != MAIL_LOCK_SHARED);
@@ -129,10 +129,20 @@
 		if (dest_dir != NULL) {
 			/* move the file into dest_dir - abort everything if it
 			   already exists, as that should never happen */
-			i_snprintf(sourcepath, sizeof(sourcepath), "%s/%s",
-				   source_dir, d->d_name);
-			i_snprintf(destpath, sizeof(destpath), "%s/%s",
-				   dest_dir, d->d_name);
+			if (str_path(sourcepath, sizeof(sourcepath),
+				     source_dir, d->d_name) < 0) {
+				index_set_error(index, "Path too long: %s/%s",
+						source_dir, d->d_name);
+				failed = TRUE;
+				break;
+			}
+			if (str_path(destpath, sizeof(destpath),
+				     dest_dir, d->d_name) < 0) {
+				index_set_error(index, "Path too long: %s/%s",
+						dest_dir, d->d_name);
+				failed = TRUE;
+				break;
+			}
 			if (stat(destpath, &st) == 0) {
 				index_set_error(index, "Can't move mail %s to "
 						"%s: file already exists",

Index: maildir-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-sync.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- maildir-sync.c	16 Dec 2002 03:27:35 -0000	1.19
+++ maildir-sync.c	19 Dec 2002 01:02:35 -0000	1.20
@@ -70,8 +70,8 @@
 	MailIndexRecord *rec;
 	MailIndexDataRecordHeader *data_hdr;
 	struct stat st;
-	const char *fname, *value;
-	char str[1024], *p;
+	const char *fname, *base_fname, *value;
+	char path[PATH_MAX];
 	unsigned int seq;
 	int fname_changed, file_changed;
 
@@ -87,13 +87,15 @@
 			return FALSE;
 		}
 
+		t_push();
+
 		/* get the filename without the ":flags" part */
-		strncpy(str, fname, sizeof(str)-1); str[sizeof(str)-1] = '\0';
-		p = strchr(str, ':');
-		if (p != NULL) *p = '\0';
+		base_fname = t_strcut(fname, ':');
 
-		value = hash_lookup(files, str);
-		hash_remove(files, str);
+		value = hash_lookup(files, base_fname);
+		hash_remove(files, base_fname);
+
+		t_pop();
 
 		if (value == NULL) {
 			/* mail is expunged */
@@ -106,13 +108,17 @@
 		}
 
 		/* file still exists */
-		i_snprintf(str, sizeof(str), "%s/%s", dir, value);
+		if (str_path(path, sizeof(path), dir, value) < 0) {
+			index_set_error(index, "Path too long: %s/%s",
+					dir, value);
+			return FALSE;
+		}
 
 		if (!check_content_changes)
 			file_changed = FALSE;
 		else {
-			if (stat(str, &st) < 0) {
-				index_file_set_syscall_error(index, str,
+			if (stat(path, &st) < 0) {
+				index_file_set_syscall_error(index, path,
 							     "stat()");
 				return FALSE;
 			}
@@ -128,7 +134,7 @@
 		fname_changed = strcmp(value, fname) != 0;
 		if (fname_changed || file_changed) {
 			if (!maildir_index_sync_file(index, rec, seq, value,
-						     str, fname_changed,
+						     path, fname_changed,
 						     file_changed))
 				return FALSE;
 		}
@@ -140,6 +146,7 @@
 		index_set_corrupted(index, "Wrong messages_count in header "
 				    "(%u != %u)", seq-1,
 				    index->header->messages_count);
+		return FALSE;
 	}
 
 	return TRUE;




More information about the dovecot-cvs mailing list