dovecot-2.2: Removed all invocations of strtoll() and friends.

dovecot at dovecot.org dovecot at dovecot.org
Sat Aug 29 11:50:16 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/f8ab4f979e92
changeset: 19038:f8ab4f979e92
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Sat Aug 29 14:42:49 2015 +0300
description:
Removed all invocations of strtoll() and friends.

diffstat:

 configure.ac                                    |  40 ++---------------------
 src/anvil/anvil-connection.c                    |  15 +++++++-
 src/auth/checkpassword-reply.c                  |  12 ++++--
 src/doveadm/doveadm-penalty.c                   |   7 ++-
 src/doveadm/doveadm-who.c                       |   3 +-
 src/doveadm/dsync/dsync-ibc-stream.c            |  34 +++++++++++++++++---
 src/lib-dict/dict-file.c                        |   5 +-
 src/lib-fs/fs-posix.c                           |   7 +++-
 src/lib-otp/otp-parse.c                         |   4 +-
 src/lib-settings/settings-parser.c              |  24 ++++++++------
 src/lib-storage/index/dbox-common/dbox-file.c   |  21 +++++++++---
 src/lib-storage/index/dbox-common/dbox-mail.c   |  12 ++++++-
 src/lib-storage/index/maildir/maildir-uidlist.c |  12 ++++++-
 src/lib-storage/mailbox-uidvalidity.c           |   9 +---
 src/lib/compat.c                                |  41 -------------------------
 src/lib/compat.h                                |   9 -----
 src/lib/rand.c                                  |   5 +-
 src/lib/var-expand.c                            |   3 +-
 src/log/log-connection.c                        |   8 +++-
 src/login-common/sasl-server.c                  |   8 +++-
 src/master/main.c                               |   7 +++-
 src/plugins/quota/quota-dict.c                  |   5 +-
 src/plugins/quota/quota-maildir.c               |   7 +++-
 src/plugins/quota/quota-util.c                  |  27 +++++++++++----
 src/util/maildirlock.c                          |   3 +-
 25 files changed, 172 insertions(+), 156 deletions(-)

diffs (truncated from 774 to 300 lines):

diff -r de73e7121676 -r f8ab4f979e92 configure.ac
--- a/configure.ac	Sat Aug 29 14:31:51 2015 +0300
+++ b/configure.ac	Sat Aug 29 14:42:49 2015 +0300
@@ -453,10 +453,10 @@
 AC_CHECK_FUNCS(fcntl flock lockf inet_aton sigaction getpagesize madvise \
                strcasecmp stricmp vsyslog writev pread uname unsetenv \
 	       setrlimit setproctitle seteuid setreuid setegid setresgid \
-	       strtoull strtoll strtouq strtoq getmntinfo \
-	       setpriority quotactl getmntent kqueue kevent backtrace_symbols \
-	       walkcontext dirfd clearenv malloc_usable_size glob fallocate \
-	       posix_fadvise getpeereid getpeerucred inotify_init)
+	       getmntinfo setpriority quotactl getmntent kqueue kevent \
+	       backtrace_symbols walkcontext dirfd clearenv \
+	       malloc_usable_size glob fallocate posix_fadvise \
+	       getpeereid getpeerucred inotify_init)
 
 AC_CHECK_TYPES([struct sockpeercred],,,[
 #include <sys/types.h>
@@ -482,38 +482,6 @@
   AC_DEFINE(HAVE_TYPEOF,, [Define if you have typeof()])
 fi
 
-dnl strtoimax and strtoumax are macros in HP-UX, so inttypes.h must be included
-dnl Link instead of just compiling since there's something wrong with Tru64
-AC_CACHE_CHECK([for strtoimax],i_cv_have_strtoimax,[
-  AC_TRY_LINK([
-    #include <inttypes.h>
-  ], [
-    strtoimax(0, 0, 0);
-  ], [
-    i_cv_have_strtoimax=yes
-  ], [
-    i_cv_have_strtoimax=no
-  ])
-])
-if test $i_cv_have_strtoimax = yes; then
-  AC_DEFINE(HAVE_STRTOIMAX,, [Define if you have strtoimax function])
-fi
-
-AC_CACHE_CHECK([for strtoumax],i_cv_have_strtoumax,[
-  AC_TRY_LINK([
-    #include <inttypes.h>
-  ], [
-    strtoumax(0, 0, 0);
-  ], [
-    i_cv_have_strtoumax=yes
-  ], [
-    i_cv_have_strtoumax=no
-  ])
-])
-if test $i_cv_have_strtoumax = yes; then
-  AC_DEFINE(HAVE_STRTOUMAX,, [Define if you have strtoumax function])
-fi
-
 dnl * I/O loop function
 have_ioloop=no
 
diff -r de73e7121676 -r f8ab4f979e92 src/anvil/anvil-connection.c
--- a/src/anvil/anvil-connection.c	Sat Aug 29 14:31:51 2015 +0300
+++ b/src/anvil/anvil-connection.c	Sat Aug 29 14:42:49 2015 +0300
@@ -58,14 +58,20 @@
 			*error_r = "CONNECT: Not enough parameters";
 			return -1;
 		}
-		pid = strtol(args[0], NULL, 10);
+		if (str_to_pid(args[0], &pid) < 0) {
+			*error_r = "CONNECT: Invalid pid";
+			return -1;
+		}
 		connect_limit_connect(connect_limit, pid, args[1]);
 	} else if (strcmp(cmd, "DISCONNECT") == 0) {
 		if (args[0] == NULL || args[1] == NULL) {
 			*error_r = "DISCONNECT: Not enough parameters";
 			return -1;
 		}
-		pid = strtol(args[0], NULL, 10);
+		if (str_to_pid(args[0], &pid) < 0) {
+			*error_r = "DISCONNECT: Invalid pid";
+			return -1;
+		}
 		connect_limit_disconnect(connect_limit, pid, args[1]);
 	} else if (strcmp(cmd, "CONNECT-DUMP") == 0) {
 		connect_limit_dump(connect_limit, conn->output);
@@ -78,7 +84,10 @@
 			*error_r = "KILL sent by a non-master connection";
 			return -1;
 		}
