dovecot-2.0: Started using str_to_*() functions instead of libc'...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Apr 7 01:49:35 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/260e190306b0
changeset: 11086:260e190306b0
user: Timo Sirainen <tss at iki.fi>
date: Wed Apr 07 01:49:00 2010 +0300
description:
Started using str_to_*() functions instead of libc's ones.
diffstat:
src/anvil/anvil-connection.c | 14 +++---
src/auth/auth-client-connection.c | 7 +--
src/auth/auth-master-connection.c | 21 +++++-----
src/auth/auth-request-handler.c | 9 +---
src/auth/auth-request.c | 2 +-
src/auth/auth-worker-client.c | 30 +++++++++------
src/auth/auth-worker-server.c | 5 +-
src/auth/mech-digest-md5.c | 4 +-
src/auth/passdb-pam.c | 8 +++-
src/auth/userdb.c | 16 ++------
src/config/config-connection.c | 4 +-
src/config/config-parser.c | 10 +++--
src/dict/dict-commands.c | 26 +++++--------
src/imap/cmd-fetch.c | 8 ++--
src/imap/cmd-select.c | 14 +++---
src/imap/cmd-store.c | 6 ++-
src/lib-auth/auth-master.c | 12 +++--
src/lib-auth/auth-server-connection.c | 17 ++++----
src/lib-dict/dict-client.c | 5 ++-
src/lib-dict/dict-db.c | 6 ++-
src/lib-master/master-login-auth.c | 17 +++++---
src/lib-master/master-service.c | 24 ++++-------
src/lib-settings/settings-parser.c | 31 ++++++++++++---
src/lib-sql/sql-api.c | 14 +++----
src/lib-storage/index/dbox-multi/mdbox-map.c | 5 +-
src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c | 3 +-
src/lib-storage/index/dbox-multi/mdbox-sync.c | 6 +-
src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c | 6 +--
src/lib-storage/index/maildir/maildir-keywords.c | 7 ++-
src/lib-storage/index/maildir/maildir-mail.c | 11 +----
src/lib-storage/mail-search-build.c | 13 ++----
src/lib-storage/mail-storage-service.c | 16 ++------
src/lib/file-dotlock.c | 3 +-
src/lib/network.c | 5 +-
src/lib/restrict-access.c | 35 +++++++++++------
src/plugins/acl/acl-backend-vfile.c | 10 +++-
src/plugins/expire/expire-env.c | 2 +-
src/plugins/fts-squat/fts-backend-squat.c | 8 +--
src/plugins/imap-quota/imap-quota-plugin.c | 3 +-
src/plugins/imap-zlib/imap-zlib-plugin.c | 4 +-
src/plugins/trash/trash-plugin.c | 7 +++-
src/plugins/zlib/zlib-plugin.c | 6 +-
42 files changed, 238 insertions(+), 222 deletions(-)
diffs (truncated from 1308 to 300 lines):
diff -r b262aad23e59 -r 260e190306b0 src/anvil/anvil-connection.c
--- a/src/anvil/anvil-connection.c Wed Apr 07 01:48:03 2010 +0300
+++ b/src/anvil/anvil-connection.c Wed Apr 07 01:49:00 2010 +0300
@@ -104,21 +104,21 @@
*error_r = "PENALTY-INC: Not enough parameters";
return -1;
}
- checksum = strtoul(args[1], NULL, 10);
- value = strtoul(args[2], NULL, 10);
- if (value > PENALTY_MAX_VALUE ||
+ if (str_to_uint(args[1], &checksum) < 0 ||
+ str_to_uint(args[2], &value) < 0 ||
+ value > PENALTY_MAX_VALUE ||
(value == 0 && checksum != 0)) {
*error_r = "PENALTY-INC: Invalid parameters";
return -1;
}
penalty_inc(penalty, args[0], checksum, value);
} else if (strcmp(cmd, "PENALTY-SET-EXPIRE-SECS") == 0) {
- if (args[0] == NULL) {
+ if (args[0] == NULL || str_to_uint(args[0], &value) < 0) {
*error_r = "PENALTY-SET-EXPIRE-SECS: "
- "Not enough parameters";
+ "Invalid parameters";
return -1;
}
- penalty_set_expire_secs(penalty, atoi(args[0]));
+ penalty_set_expire_secs(penalty, value);
} else if (strcmp(cmd, "PENALTY-DUMP") == 0) {
penalty_dump(penalty, conn->output);
} else {
@@ -150,7 +150,7 @@
if (str_array_length(args) < 4 ||
strcmp(args[0], "VERSION") != 0 ||
strcmp(args[1], "anvil") != 0 ||
- atoi(args[2]) != ANVIL_CLIENT_PROTOCOL_MAJOR_VERSION) {
+ !str_uint_equals(args[2], ANVIL_CLIENT_PROTOCOL_MAJOR_VERSION)) {
i_error("Anvil client not compatible with this server "
"(mixed old and new binaries?)");
anvil_connection_destroy(conn);
diff -r b262aad23e59 -r 260e190306b0 src/auth/auth-client-connection.c
--- a/src/auth/auth-client-connection.c Wed Apr 07 01:48:03 2010 +0300
+++ b/src/auth/auth-client-connection.c Wed Apr 07 01:49:00 2010 +0300
@@ -89,8 +89,7 @@
i_assert(conn->pid == 0);
- pid = (unsigned int)strtoul(args, NULL, 10);
- if (pid == 0) {
+ if (str_to_uint(args, &pid) < 0 || pid == 0) {
i_error("BUG: Authentication client said it's PID 0");
return FALSE;
}
@@ -221,8 +220,8 @@
if (!conn->version_received) {
/* make sure the major version matches */
if (strncmp(line, "VERSION\t", 8) != 0 ||
- atoi(t_strcut(line + 8, '\t')) !=
- AUTH_CLIENT_PROTOCOL_MAJOR_VERSION) {
+ !str_uint_equals(t_strcut(line + 8, '\t'),
+ AUTH_CLIENT_PROTOCOL_MAJOR_VERSION)) {
i_error("Authentication client "
"not compatible with this server "
"(mixed old and new binaries?)");
diff -r b262aad23e59 -r 260e190306b0 src/auth/auth-master-connection.c
--- a/src/auth/auth-master-connection.c Wed Apr 07 01:48:03 2010 +0300
+++ b/src/auth/auth-master-connection.c Wed Apr 07 01:49:00 2010 +0300
@@ -75,14 +75,14 @@
/* <id> <client-pid> <client-id> <cookie> */
list = t_strsplit(args, "\t");
- if (str_array_length(list) < 4) {
+ if (str_array_length(list) < 4 ||
+ str_to_uint(list[0], &id) < 0 ||
+ str_to_uint(list[1], &client_pid) < 0 ||
+ str_to_uint(list[2], &client_id) < 0) {
i_error("BUG: Master sent broken REQUEST");
return FALSE;
}
- id = (unsigned int)strtoul(list[0], NULL, 10);
- client_pid = (unsigned int)strtoul(list[1], NULL, 10);
- client_id = (unsigned int)strtoul(list[2], NULL, 10);
buffer_create_data(&buf, cookie, sizeof(cookie));
if (hex_to_binary(list[3], &buf) < 0) {
i_error("BUG: Master sent broken REQUEST cookie");
@@ -114,16 +114,18 @@
{
struct auth_request *auth_request;
const char *const *list, *name, *arg;
+ unsigned int id;
/* <id> <userid> [<parameters>] */
list = t_strsplit(args, "\t");
- if (list[0] == NULL || list[1] == NULL) {
+ if (list[0] == NULL || list[1] == NULL ||
+ str_to_uint(list[0], &id) < 0) {
i_error("BUG: Master sent broken %s", cmd);
return -1;
}
auth_request = auth_request_new_dummy();
- auth_request->id = (unsigned int)strtoul(list[0], NULL, 10);
+ auth_request->id = id;
auth_request->context = conn;
auth_master_connection_ref(conn);
@@ -358,11 +360,10 @@
unsigned int id;
/* <id> */
- if (*args == '\0') {
+ if (str_to_uint(args, &id) < 0) {
i_error("BUG: Master sent broken LIST");
return FALSE;
}
- id = strtoul(args, NULL, 10);
while (userdb != NULL && userdb->userdb->iface->iterate_init == NULL)
userdb = userdb->next;
@@ -441,8 +442,8 @@
/* make sure the major version matches */
if (strncmp(line, "VERSION\t", 8) != 0 ||
- atoi(t_strcut(line + 8, '\t')) !=
- AUTH_MASTER_PROTOCOL_MAJOR_VERSION) {
+ !str_uint_equals(t_strcut(line + 8, '\t'),
+ AUTH_MASTER_PROTOCOL_MAJOR_VERSION)) {
i_error("Master not compatible with this server "
"(mixed old and new binaries?)");
auth_master_connection_destroy(&conn);
diff -r b262aad23e59 -r 260e190306b0 src/auth/auth-request-handler.c
--- a/src/auth/auth-request-handler.c Wed Apr 07 01:48:03 2010 +0300
+++ b/src/auth/auth-request-handler.c Wed Apr 07 01:49:00 2010 +0300
@@ -314,14 +314,13 @@
/* <id> <mechanism> [...] */
list = t_strsplit(args, "\t");
- if (list[0] == NULL || list[1] == NULL) {
+ if (list[0] == NULL || list[1] == NULL ||
+ str_to_uint(list[0], &id) < 0) {
i_error("BUG: Authentication client %u "
"sent broken AUTH request", handler->client_pid);
return FALSE;
}
- id = (unsigned int)strtoul(list[0], NULL, 10);
-
mech = mech_module_find(list[1]);
if (mech == NULL) {
/* unsupported mechanism */
@@ -427,14 +426,12 @@
unsigned int id;
data = strchr(args, '\t');
- if (data == NULL) {
+ if (data == NULL || str_to_uint(args, &id) < 0) {
i_error("BUG: Authentication client sent broken CONT request");
return FALSE;
}
data++;
- id = (unsigned int)strtoul(args, NULL, 10);
-
request = hash_table_lookup(handler->requests, POINTER_CAST(id));
if (request == NULL) {
struct auth_stream_reply *reply;
diff -r b262aad23e59 -r 260e190306b0 src/auth/auth-request.c
--- a/src/auth/auth-request.c Wed Apr 07 01:48:03 2010 +0300
+++ b/src/auth/auth-request.c Wed Apr 07 01:49:00 2010 +0300
@@ -1272,7 +1272,7 @@
if (!net_ip_compare(&ip, &request->local_ip))
return FALSE;
- if (port != NULL && (unsigned int)atoi(port) != request->local_port)
+ if (port != NULL && !str_uint_equals(port, request->local_port))
return FALSE;
return destuser == NULL ||
strcmp(destuser, request->original_username) == 0;
diff -r b262aad23e59 -r 260e190306b0 src/auth/auth-worker-client.c
--- a/src/auth/auth-worker-client.c Wed Apr 07 01:48:03 2010 +0300
+++ b/src/auth/auth-worker-client.c Wed Apr 07 01:49:00 2010 +0300
@@ -151,11 +151,10 @@
unsigned int passdb_id;
/* <passdb id> <password> [<args>] */
- if (args[1] == NULL) {
+ if (str_to_uint(args[0], &passdb_id) < 0 || args[1] == NULL) {
i_error("BUG: Auth worker server sent us invalid PASSV");
return FALSE;
}
- passdb_id = atoi(args[0]);
password = args[1];
auth_request = worker_auth_request_new(client, id, args + 2);
@@ -256,11 +255,10 @@
unsigned int passdb_id;
/* <passdb id> <scheme> [<args>] */
- if (args[1] == NULL) {
+ if (str_to_uint(args[0], &passdb_id) < 0 || args[1] == NULL) {
i_error("BUG: Auth worker server sent us invalid PASSL");
return FALSE;
}
- passdb_id = atoi(args[0]);
scheme = args[1];
auth_request = worker_auth_request_new(client, id, args + 2);
@@ -318,11 +316,10 @@
const char *creds;
/* <passdb id> <credentials> [<args>] */
- if (args[1] == NULL) {
+ if (str_to_uint(args[0], &passdb_id) < 0 || args[1] == NULL) {
i_error("BUG: Auth worker server sent us invalid SETCRED");
return FALSE;
}
- passdb_id = atoi(args[0]);
creds = args[1];
auth_request = worker_auth_request_new(client, id, args + 2);
@@ -407,7 +404,10 @@
unsigned int userdb_id;
/* <userdb id> [<args>] */
- userdb_id = atoi(args[0]);
+ if (str_to_uint(args[0], &userdb_id) < 0) {
+ i_error("BUG: Auth worker server sent us invalid USER");
+ return FALSE;
+ }
auth_request = worker_auth_request_new(client, id, args + 1);
if (auth_request->user == NULL || auth_request->service == NULL) {
@@ -504,8 +504,14 @@
{
struct auth_worker_list_context *ctx;
struct auth_userdb *userdb;
+ unsigned int userdb_id;
- userdb = auth_userdb_find_by_id(client->auth->userdbs, atoi(args[0]));
+ if (str_to_uint(args[0], &userdb_id) < 0) {
+ i_error("BUG: Auth worker server sent us invalid LIST");
+ return FALSE;
+ }
+
+ userdb = auth_userdb_find_by_id(client->auth->userdbs, userdb_id);
if (userdb == NULL) {
i_error("BUG: LIST had invalid userdb ID");
return FALSE;
@@ -534,12 +540,12 @@
bool ret = FALSE;
args = t_strsplit(line, "\t");
- if (args[0] == NULL || args[1] == NULL || args[2] == NULL) {
+ if (args[0] == NULL || args[1] == NULL || args[2] == NULL ||
+ str_to_uint(args[0], &id) < 0) {
i_error("BUG: Invalid input: %s", line);
return FALSE;
}
- id = (unsigned int)strtoul(args[0], NULL, 10);
if (strcmp(args[1], "PASSV") == 0)
ret = auth_worker_handle_passv(client, id, args + 2);
else if (strcmp(args[1], "PASSL") == 0)
@@ -601,8 +607,8 @@
return;
if (strncmp(line, "VERSION\tauth-worker\t", 20) != 0 ||
- atoi(t_strcut(line + 20, '\t')) !=
- AUTH_WORKER_PROTOCOL_MAJOR_VERSION) {
+ !str_uint_equals(t_strcut(line + 20, '\t'),
+ AUTH_WORKER_PROTOCOL_MAJOR_VERSION)) {
i_error("Auth worker not compatible with this server "
"(mixed old and new binaries?)");
auth_worker_client_destroy(&client);
diff -r b262aad23e59 -r 260e190306b0 src/auth/auth-worker-server.c
--- a/src/auth/auth-worker-server.c Wed Apr 07 01:48:03 2010 +0300
+++ b/src/auth/auth-worker-server.c Wed Apr 07 01:49:00 2010 +0300
@@ -277,11 +277,10 @@
}
id_str = line;
line = strchr(line, '\t');
- if (line == NULL)
+ if (line == NULL ||
+ str_to_uint(t_strdup_until(id_str, line), &id) < 0)
continue;
- id = (unsigned int)strtoul(t_strcut(id_str, '\t'),
- NULL, 10);
if (conn->request != NULL && id == conn->request->id) {
auth_worker_request_handle(conn, conn->request,
line + 1);
diff -r b262aad23e59 -r 260e190306b0 src/auth/mech-digest-md5.c
--- a/src/auth/mech-digest-md5.c Wed Apr 07 01:48:03 2010 +0300
+++ b/src/auth/mech-digest-md5.c Wed Apr 07 01:49:00 2010 +0300
@@ -384,8 +384,8 @@
return FALSE;
}
- request->maxbuf = strtoul(value, NULL, 10);
More information about the dovecot-cvs
mailing list