# HG changeset patch # User Matt Johnston # Date 1222092824 0 # Node ID b956d6151600807c11d0b1dce60ba2e4760c994b # Parent 9dbc0c4434971da157f987f040f2bc0965e0c81c Replace calls to strtoul() with a helper m_str_to_uint() diff -r 9dbc0c443497 -r b956d6151600 cli-runopts.c --- a/cli-runopts.c Mon Sep 22 14:13:14 2008 +0000 +++ b/cli-runopts.c Mon Sep 22 14:13:44 2008 +0000 @@ -355,8 +355,7 @@ } } if (keepalive_arg) { - opts.keepalive_secs = strtoul(keepalive_arg, NULL, 10); - if (opts.keepalive_secs == 0 && errno == EINVAL) { + if (m_str_to_uint(keepalive_arg, &opts.keepalive_secs) == DROPBEAR_FAILURE) { dropbear_exit("Bad keepalive '%s'", keepalive_arg); } } @@ -499,8 +498,7 @@ goto fail; } - cli_opts.netcat_port = strtoul(portstr, NULL, 10); - if (errno != 0) { + if (m_str_to_uint(portstr, &cli_opts.netcat_port) == DROPBEAR_FAILURE) { TRACE(("bad netcat port")) goto fail; } @@ -571,15 +569,13 @@ /* Now we check the ports - note that the port ints are unsigned, * the check later only checks for >= MAX_PORT */ - newfwd->listenport = strtoul(listenport, NULL, 10); - if (errno != 0) { - TRACE(("bad listenport strtol")) + if (m_str_to_uint(listenport, &newfwd->listenport) == DROPBEAR_FAILURE) { + TRACE(("bad listenport strtoul")) goto fail; } - newfwd->connectport = strtoul(connectport, NULL, 10); - if (errno != 0) { - TRACE(("bad connectport strtol")) + if (m_str_to_uint(connectport, &newfwd->connectport) == DROPBEAR_FAILURE) { + TRACE(("bad connectport strtoul")) goto fail; } diff -r 9dbc0c443497 -r b956d6151600 dbutil.c --- a/dbutil.c Mon Sep 22 14:13:14 2008 +0000 +++ b/dbutil.c Mon Sep 22 14:13:44 2008 +0000 @@ -504,7 +504,7 @@ if (cmd != NULL) { argv[1] = "-c"; - argv[2] = cmd; + argv[2] = (char*)cmd; argv[3] = NULL; } else { /* construct a shell of the form "-bash" etc */ @@ -835,3 +835,17 @@ lim.rlim_cur = lim.rlim_max = 0; setrlimit(RLIMIT_CORE, &lim); } + +/* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE, with the result in *val */ +int m_str_to_uint(const char* str, unsigned int *val) { + errno = 0; + *val = strtoul(str, NULL, 10); + /* The c99 spec doesn't actually seem to define EINVAL, but most platforms + * I've looked at mention it in their manpage */ + if ((*val == 0 && errno == EINVAL) + || (*val == ULONG_MAX && errno == ERANGE)) { + return DROPBEAR_FAILURE; + } else { + return DROPBEAR_SUCCESS; + } +} diff -r 9dbc0c443497 -r b956d6151600 dbutil.h --- a/dbutil.h Mon Sep 22 14:13:14 2008 +0000 +++ b/dbutil.h Mon Sep 22 14:13:44 2008 +0000 @@ -67,6 +67,7 @@ void m_burn(void* data, unsigned int len); void setnonblocking(int fd); void disallow_core(); +int m_str_to_uint(const char* str, unsigned int *val); /* Used to force mp_ints to be initialised */ #define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL} diff -r 9dbc0c443497 -r b956d6151600 runopts.h --- a/runopts.h Mon Sep 22 14:13:14 2008 +0000 +++ b/runopts.h Mon Sep 22 14:13:44 2008 +0000 @@ -37,7 +37,7 @@ int listen_fwd_all; #endif unsigned int recv_window; - time_t keepalive_secs; + unsigned int keepalive_secs; } runopts; diff -r 9dbc0c443497 -r b956d6151600 svr-runopts.c --- a/svr-runopts.c Mon Sep 22 14:13:14 2008 +0000 +++ b/svr-runopts.c Mon Sep 22 14:13:44 2008 +0000 @@ -284,16 +284,13 @@ if (recv_window_arg) { opts.recv_window = atol(recv_window_arg); - if (opts.recv_window == 0 || opts.recv_window > MAX_RECV_WINDOW) - { + if (opts.recv_window == 0 || opts.recv_window > MAX_RECV_WINDOW) { dropbear_exit("Bad recv window '%s'", recv_window_arg); } } if (keepalive_arg) { - opts.keepalive_secs = strtoul(keepalive_arg, NULL, 10); - if (opts.keepalive_secs == 0 && errno == EINVAL) - { + if (m_str_to_uint(keepalive_arg, &opts.keepalive_secs) == DROPBEAR_FAILURE) { dropbear_exit("Bad keepalive '%s'", keepalive_arg); } }