Skip to content

Commit

Permalink
Do proper error handling with strtonum
Browse files Browse the repository at this point in the history
Checking for an error string is the proper step.
Also, cast to u_int, not int.
  • Loading branch information
RSilicon committed Jul 5, 2023
1 parent a95fc5e commit 59ac3b5
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 = (u_int)strtonum(optarg, 1, UINT_MAX, &errstr);
if (errstr) {
usage();
ret = 1;
goto done;
}
break;
case 'M':
maxsign = (int)strtonum(optarg, 1, UINT_MAX, NULL);
if (maxsign == 0) {
maxsign = (u_int)strtonum(optarg, 1, UINT_MAX, &errstr);
if (errstr) {
usage();
ret = 1;
goto done;
Expand Down

0 comments on commit 59ac3b5

Please sign in to comment.