comparison 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
comparison
equal deleted inserted replaced
491:9dbc0c443497 492:b956d6151600
502 snprintf(argv[0], len, "-%s", baseshell); 502 snprintf(argv[0], len, "-%s", baseshell);
503 } 503 }
504 504
505 if (cmd != NULL) { 505 if (cmd != NULL) {
506 argv[1] = "-c"; 506 argv[1] = "-c";
507 argv[2] = cmd; 507 argv[2] = (char*)cmd;
508 argv[3] = NULL; 508 argv[3] = NULL;
509 } else { 509 } else {
510 /* construct a shell of the form "-bash" etc */ 510 /* construct a shell of the form "-bash" etc */
511 argv[1] = NULL; 511 argv[1] = NULL;
512 } 512 }
833 void disallow_core() { 833 void disallow_core() {
834 struct rlimit lim; 834 struct rlimit lim;
835 lim.rlim_cur = lim.rlim_max = 0; 835 lim.rlim_cur = lim.rlim_max = 0;
836 setrlimit(RLIMIT_CORE, &lim); 836 setrlimit(RLIMIT_CORE, &lim);
837 } 837 }
838
839 /* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE, with the result in *val */
840 int m_str_to_uint(const char* str, unsigned int *val) {
841 errno = 0;
842 *val = strtoul(str, NULL, 10);
843 /* The c99 spec doesn't actually seem to define EINVAL, but most platforms
844 * I've looked at mention it in their manpage */
845 if ((*val == 0 && errno == EINVAL)
846 || (*val == ULONG_MAX && errno == ERANGE)) {
847 return DROPBEAR_FAILURE;
848 } else {
849 return DROPBEAR_SUCCESS;
850 }
851 }