From a013c086769bbb33e112c3693b0be3ee4560e6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=82=96=E5=9C=A8?= Date: Tue, 16 Jul 2024 11:35:07 +0800 Subject: [PATCH] convert fsrallfs to use time_t instead of int and replace atoi with strtol --- ...fsrallfs-to-use-time_t-instead-of-in.patch | 56 ++++++++++++++++ 0009-xfs_fsr-replace-atoi-with-strtol.patch | 64 +++++++++++++++++++ xfsprogs.spec | 7 +- 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 0008-xfs_fsr-convert-fsrallfs-to-use-time_t-instead-of-in.patch create mode 100644 0009-xfs_fsr-replace-atoi-with-strtol.patch diff --git a/0008-xfs_fsr-convert-fsrallfs-to-use-time_t-instead-of-in.patch b/0008-xfs_fsr-convert-fsrallfs-to-use-time_t-instead-of-in.patch new file mode 100644 index 0000000..1cc4d6e --- /dev/null +++ b/0008-xfs_fsr-convert-fsrallfs-to-use-time_t-instead-of-in.patch @@ -0,0 +1,56 @@ +From 9c6e9d8de2d236f630efdd6fddb6277e8664989b Mon Sep 17 00:00:00 2001 +From: Andrey Albershteyn +Date: Tue, 23 Apr 2024 14:36:17 +0200 +Subject: [PATCH 1/7] xfs_fsr: convert fsrallfs to use time_t instead of int + +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. + +Reviewed-by: Darrick J. Wong +Reviewed-by: Christoph Hellwig +Signed-off-by: Andrey Albershteyn +--- + fsr/xfs_fsr.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c +index 3077d8f4..02d61ef9 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,12 @@ main(int argc, char **argv) + break; + case 't': + howlong = atoi(optarg); ++ if (howlong > INT_MAX) { ++ fprintf(stderr, ++ _("%s: the maximum runtime is %d seconds.\n"), ++ optarg, INT_MAX); ++ exit(1); ++ } + break; + case 'f': + leftofffile = optarg; +@@ -387,7 +393,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.33.0 + diff --git a/0009-xfs_fsr-replace-atoi-with-strtol.patch b/0009-xfs_fsr-replace-atoi-with-strtol.patch new file mode 100644 index 0000000..fc104a7 --- /dev/null +++ b/0009-xfs_fsr-replace-atoi-with-strtol.patch @@ -0,0 +1,64 @@ +From 652f8066b7ca7dc1e08c2c40cdd9ba593a9de568 Mon Sep 17 00:00:00 2001 +From: Andrey Albershteyn +Date: Wed, 17 Apr 2024 18:19:29 +0200 +Subject: [PATCH 2/7] xfs_fsr: replace atoi() with strtol() + +Replace atoi() which silently fails with strtol() and report the +error. + +Signed-off-by: Andrey Albershteyn +Reviewed-by: Darrick J. Wong +Reviewed-by: Christoph Hellwig +--- + fsr/xfs_fsr.c | 26 +++++++++++++++++++++++--- + 1 file changed, 23 insertions(+), 3 deletions(-) + +diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c +index 02d61ef9..fdd37756 100644 +--- a/fsr/xfs_fsr.c ++++ b/fsr/xfs_fsr.c +@@ -164,7 +164,13 @@ main(int argc, char **argv) + usage(1); + break; + case 't': +- howlong = atoi(optarg); ++ errno = 0; ++ howlong = strtol(optarg, NULL, 10); ++ if (errno) { ++ fprintf(stderr, _("%s: invalid runtime: %s\n"), ++ optarg, strerror(errno)); ++ exit(1); ++ } + if (howlong > INT_MAX) { + fprintf(stderr, + _("%s: the maximum runtime is %d seconds.\n"), +@@ -179,10 +185,24 @@ main(int argc, char **argv) + mtab = optarg; + break; + case 'b': +- argv_blksz_dio = atoi(optarg); ++ errno = 0; ++ argv_blksz_dio = strtol(optarg, NULL, 10); ++ if (errno) { ++ fprintf(stderr, ++ _("%s: invalid block size: %s\n"), ++ optarg, strerror(errno)); ++ exit(1); ++ } + break; + case 'p': +- npasses = atoi(optarg); ++ errno = 0; ++ npasses = strtol(optarg, NULL, 10); ++ if (errno) { ++ fprintf(stderr, ++ _("%s: invalid number of passes: %s\n"), ++ optarg, strerror(errno)); ++ exit(1); ++ } + break; + case 'C': + /* Testing opt: coerses frag count in result */ +-- +2.33.0 + diff --git a/xfsprogs.spec b/xfsprogs.spec index abb028f..dea435a 100644 --- a/xfsprogs.spec +++ b/xfsprogs.spec @@ -1,6 +1,6 @@ Name: xfsprogs Version: 6.6.0 -Release: 7 +Release: 8 Summary: Administration and debugging tools for the XFS file system License: GPL+ and LGPLv2+ URL: https://xfs.wiki.kernel.org @@ -26,6 +26,8 @@ Patch4: 0004-xfs_db-fix-leak-in-flist_find_ftyp.patch Patch5: 0005-xfs_db-add-helper-for-flist_find_type-for-clearer-fi.patch Patch6: 0006-xfs_io-fix-mread-with-length-1-mod-page-size.patch Patch7: 0007-xfs_scrub-don-t-call-phase_end-if-phase_rusage-was-n.patch +Patch8: 0008-xfs_fsr-convert-fsrallfs-to-use-time_t-instead-of-in.patch +Patch9: 0009-xfs_fsr-replace-atoi-with-strtol.patch %description xfsprogs are the userspace utilities that manage XFS filesystems. @@ -109,6 +111,9 @@ rm -rf %{buildroot}%{_datadir}/doc/xfsprogs/ %changelog +* Tue Jul 16 2024 xiaozai - 6.6.0-8 +- sync patches: 0008-xfs_fsr-convert-fsrallfs-to-use-time_t-instead-of-in.patch, 0009-xfs_fsr-replace-atoi-with-strtol.patch + * Sat Jul 6 2024 liuh - 6.6.0-7 - xfs_scrub: don't call phase_end if phase_rusage was not initialized -- Gitee