Skip to content

Commit 827fa8b

Browse files
committed
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.
1 parent cba5d2a commit 827fa8b

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

plugins/sudoers/policy.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,18 +466,19 @@ sudoers_policy_deserialize_info(struct sudoers_context *ctx, void *v,
466466
continue;
467467
}
468468
if (MATCHES(*cur, "ttydev=")) {
469-
unsigned long long ullval;
470-
char *ep;
469+
long long llval;
471470

471+
/*
472+
* dev_t is unsigned but sudo_strtonum() deals with signed values.
473+
* This is not a problem in practice since we allow the full range.
474+
*/
472475
p = *cur + sizeof("ttydev=") - 1;
473-
errno = 0;
474-
ullval = strtoull(p, &ep, 10);
475-
if ((*p == '\0' || *ep != '\0') ||
476-
(errno == ERANGE && ullval == ULLONG_MAX)) {
476+
llval = sudo_strtonum(p, LLONG_MIN, LLONG_MAX, &errstr);
477+
if (errstr != NULL) {
477478
INVALID("ttydev=");
478479
goto bad;
479480
}
480-
ctx->user.ttydev = (dev_t)ullval;
481+
ctx->user.ttydev = (dev_t)llval;
481482
continue;
482483
}
483484
if (MATCHES(*cur, "host=")) {

0 commit comments

Comments
 (0)