Skip to content

Commit

Permalink
Ensure strtonum returns a number that is always positive in the range…
Browse files Browse the repository at this point in the history
… of an integer

We should be using INT_MAX, not UINT_MAX, and checking for errors via errstr, as opposed to allowing negative numbers.
  • Loading branch information
AreaZR committed Jul 4, 2023
1 parent 8a6cd08 commit 2fc258a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ssh-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ main(int argc, char **argv)
extern char *optarg;
extern int optind;
int agent_fd;
const char *errstr = NULL;
char *pkcs11provider = NULL, *skprovider = NULL;
char **dest_constraint_strings = NULL, **hostkey_files = NULL;
int r, i, ch, deleting = 0, ret = 0, key_only = 0, do_download = 0;
Expand Down Expand Up @@ -863,16 +864,16 @@ main(int argc, char **argv)
confirm = 1;
break;
case 'm':
minleft = (int)strtonum(optarg, 1, UINT_MAX, NULL);
if (minleft == 0) {
minleft = (int)strtonum(optarg, 1, INT_MAX, &errstr);
if (errstr) {
usage();
ret = 1;
goto done;
}
break;
case 'M':
maxsign = (int)strtonum(optarg, 1, UINT_MAX, NULL);
if (maxsign == 0) {
maxsign = (int)strtonum(optarg, 1, INT_MAX, &errstr);
if (errstr) {
usage();
ret = 1;
goto done;
Expand Down

0 comments on commit 2fc258a

Please sign in to comment.