dovecot-2.2: Check for syscall errors that are quite unlikely to...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 16 12:48:55 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/3d3796c15074
changeset: 17496:3d3796c15074
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jun 16 15:41:52 2014 +0300
description:
Check for syscall errors that are quite unlikely to happen.
Flagged by Coverity.

diffstat:

 src/doveadm/doveadm-dump-log.c                |  8 ++++++--
 src/lib-storage/index/dbox-common/dbox-file.c |  5 ++++-
 src/master/main.c                             |  2 +-
 src/util/maildirlock.c                        |  5 +++--
 4 files changed, 14 insertions(+), 6 deletions(-)

diffs (81 lines):

diff -r fc40b1a6e962 -r 3d3796c15074 src/doveadm/doveadm-dump-log.c
--- a/src/doveadm/doveadm-dump-log.c	Mon Jun 16 15:35:07 2014 +0300
+++ b/src/doveadm/doveadm-dump-log.c	Mon Jun 16 15:41:52 2014 +0300
@@ -24,7 +24,8 @@
 		memset(PTR_OFFSET(&hdr, hdr.hdr_size), 0,
 		       sizeof(hdr) - hdr.hdr_size);
 	}
-	lseek(fd, hdr.hdr_size, SEEK_SET);
+	if (lseek(fd, hdr.hdr_size, SEEK_SET) < 0)
+		i_fatal("lseek() failed: %m");
 
 	printf("version = %u.%u\n", hdr.major_version, hdr.minor_version);
 	printf("hdr size = %u\n", hdr.hdr_size);
@@ -467,6 +468,8 @@
 	unsigned int orig_size;
 
 	offset = lseek(fd, 0, SEEK_CUR);
+	if (offset == -1)
+		i_fatal("lseek() failed: %m");
 
 	ret = read(fd, &hdr, sizeof(hdr));
 	if (ret == 0)
@@ -504,7 +507,8 @@
 		}
 		log_record_print(&hdr, buf, modseq);
 	} else {
-		lseek(fd, hdr.size - sizeof(hdr), SEEK_CUR);
+		if (lseek(fd, hdr.size - sizeof(hdr), SEEK_CUR) < 0)
+			i_fatal("lseek() failed: %m");
 	}
 	return 1;
 }
diff -r fc40b1a6e962 -r 3d3796c15074 src/lib-storage/index/dbox-common/dbox-file.c
--- a/src/lib-storage/index/dbox-common/dbox-file.c	Mon Jun 16 15:35:07 2014 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-file.c	Mon Jun 16 15:41:52 2014 +0300
@@ -555,7 +555,10 @@
 			dbox_file_set_syscall_error(ctx->file, "ftruncate()");
 			return -1;
 		}
-		o_stream_seek(ctx->output, ctx->last_checkpoint_offset);
+		if (o_stream_seek(ctx->output, ctx->last_checkpoint_offset) < 0) {
+			dbox_file_set_syscall_error(ctx->file, "lseek()");
+			return -1;
+		}
 	}
 
 	if (storage->set->parsed_fsync_mode != FSYNC_MODE_NEVER) {
diff -r fc40b1a6e962 -r 3d3796c15074 src/master/main.c
--- a/src/master/main.c	Mon Jun 16 15:35:07 2014 +0300
+++ b/src/master/main.c	Mon Jun 16 15:41:52 2014 +0300
@@ -214,7 +214,7 @@
 			"information): %s\n", buf);
 	}
 
-	close(fd);
+	i_close_fd(&fd);
 	if (unlink(path) < 0)
 		i_error("unlink(%s) failed: %m", path);
 }
diff -r fc40b1a6e962 -r 3d3796c15074 src/util/maildirlock.c
--- a/src/util/maildirlock.c	Mon Jun 16 15:35:07 2014 +0300
+++ b/src/util/maildirlock.c	Mon Jun 16 15:41:52 2014 +0300
@@ -67,7 +67,7 @@
 	lib_signals_set_handler(SIGTERM, LIBSIG_FLAG_DELAYED, sig_die, NULL);
 
 	if (pid != 0) {
-		close(fd[1]);
+		i_close_fd(&fd[1]);
 		ret = read(fd[0], &c, 1);
 		if (ret < 0) {
 			i_error("read(pipe) failed: %m");
@@ -84,7 +84,8 @@
 
 	/* child process - stdout has to be closed so that caller knows when
 	   to stop reading it. */
-	dup2(STDERR_FILENO, STDOUT_FILENO);
+	if (dup2(STDERR_FILENO, STDOUT_FILENO) < 0)
+		i_fatal("dup2() failed: %m");
 
 	timeout = strtoul(argv[2], NULL, 10);
 	if (maildir_lock(argv[1], timeout, &dotlock) <= 0)


More information about the dovecot-cvs mailing list