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);
}
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;
}
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;
}
}
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;
}
}
const char *line)
{
const char *username, *name, *value_type;
+ unsigned int value_type_num;
if (*line++ != DICT_PROTOCOL_CMD_HELLO)
return -1;
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;
#include "user-directory.h"
#include "director-connection.h"
-#include <stdlib.h>
#include <unistd.h>
#define MAX_INBUF_SIZE 1024
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) {
"(%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)
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;
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);
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;
#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
} 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) {
enum dict_data_type {
DICT_DATA_TYPE_STRING = 0,
- DICT_DATA_TYPE_UINT32
+ DICT_DATA_TYPE_UINT32,
+ DICT_DATA_TYPE_LAST
};
struct dict_settings {
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
/* 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;
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;
} 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);
}
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();
}
sql_result_unref(result);
}
struct pgsql_result *pg_result =
(struct pgsql_result *)result;
- *single_query->affected_rows =
- atoi(PQcmdTuples(pg_result->pgres));
+ if (str_to_uint(PQcmdTuples(pg_result->pgres),
+ single_query->affected_rows) < 0)
+ i_unreached();
}
}
if (result != NULL)
p_strdup(user->pool, line + 19);
} else if (strncmp(line, "nice=", 5) == 0) {
#ifdef HAVE_SETPRIORITY
- int n = atoi(line + 5);
-
- if (n != 0) {
+ int n;
+ if (str_to_int(line + 5, &n) < 0) {
+ i_error("userdb returned invalid nice value %s",
+ line + 5);
+ } else if (n != 0) {
if (setpriority(PRIO_PROCESS, 0, n) < 0)
i_error("setpriority(%d) failed: %m", n);
}
#include "commands.h"
#include "lmtp-proxy.h"
-#include <stdlib.h>
-
#define ERRSTR_TEMP_MAILBOX_FAIL "451 4.3.0 <%s> Temporary internal error"
#define ERRSTR_TEMP_USERDB_FAIL_PREFIX "451 4.3.0 <%s> "
#define ERRSTR_TEMP_USERDB_FAIL \
return FALSE;
}
port_set = TRUE;
- } else if (strcmp(key, "proxy_timeout") == 0)
- set->timeout_msecs = atoi(value)*1000;
- else if (strcmp(key, "protocol") == 0) {
+ } else if (strcmp(key, "proxy_timeout") == 0) {
+ if (str_to_uint(value, &set->timeout_msecs) < 0) {
+ i_error("proxy: Invalid proxy_timeout value %s", value);
+ return FALSE;
+ }
+ set->timeout_msecs *= 1000;
+ } else if (strcmp(key, "protocol") == 0) {
if (strcmp(value, "lmtp") == 0)
set->protocol = LMTP_CLIENT_PROTOCOL_LMTP;
else if (strcmp(value, "smtp") == 0) {
#include "master-service-ssl-settings.h"
#include "client-common.h"
-#include <stdlib.h>
-
#define PROXY_FAILURE_MSG "Account is temporarily unavailable."
#define PROXY_DEFAULT_TIMEOUT_MSECS (1000*30)
reply_r->destuser = value;
else if (strcmp(key, "pass") == 0)
reply_r->password = value;
- else if (strcmp(key, "proxy_timeout") == 0)
- reply_r->proxy_timeout_msecs = 1000*atoi(value);
- else if (strcmp(key, "proxy_refresh") == 0)
- reply_r->proxy_refresh_secs = atoi(value);
- else if (strcmp(key, "proxy_mech") == 0)
+ else if (strcmp(key, "proxy_timeout") == 0) {
+ if (str_to_uint(value, &reply_r->proxy_timeout_msecs) < 0) {
+ i_error("BUG: Auth service returned invalid "
+ "proxy_timeout value: %s", value);
+ }
+ reply_r->proxy_timeout_msecs *= 1000;
+ } else if (strcmp(key, "proxy_refresh") == 0) {
+ if (str_to_uint(value, &reply_r->proxy_refresh_secs) < 0) {
+ i_error("BUG: Auth service returned invalid "
+ "proxy_refresh value: %s", value);
+ }
+ } else if (strcmp(key, "proxy_mech") == 0)
reply_r->proxy_mech = value;
else if (strcmp(key, "proxy_nopipelining") == 0)
reply_r->proxy_nopipelining = TRUE;
if (buf[ret-1] == '\n')
ret--;
buf[ret] = '\0';
- *pid_r = atoi(buf);
-
- found = !(*pid_r == getpid() ||
- (kill(*pid_r, 0) < 0 && errno == ESRCH));
+ if (str_to_pid(buf, pid_r) < 0) {
+ i_error("PID file contains invalid PID value");
+ found = FALSE;
+ } else {
+ found = !(*pid_r == getpid() ||
+ (kill(*pid_r, 0) < 0 && errno == ESRCH));
+ }
}
i_close_fd(&fd);
return found;
script_verify_version(*args); args++;
if (*args != NULL) {
if (strncmp(*args, "alarm=", 6) == 0) {
- alarm(atoi(*args + 6));
+ unsigned int seconds;
+ if (str_to_uint(*args + 6, &seconds) < 0)
+ i_fatal("invalid alarm option");
+ alarm(seconds);
args++;
}
if (strcmp(*args, "noreply") == 0) {