-		pid = strtol(args[0], NULL, 10);
+		if (str_to_pid(args[0], &pid) < 0) {
+			*error_r = "KILL: Invalid pid";
+			return -1;
+		}
 		connect_limit_disconnect_pid(connect_limit, pid);
 	} else if (strcmp(cmd, "LOOKUP") == 0) {
 		if (args[0] == NULL) {
diff -r de73e7121676 -r f8ab4f979e92 src/auth/checkpassword-reply.c
--- a/src/auth/checkpassword-reply.c	Sat Aug 29 14:31:51 2015 +0300
+++ b/src/auth/checkpassword-reply.c	Sat Aug 29 14:42:49 2015 +0300
@@ -11,14 +11,18 @@
 int main(void)
 {
 	string_t *str;
-	const char *user, *home, *authorized, *orig_uid;
+	const char *user, *home, *authorized, *orig_uid_env;
 	const char *extra_env, *key, *value, *const *tmp;
 	bool uid_found = FALSE, gid_found = FALSE;
+	uid_t orig_uid;
 
 	lib_init();
 	str = t_str_new(1024);
 
-	orig_uid = getenv("ORIG_UID");
+	orig_uid_env = getenv("ORIG_UID");
+	if (orig_uid_env == NULL || str_to_uid(orig_uid_env, &orig_uid) < 0)
+		orig_uid = (uid_t)-1;
+
 	/* ORIG_UID should have the auth process's UID that forked us.
 	   if the checkpassword changed the UID, this could be a security hole
 	   because the UID's other processes can ptrace this process and write
@@ -30,9 +34,9 @@
 	      userdb_uid instead)
 	   */
 	if (getenv("INSECURE_SETUID") == NULL &&
-	    (orig_uid == NULL || strtoul(orig_uid, NULL, 10) != getuid()) &&
+	    (orig_uid == (uid_t)-1 || orig_uid != getuid()) &&
 	    getuid() == geteuid() && getgid() == getegid()) {
-		if (orig_uid == NULL) {
+		if (orig_uid_env == NULL) {
 			i_error("checkpassword: ORIG_UID environment was dropped by checkpassword. "
 				"Can't verify if we're safe to run. See "
 				"http://wiki2.dovecot.org/AuthDatabase/CheckPassword#Security");
diff -r de73e7121676 -r f8ab4f979e92 src/doveadm/doveadm-penalty.c
--- a/src/doveadm/doveadm-penalty.c	Sat Aug 29 14:31:51 2015 +0300
+++ b/src/doveadm/doveadm-penalty.c	Sat Aug 29 14:42:49 2015 +0300
@@ -36,9 +36,10 @@
 	memset(line_r, 0, sizeof(*line_r));
 
 	(void)net_addr2ip(ident, &line_r->ip);
-	line_r->penalty = strtoul(penalty_str, NULL, 10);
-	line_r->last_penalty = strtoul(last_penalty_str, NULL, 10);
-	line_r->last_update = strtoul(last_update_str, NULL, 10);
+	if (str_to_uint(penalty_str, &line_r->penalty) < 0 ||
+	    str_to_time(last_penalty_str, &line_r->last_penalty) < 0 ||
+	    str_to_time(last_update_str, &line_r->last_update) < 0)
+		i_fatal("Read invalid penalty line: %s", line);
 }
 
 static void
diff -r de73e7121676 -r f8ab4f979e92 src/doveadm/doveadm-who.c
--- a/src/doveadm/doveadm-who.c	Sat Aug 29 14:31:51 2015 +0300
+++ b/src/doveadm/doveadm-who.c	Sat Aug 29 14:42:49 2015 +0300
@@ -63,7 +63,8 @@
 	p = strchr(ident, '/');
 	if (p == NULL)
 		return -1;
-	line_r->pid = strtoul(pid_str, NULL, 10);
+	if (str_to_pid(pid_str, &line_r->pid) < 0)
+		return -1;
 	line_r->service = t_strdup_until(ident, p++);
 	line_r->username = strchr(p, '/');
 	if (line_r->username == NULL)
diff -r de73e7121676 -r f8ab4f979e92 src/doveadm/dsync/dsync-ibc-stream.c
--- a/src/doveadm/dsync/dsync-ibc-stream.c	Sat Aug 29 14:31:51 2015 +0300
+++ b/src/doveadm/dsync/dsync-ibc-stream.c	Sat Aug 29 14:42:49 2015 +0300
@@ -1593,6 +1593,7 @@
 	struct dsync_deserializer_decoder *decoder;
 	struct dsync_mail_change *change;
 	const char *value;
+	unsigned int uintval;
 	enum dsync_ibc_recv_ret ret;
 
 	p_clear(pool);
@@ -1639,12 +1640,33 @@
 		return DSYNC_IBC_RECV_RET_TRYAGAIN;
 	}
 
-	if (dsync_deserializer_decode_try(decoder, "add_flags", &value))
-		change->add_flags = strtoul(value, NULL, 16);
-	if (dsync_deserializer_decode_try(decoder, "remove_flags", &value))
-		change->remove_flags = strtoul(value, NULL, 16);
-	if (dsync_deserializer_decode_try(decoder, "final_flags", &value))
-		change->final_flags = strtoul(value, NULL, 16);
+	if (dsync_deserializer_decode_try(decoder, "add_flags", &value)) {
+		if (str_to_uint_hex(value, &uintval) < 0 ||
+		    uintval > (uint8_t)-1) {
+			dsync_ibc_input_error(ibc, decoder,
+				"Invalid add_flags: %s", value);
+			return DSYNC_IBC_RECV_RET_TRYAGAIN;
+		}
+		change->add_flags = uintval;
+	}
+	if (dsync_deserializer_decode_try(decoder, "remove_flags", &value)) {
+		if (str_to_uint_hex(value, &uintval) < 0 ||
+		    uintval > (uint8_t)-1) {
+			dsync_ibc_input_error(ibc, decoder,
+				"Invalid remove_flags: %s", value);
+			return DSYNC_IBC_RECV_RET_TRYAGAIN;
+		}
+		change->remove_flags = uintval;
+	}
+	if (dsync_deserializer_decode_try(decoder, "final_flags", &value)) {
+		if (str_to_uint_hex(value, &uintval) < 0 ||
+		    uintval > (uint8_t)-1) {
+			dsync_ibc_input_error(ibc, decoder,
+				"Invalid final_flags: %s", value);
+			return DSYNC_IBC_RECV_RET_TRYAGAIN;
+		}
+		change->final_flags = uintval;
+	}
 	if (dsync_deserializer_decode_try(decoder, "keywords_reset", &value))
 		change->keywords_reset = TRUE;
 
diff -r de73e7121676 -r f8ab4f979e92 src/lib-dict/dict-file.c
--- a/src/lib-dict/dict-file.c	Sat Aug 29 14:31:51 2015 +0300
+++ b/src/lib-dict/dict-file.c	Sat Aug 29 14:42:49 2015 +0300
@@ -329,8 +329,9 @@
 				*atomic_inc_not_found_r = TRUE;
 				break;
 			}
-			diff = strtoll(old_value, NULL, 10) +
-				change->value.diff;
+			if (str_to_llong(old_value, &diff) < 0)
+				i_unreached();
+			diff +=	change->value.diff;
 			tmp = t_strdup_printf("%lld", diff);
 			new_len = strlen(tmp);
 			if (old_value == NULL || new_len > strlen(old_value))
diff -r de73e7121676 -r f8ab4f979e92 src/lib-fs/fs-posix.c
--- a/src/lib-fs/fs-posix.c	Sat Aug 29 14:31:51 2015 +0300
+++ b/src/lib-fs/fs-posix.c	Sat Aug 29 14:42:49 2015 +0300
@@ -104,7 +104,12 @@
 			else
 				fs->path_prefix = i_strdup(arg + 7);
 		} else if (strncmp(arg, "mode=", 5) == 0) {
-			fs->mode = strtoul(arg+5, NULL, 8) & 0666;
+			unsigned int mode;
+			if (str_to_uint_oct(arg+5, &mode) < 0) {
+				fs_set_error(_fs, "Invalid mode value: %s", arg+5);
+				return -1;
+			}
+			fs->mode = mode & 0666;
 			if (fs->mode == 0) {
 				fs_set_error(_fs, "Invalid mode: %s", arg+5);
 				return -1;
diff -r de73e7121676 -r f8ab4f979e92 src/lib-otp/otp-parse.c
--- a/src/lib-otp/otp-parse.c	Sat Aug 29 14:31:51 2015 +0300
+++ b/src/lib-otp/otp-parse.c	Sat Aug 29 14:42:49 2015 +0300
@@ -148,7 +148,6 @@
 			struct otp_state *state)
 {
 	const char *p, *s;
-	char *end;
 	unsigned int i = 0;
 	int algo;
 
@@ -164,8 +163,7 @@
 	state->algo = algo;
 
 	s = p;
-	state->seq = strtol(s, &end, 10); p = end;
-	if ((p == s) || !IS_LWS(*p))
+	if (str_parse_int(s, &state->seq, &p) < 0 || !IS_LWS(*p))
 		return -3;
 	p++;
 
diff -r de73e7121676 -r f8ab4f979e92 src/lib-settings/settings-parser.c
--- a/src/lib-settings/settings-parser.c	Sat Aug 29 14:31:51 2015 +0300
+++ b/src/lib-settings/settings-parser.c	Sat Aug 29 14:42:49 2015 +0300
@@ -338,13 +338,11 @@
 	  unsigned int *result_r)
 {
 	unsigned long long octal;
-	char *p;
 
 	if (*value != '0')
 		return get_uint(ctx, value, result_r);
 
-	octal = strtoull(value + 1, &p, 8);
-	if (*p != '\0' || octal > UINT_MAX) {
+	if (str_to_ullong_oct(value+1, &octal) < 0) {
 		ctx->error = p_strconcat(ctx->parser_pool, "Invalid number: ",
 					 value, NULL);
 	}
@@ -355,10 +353,13 @@
 int settings_get_time(const char *str, unsigned int *secs_r,
 		      const char **error_r)
 {
-	unsigned int num, multiply = 1;
-	char *p;
+	uintmax_t num, multiply = 1;
+	const char *p;
 
-	num = strtoull(str, &p, 10);
+	if (str_parse_uintmax(str, &num, &p) < 0) {
+		*error_r = t_strconcat("Invalid time interval: ", str, NULL);
+		return -1;
+	}
 	while (*p == ' ') p++;
 	switch (i_toupper(*p)) {
 	case 'S':


More information about the dovecot-cvs mailing list