diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-04-10 14:02:16 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-04-12 20:41:34 +0200 |
commit | 58c9982e75c1b23b9c3ff9aad8295035866a67f0 (patch) | |
tree | 509e2313ac5204d54d29863c7fa4d9c9253684a7 /lib/common | |
parent | aafae427048afa25e71d31deeae79b7b7f767891 (diff) |
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/common')
-rw-r--r-- | lib/common/src/fstree_cli.c | 8 | ||||
-rw-r--r-- | lib/common/test/fstree_cli.c | 10 |
2 files changed, 17 insertions, 1 deletions
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 <string.h> #include <stdlib.h> #include <stdio.h> +#include <errno.h> 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; } |