dovecot-2.2: Removed all invocations of atoi().
dovecot at dovecot.org
dovecot at dovecot.org
Sat Aug 29 11:50:15 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/f78e38c7cba2
changeset: 19036:f78e38c7cba2
user: Stephan Bosch <stephan at rename-it.nl>
date: Sat Aug 29 14:30:37 2015 +0300
description:
Removed all invocations of atoi().
diffstat:
src/auth/db-ldap.c | 10 +++++++---
src/auth/mech-digest-md5.c | 9 ++++++++-
src/auth/passdb-blocking.c | 27 ++++++++++++++++-----------
src/dict/dict-connection.c | 7 ++++++-
src/director/director-connection.c | 18 +++++++++++++-----
src/doveadm/doveadm-dump-index.c | 6 ++++--
src/doveadm/doveadm-who.c | 3 ++-
src/imap-login/client.c | 6 +++---
src/lib-dict/dict.h | 3 ++-
src/lib-master/master-service.c | 7 ++++---
src/lib-sql/driver-mysql.c | 7 ++++---
src/lib-sql/driver-pgsql.c | 14 +++++++++-----
src/lib-storage/mail-storage-service.c | 8 +++++---
src/lmtp/commands.c | 12 +++++++-----
src/login-common/client-common-auth.c | 19 ++++++++++++-------
src/master/main.c | 11 +++++++----
src/util/script.c | 5 ++++-
17 files changed, 113 insertions(+), 59 deletions(-)
diffs (truncated from 434 to 300 lines):
diff -r aabfe48db1cf -r f78e38c7cba2 src/auth/db-ldap.c
--- a/src/auth/db-ldap.c Sat Aug 29 14:26:30 2015 +0300
+++ b/src/auth/db-ldap.c Sat Aug 29 14:30:37 2015 +0300
@@ -1103,8 +1103,7 @@
db_ldap_set_opt(conn, conn->ld, LDAP_OPT_DEREF, &conn->set.ldap_deref,
"deref", conn->set.deref);
#ifdef LDAP_OPT_DEBUG_LEVEL
- value = atoi(conn->set.debug_level);
- if (value != 0) {
+ if (str_to_int(conn->set.debug_level, &value) >= 0 && value != 0) {
db_ldap_set_opt(conn, NULL, LDAP_OPT_DEBUG_LEVEL, &value,
"debug_level", conn->set.debug_level);
}
@@ -1143,10 +1142,15 @@
int db_ldap_connect(struct ldap_connection *conn)
{
- bool debug = atoi(conn->set.debug_level) > 0;
+ int debug_level;
+ bool debug;
struct timeval start, end;
int ret;
+ debug = FALSE;
+ if (str_to_int(conn->set.debug_level, &debug_level) >= 0)
+ debug = debug_level > 0;
+
if (conn->conn_state != LDAP_CONN_STATE_DISCONNECTED)
return 0;
diff -r aabfe48db1cf -r f78e38c7cba2 src/auth/mech-digest-md5.c
--- a/src/auth/mech-digest-md5.c Sat Aug 29 14:26:30 2015 +0300
+++ b/src/auth/mech-digest-md5.c Sat Aug 29 14:30:37 2015 +0300
@@ -334,12 +334,19 @@
}
if (strcmp(key, "nc") == 0) {
+ unsigned int nc;
+
if (request->nonce_count != NULL) {
*error = "nonce-count must not exist more than once";
return FALSE;
}
- if (atoi(value) != 1) {
+ if (str_to_uint(value, &nc) < 0) {
+ *error = "nonce-count value invalid";
+ return FALSE;
+ }
+
+ if (nc != 1) {
*error = "re-auth not supported currently";
return FALSE;
}
diff -r aabfe48db1cf -r f78e38c7cba2 src/auth/passdb-blocking.c
--- a/src/auth/passdb-blocking.c Sat Aug 29 14:26:30 2015 +0300
+++ b/src/auth/passdb-blocking.c Sat Aug 29 14:30:37 2015 +0300
@@ -38,20 +38,25 @@
}
if (strcmp(*args, "FAIL") == 0 && args[1] != NULL) {
+ int result;
/* FAIL \t result [\t user \t password [\t extra]] */
- ret = atoi(args[1]);
- if (ret == PASSDB_RESULT_OK) {
+ if (str_to_int(args[1], &result) < 0) {
/* shouldn't happen */
- } else if (args[2] == NULL) {
- /* internal failure most likely */
- return ret;
- } else if (args[3] != NULL) {
- if (*args[2] != '\0') {
- auth_request_set_field(request, "user",
- args[2], NULL);
+ } else {
+ ret = (enum passdb_result)result;
+ if (ret == PASSDB_RESULT_OK) {
+ /* shouldn't happen */
+ } else if (args[2] == NULL) {
+ /* internal failure most likely */
+ return ret;
+ } else if (args[3] != NULL) {
+ if (*args[2] != '\0') {
+ auth_request_set_field(request, "user",
+ args[2], NULL);
+ }
+ auth_worker_reply_parse_args(request, args + 3);
+ return ret;
}
- auth_worker_reply_parse_args(request, args + 3);
- return ret;
}
}
diff -r aabfe48db1cf -r f78e38c7cba2 src/dict/dict-connection.c
--- a/src/dict/dict-connection.c Sat Aug 29 14:26:30 2015 +0300
+++ b/src/dict/dict-connection.c Sat Aug 29 14:30:37 2015 +0300
@@ -21,6 +21,7 @@
const char *line)
{
const char *username, *name, *value_type;
+ unsigned int value_type_num;
if (*line++ != DICT_PROTOCOL_CMD_HELLO)
return -1;
@@ -42,7 +43,11 @@
if (*line++ != '\t')
return -1;
- conn->value_type = atoi(t_strdup_until(value_type, line - 1));
+ if (str_to_uint(t_strdup_until(value_type, line - 1), &value_type_num) < 0)
+ return -1;
+ if (value_type_num >= DICT_DATA_TYPE_LAST)
+ return -1;
+ conn->value_type = (enum dict_data_type)value_type_num;
/* get username */
username = line;
diff -r aabfe48db1cf -r f78e38c7cba2 src/director/director-connection.c
--- a/src/director/director-connection.c Sat Aug 29 14:26:30 2015 +0300
+++ b/src/director/director-connection.c Sat Aug 29 14:30:37 2015 +0300
@@ -44,7 +44,6 @@
#include "user-directory.h"
#include "director-connection.h"
-#include <stdlib.h>
#include <unistd.h>
#define MAX_INBUF_SIZE 1024
@@ -1145,6 +1144,8 @@
director_connection_handle_handshake(struct director_connection *conn,
const char *cmd, const char *const *args)
{
+ unsigned int major_version;
+
/* both incoming and outgoing connections get VERSION and ME */
if (strcmp(cmd, "VERSION") == 0 && str_array_length(args) >= 3) {
if (strcmp(args[0], DIRECTOR_VERSION_NAME) != 0) {
@@ -1152,13 +1153,17 @@
"(%s vs %s)",
conn->name, args[0], DIRECTOR_VERSION_NAME);
return -1;
- } else if (atoi(args[1]) != DIRECTOR_VERSION_MAJOR) {
+ } else if (str_to_uint(args[1], &major_version) < 0 ||
+ str_to_uint(args[2], &conn->minor_version) < 0) {
+ i_error("director(%s): Invalid protocol version: "
+ "%s.%s", conn->name, args[1], args[2]);
+ return -1;
+ } else if (major_version != DIRECTOR_VERSION_MAJOR) {
i_error("director(%s): Incompatible protocol version: "
- "%u vs %u", conn->name, atoi(args[1]),
+ "%u vs %u", conn->name, major_version,
DIRECTOR_VERSION_MAJOR);
return -1;
}
- conn->minor_version = atoi(args[2]);
conn->version_received = TRUE;
if (conn->done_pending) {
if (director_connection_send_done(conn) < 0)
@@ -1306,7 +1311,10 @@
return FALSE;
}
if (args[3] != NULL) {
- minor_version = atoi(args[3]);
+ if (str_to_uint(args[3], &minor_version) < 0) {
+ director_cmd_error(conn, "Invalid parameters");
+ return FALSE;
+ }
if (args[4] != NULL && str_to_uint(args[4], ×tamp) < 0) {
director_cmd_error(conn, "Invalid parameters");
return FALSE;
diff -r aabfe48db1cf -r f78e38c7cba2 src/doveadm/doveadm-dump-index.c
--- a/src/doveadm/doveadm-dump-index.c Sat Aug 29 14:26:30 2015 +0300
+++ b/src/doveadm/doveadm-dump-index.c Sat Aug 29 14:30:37 2015 +0300
@@ -668,8 +668,10 @@
if (index == NULL ||
mail_index_open(index, MAIL_INDEX_OPEN_FLAG_READONLY) <= 0)
i_fatal("Couldn't open index %s", argv[1]);
- if (argv[2] != NULL)
- uid = atoi(argv[2]);
+ if (argv[2] != NULL) {
+ if (str_to_uint(argv[2], &uid) < 0)
+ i_fatal("Invalid uid number %s", argv[2]);
+ }
view = mail_index_view_open(index);
cache_view = mail_cache_view_open(index->cache, view);
diff -r aabfe48db1cf -r f78e38c7cba2 src/doveadm/doveadm-who.c
--- a/src/doveadm/doveadm-who.c Sat Aug 29 14:26:30 2015 +0300
+++ b/src/doveadm/doveadm-who.c Sat Aug 29 14:30:37 2015 +0300
@@ -68,7 +68,8 @@
line_r->username = strchr(p, '/');
if (line_r->username == NULL)
return -1;
- line_r->refcount = atoi(refcount_str);
+ if (str_to_uint(refcount_str, &line_r->refcount) < 0)
+ return -1;
ip_str = t_strdup_until(p, line_r->username++);
(void)net_addr2ip(ip_str, &line_r->ip);
return 0;
diff -r aabfe48db1cf -r f78e38c7cba2 src/imap-login/client.c
--- a/src/imap-login/client.c Sat Aug 29 14:26:30 2015 +0300
+++ b/src/imap-login/client.c Sat Aug 29 14:30:37 2015 +0300
@@ -21,8 +21,6 @@
#include "imap-proxy.h"
#include "imap-login-settings.h"
-#include <stdlib.h>
-
#if LOGIN_MAX_INBUF_SIZE < 1024+2
# error LOGIN_MAX_INBUF_SIZE too short to fit all ID command parameters
#endif
@@ -158,7 +156,9 @@
} else if (strcasecmp(key, "x-connected-port") == 0) {
(void)net_str2port(value, &client->common.local_port);
} else if (strcasecmp(key, "x-proxy-ttl") == 0) {
- client->common.proxy_ttl = atoi(value);
+ if (str_to_uint(value, &client->common.proxy_ttl) < 0) {
+ /* nothing */
+ }
} else if (strcasecmp(key, "x-session-id") == 0 ||
strcasecmp(key, "x-session-ext-id") == 0) {
if (strlen(value) <= LOGIN_MAX_SESSION_ID_LEN) {
diff -r aabfe48db1cf -r f78e38c7cba2 src/lib-dict/dict.h
--- a/src/lib-dict/dict.h Sat Aug 29 14:26:30 2015 +0300
+++ b/src/lib-dict/dict.h Sat Aug 29 14:30:37 2015 +0300
@@ -23,7 +23,8 @@
enum dict_data_type {
DICT_DATA_TYPE_STRING = 0,
- DICT_DATA_TYPE_UINT32
+ DICT_DATA_TYPE_UINT32,
+ DICT_DATA_TYPE_LAST
};
struct dict_settings {
diff -r aabfe48db1cf -r f78e38c7cba2 src/lib-master/master-service.c
--- a/src/lib-master/master-service.c Sat Aug 29 14:26:30 2015 +0300
+++ b/src/lib-master/master-service.c Sat Aug 29 14:30:37 2015 +0300
@@ -164,7 +164,8 @@
int count;
value = getenv("SOCKET_COUNT");
- count = value == NULL ? 0 : atoi(value);
+ if (value == NULL || str_to_uint(value, &count) < 0)
+ count = 0;
fd_debug_verify_leaks(MASTER_LISTEN_FD_FIRST + count, 1024);
}
#endif
@@ -222,8 +223,8 @@
/* listener configuration */
value = getenv("SOCKET_COUNT");
- if (value != NULL)
- service->socket_count = atoi(value);
+ if (value != NULL && str_to_uint(value, &service->socket_count) < 0)
+ i_fatal("Invalid SOCKET_COUNT environment");
T_BEGIN {
master_service_init_socket_listeners(service);
} T_END;
diff -r aabfe48db1cf -r f78e38c7cba2 src/lib-sql/driver-mysql.c
--- a/src/lib-sql/driver-mysql.c Sat Aug 29 14:26:30 2015 +0300
+++ b/src/lib-sql/driver-mysql.c Sat Aug 29 14:30:37 2015 +0300
@@ -184,9 +184,10 @@
else if (strcmp(name, "port") == 0) {
if (net_str2port(value, &db->port) < 0)
i_fatal("mysql: Invalid port number: %s", value);
- } else if (strcmp(name, "client_flags") == 0)
- db->client_flags = atoi(value);
- else if (strcmp(name, "ssl_cert") == 0)
+ } else if (strcmp(name, "client_flags") == 0) {
+ if (str_to_uint(value, &db->client_flags) < 9)
+ i_fatal("mysql: Invalid client flags: %s", value);
+ } else if (strcmp(name, "ssl_cert") == 0)
field = &db->ssl_cert;
else if (strcmp(name, "ssl_key") == 0)
field = &db->ssl_key;
diff -r aabfe48db1cf -r f78e38c7cba2 src/lib-sql/driver-pgsql.c
--- a/src/lib-sql/driver-pgsql.c Sat Aug 29 14:26:30 2015 +0300
+++ b/src/lib-sql/driver-pgsql.c Sat Aug 29 14:30:37 2015 +0300
@@ -898,7 +898,9 @@
} else if (query->affected_rows != NULL) {
struct pgsql_result *pg_result = (struct pgsql_result *)result;
- *query->affected_rows = atoi(PQcmdTuples(pg_result->pgres));
+ if (str_to_uint(PQcmdTuples(pg_result->pgres),
+ query->affected_rows) < 0)
+ i_unreached();
}
driver_pgsql_transaction_unref(ctx);
}
@@ -969,8 +971,9 @@
struct pgsql_result *pg_result =
(struct pgsql_result *)result;
- *query->affected_rows =
- atoi(PQcmdTuples(pg_result->pgres));
+ if (str_to_uint(PQcmdTuples(pg_result->pgres),
+ query->affected_rows) < 0)
+ i_unreached();
More information about the dovecot-cvs
mailing list