[dovecot-cvs] dovecot/src/plugins/quota quota-maildir.c, 1.9.2.10, 1.9.2.11

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


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

Modified Files:
      Tag: branch_1_0
	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.9.2.10
retrieving revision 1.9.2.11
diff -u -d -r1.9.2.10 -r1.9.2.11
--- quota-maildir.c	26 Jan 2007 13:58:40 -0000	1.9.2.10
+++ quota-maildir.c	6 Mar 2007 16:32:11 -0000	1.9.2.11
@@ -372,7 +372,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;
 
@@ -413,7 +413,7 @@
 {
 	const char *path;
 	char buf[5120+1];
-	unsigned int size;
+	unsigned int i, size;
 	int fd, ret = 0;
 
 	t_push();
@@ -461,11 +461,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