[dovecot-cvs] dovecot/src/plugins/quota quota-maildir.c,1.22,1.23

tss at dovecot.org tss at dovecot.org
Tue Mar 6 18:32:17 EET 2007


Update of /var/lib/cvs/dovecot/src/plugins/quota
In directory talvi:/tmp/cvs-serv10432

Modified Files:
	quota-maildir.c 
Log Message:
If maildirsize contained NUL bytes at the beginning of the line (could
happen with NFS), we stopped parsing the file at that point instead of
rebuilding it.



Index: quota-maildir.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/quota/quota-maildir.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- quota-maildir.c	16 Feb 2007 20:21:30 -0000	1.22
+++ quota-maildir.c	6 Mar 2007 16:32:14 -0000	1.23
@@ -385,7 +385,7 @@
 
 	/* rest of the lines contains <bytes> <count> diffs */
 	total_bytes = 0; total_count = 0;
-	for (lines++; **lines != '\0'; lines++, line_count++) {
+	for (lines++; *lines != NULL; lines++, line_count++) {
 		if (sscanf(*lines, "%lld %d", &bytes_diff, &count_diff) != 2)
 			return -1;
 
@@ -424,7 +424,7 @@
 static int maildirsize_read(struct maildir_quota_root *root)
 {
 	char buf[5120+1];
-	unsigned int size;
+	unsigned int i, size;
 	int fd, ret = 0;
 
 	t_push();
@@ -467,11 +467,20 @@
 	/* file is smaller than 5120 bytes, which means we can use it */
 	root->total_bytes = root->total_count = 0;
 
-	/* skip the last line if there's no LF at the end */
+	/* skip the last line if there's no LF at the end. Remove the last LF
+	   so we don't get one empty line in the strsplit. */
 	while (size > 0 && buf[size-1] != '\n') size--;
+	if (size > 0) size--;
 	buf[size] = '\0';
 
-	if (maildirsize_parse(root, fd, t_strsplit(buf, "\n")) > 0) {
+	/* If there are any NUL bytes, the file is broken. */
+	for (i = 0; i < size; i++) {
+		if (buf[i] == '\0')
+			break;
+	}
+
+	if (i == size &&
+	    maildirsize_parse(root, fd, t_strsplit(buf, "\n")) > 0) {
 		root->fd = fd;
 		ret = 1;
 	} else {



More information about the dovecot-cvs mailing list