Mercurial > dropbear
comparison dbutil.c @ 1833:870f6e386a0b
Partial strings from strtoul should return error
author | Matt Johnston <matt@codeconstruct.com.au> |
---|---|
date | Tue, 12 Oct 2021 23:31:09 +0800 |
parents | a339b1c4b9f2 |
children | 90ac15aeac43 |
comparison
equal
deleted
inserted
replaced
1832:a974a80f5f44 | 1833:870f6e386a0b |
---|---|
581 } | 581 } |
582 | 582 |
583 /* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE, with the result in *val */ | 583 /* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE, with the result in *val */ |
584 int m_str_to_uint(const char* str, unsigned int *val) { | 584 int m_str_to_uint(const char* str, unsigned int *val) { |
585 unsigned long l; | 585 unsigned long l; |
586 errno = 0; | 586 char *endp; |
587 l = strtoul(str, NULL, 10); | 587 |
588 l = strtoul(str, &endp, 10); | |
589 | |
590 if (endp == str || *endp != '\0') { | |
591 // parse error | |
592 return DROPBEAR_FAILURE; | |
593 } | |
594 | |
588 /* The c99 spec doesn't actually seem to define EINVAL, but most platforms | 595 /* The c99 spec doesn't actually seem to define EINVAL, but most platforms |
589 * I've looked at mention it in their manpage */ | 596 * I've looked at mention it in their manpage */ |
590 if ((l == 0 && errno == EINVAL) | 597 if ((l == 0 && errno == EINVAL) |
591 || (l == ULONG_MAX && errno == ERANGE) | 598 || (l == ULONG_MAX && errno == ERANGE) |
592 || (l > UINT_MAX)) { | 599 || (l > UINT_MAX)) { |