From 334fb77da2acac03fcfb327a31fdcf250d97bf4f Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Thu, 25 Jul 2024 18:02:46 +0000 Subject: [PATCH] inject.f2fs: fix max boundary check Signed-off-by: Jaegeuk Kim --- fsck/inject.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fsck/inject.c b/fsck/inject.c index 2a21dae2..fab0e964 100644 --- a/fsck/inject.c +++ b/fsck/inject.c @@ -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; @@ -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: @@ -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: