Skip to content

Commit

Permalink
Use sudo_strtonum() instead of strtoull().
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
millert committed Aug 13, 2024
1 parent cba5d2a commit 827fa8b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions plugins/sudoers/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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=")) {
Expand Down

0 comments on commit 827fa8b

Please sign in to comment.