diff dbutil.c @ 492:b956d6151600

Replace calls to strtoul() with a helper m_str_to_uint()
author Matt Johnston <matt@ucc.asn.au>
date Mon, 22 Sep 2008 14:13:44 +0000
parents bd2634b03b12
children d588e3ea557a
line wrap: on
line diff
--- 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;
+	}
+}