2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-29 13:28:10 +00:00

Use sudo_strtonum() instead of strtoull().

Fixes building on systems that lack strtoull().  While dev_t is
unsigned on most systems, we can still use sudo_strtonum() here as
long as we allow the full range of values [LLONG_MIN,LLONG_MAX].
We don't use strtoul() here since some 32-bit systems have 64-bit
dev_t.
This commit is contained in:
Todd C. Miller 2024-08-13 12:43:10 -06:00
parent cba5d2a5c9
commit 827fa8b76d

View File

@ -466,18 +466,19 @@ sudoers_policy_deserialize_info(struct sudoers_context *ctx, void *v,
continue;
}
if (MATCHES(*cur, "ttydev=")) {
unsigned long long ullval;
char *ep;
long long llval;
/*
* dev_t is unsigned but sudo_strtonum() deals with signed values.
* This is not a problem in practice since we allow the full range.
*/
p = *cur + sizeof("ttydev=") - 1;
errno = 0;
ullval = strtoull(p, &ep, 10);
if ((*p == '\0' || *ep != '\0') ||
(errno == ERANGE && ullval == ULLONG_MAX)) {
llval = sudo_strtonum(p, LLONG_MIN, LLONG_MAX, &errstr);
if (errstr != NULL) {
INVALID("ttydev=");
goto bad;
}
ctx->user.ttydev = (dev_t)ullval;
ctx->user.ttydev = (dev_t)llval;
continue;
}
if (MATCHES(*cur, "host=")) {