diff options
Diffstat (limited to 'lib')
-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; } |