Skip to content

Commit

Permalink
inject.f2fs: fix max boundary check
Browse files Browse the repository at this point in the history
Signed-off-by: Jaegeuk Kim <[email protected]>
  • Loading branch information
Jaegeuk Kim committed Jul 25, 2024
1 parent 8916de7 commit 334fb77
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions fsck/inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt)

while ((o = getopt_long(argc, argv, option_string,
long_opt, NULL)) != EOF) {
long nid, blk;

switch (o) {
case 1:
c.dry_run = 1;
Expand Down Expand Up @@ -265,10 +267,10 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt)
MSG(0, "Info: inject nat pack %s\n", pack[opt->nat]);
break;
case 9:
opt->nid = strtol(optarg, &endptr, 0);
if (opt->nid == LONG_MAX || opt->nid == LONG_MIN ||
*endptr != '\0')
nid = strtol(optarg, &endptr, 0);
if (nid >= UINT_MAX || *endptr != '\0')
return -ERANGE;
opt->nid = nid;
MSG(0, "Info: inject nid %u : 0x%x\n", opt->nid, opt->nid);
break;
case 10:
Expand All @@ -280,10 +282,10 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt)
MSG(0, "Info: inject sit pack %s\n", pack[opt->sit]);
break;
case 11:
opt->blk = strtol(optarg, &endptr, 0);
if (opt->blk == LONG_MAX || opt->blk == LONG_MIN ||
*endptr != '\0')
blk = strtol(optarg, &endptr, 0);
if (blk >= UINT_MAX || *endptr != '\0')
return -ERANGE;
opt->blk = blk;
MSG(0, "Info: inject blkaddr %u : 0x%x\n", opt->blk, opt->blk);
break;
case 12:
Expand Down

0 comments on commit 334fb77

Please sign in to comment.