From 58c9982e75c1b23b9c3ff9aad8295035866a67f0 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 10 Apr 2023 14:02:16 +0200 Subject: Win32: Fix fstree CLI mtime range check On Windows, long is a 32 bit integer, so we cannot check if the long value is greater than UINT32_MAX. Instead, check if strtol sets errno. Signed-off-by: David Oberhollenzer --- lib/common/src/fstree_cli.c | 8 +++++++- lib/common/test/fstree_cli.c | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/common/src/fstree_cli.c b/lib/common/src/fstree_cli.c index 179a1f5..a1a41c3 100644 --- a/lib/common/src/fstree_cli.c +++ b/lib/common/src/fstree_cli.c @@ -11,6 +11,7 @@ #include #include #include +#include enum { DEF_UID = 0, @@ -75,11 +76,16 @@ int parse_fstree_defaults(fstree_defaults_t *sb, char *subopts) sb->mode = S_IFDIR | (sqfs_u16)lval; break; case DEF_MTIME: + errno = 0; lval = strtol(value, NULL, 0); if (lval < 0) goto fail_uv; - if (lval > (long)UINT32_MAX) + if (sizeof(long) > sizeof(sqfs_u32)) { + if (lval > (long)UINT32_MAX) + goto fail_ov; + } else if (errno != 0) { goto fail_ov; + } sb->mtime = lval; break; default: diff --git a/lib/common/test/fstree_cli.c b/lib/common/test/fstree_cli.c index a582adb..fc63a98 100644 --- a/lib/common/test/fstree_cli.c +++ b/lib/common/test/fstree_cli.c @@ -43,5 +43,15 @@ int main(int argc, char **argv) TEST_ASSERT(parse_fstree_defaults(&fs, str) != 0); free(str); + str = strdup("mtime=-12"); + TEST_NOT_NULL(str); + TEST_ASSERT(parse_fstree_defaults(&fs, str) != 0); + free(str); + + str = strdup("mtime=4294967296"); + TEST_NOT_NULL(str); + TEST_ASSERT(parse_fstree_defaults(&fs, str) != 0); + free(str); + return EXIT_SUCCESS; } -- cgit v1.2.3