From: "Darrick J. Wong" <djwong@kernel.org>
To: Andrey Albershteyn <aalbersh@redhat.com>
Cc: cem@kernel.org, linux-xfs@vger.kernel.org
Subject: Re: [PATCH v2 4/4] xfs_fsr: convert fsrallfs to use time_t instead of int
Date: Tue, 16 Apr 2024 13:59:18 -0700 [thread overview]
Message-ID: <20240416205918.GF11948@frogsfrogsfrogs> (raw)
In-Reply-To: <20240416202402.724492-5-aalbersh@redhat.com>
On Tue, Apr 16, 2024 at 10:24:02PM +0200, Andrey Albershteyn wrote:
> Convert howlong argument to a time_t as it's truncated to int, but in
> practice this is not an issue as duration will never be this big.
>
> Add check for howlong to fit into int (printf can use int format
> specifier). Even longer interval doesn't make much sense.
>
> Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
> ---
> fsr/xfs_fsr.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
> index 3077d8f4ef46..4e29a8a2c548 100644
> --- a/fsr/xfs_fsr.c
> +++ b/fsr/xfs_fsr.c
> @@ -72,7 +72,7 @@ static int packfile(char *fname, char *tname, int fd,
> static void fsrdir(char *dirname);
> static int fsrfs(char *mntdir, xfs_ino_t ino, int targetrange);
> static void initallfs(char *mtab);
> -static void fsrallfs(char *mtab, int howlong, char *leftofffile);
> +static void fsrallfs(char *mtab, time_t howlong, char *leftofffile);
> static void fsrall_cleanup(int timeout);
> static int getnextents(int);
> int xfsrtextsize(int fd);
> @@ -165,6 +165,10 @@ main(int argc, char **argv)
> break;
> case 't':
> howlong = atoi(optarg);
> + if (howlong > INT_MAX) {
> + fprintf(stderr, _("%s: too long\n"), progname);
Don't just say that it's too long; tell the user what the maximum is.
Also perhaps print the argument that was wrong so that the user knows
exactly what they got wrong:
fprintf(stderr, _("%s: the maximum runtime is %d seconds.\n"),
optarg, INT_MAX);
$ xfs_fsr -t 123456789123456789
123456789123456789: the maximum runtime is 2147483647 seconds.
--D
> + exit(1);
> + }
> break;
> case 'f':
> leftofffile = optarg;
> @@ -387,7 +391,7 @@ initallfs(char *mtab)
> }
>
> static void
> -fsrallfs(char *mtab, int howlong, char *leftofffile)
> +fsrallfs(char *mtab, time_t howlong, char *leftofffile)
> {
> int fd;
> int error;
> --
> 2.42.0
>
>
next prev parent reply other threads:[~2024-04-16 20:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-16 20:23 [PATCH v2 0/4] xfsprogs random fixes found by Coverity scan Andrey Albershteyn
2024-04-16 20:23 ` [PATCH v2 1/4] xfs_db: fix leak in flist_find_ftyp() Andrey Albershteyn
2024-04-16 20:24 ` [PATCH v2 2/4] xfs_repair: make duration take time_t Andrey Albershteyn
2024-04-16 21:00 ` Darrick J. Wong
2024-04-16 20:24 ` [PATCH v2 3/4] xfs_scrub: don't call phase_end if phase_rusage was not initialized Andrey Albershteyn
2024-04-16 20:24 ` [PATCH v2 4/4] xfs_fsr: convert fsrallfs to use time_t instead of int Andrey Albershteyn
2024-04-16 20:59 ` Darrick J. Wong [this message]
2024-04-16 20:51 ` [PATCH v2 0/4] xfsprogs random fixes found by Coverity scan Bill O'Donnell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240416205918.GF11948@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=aalbersh@redhat.com \
--cc=cem@kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox