Whamcloud - gitweb
AOSP: libext2fs: fix sparse param parsing on mac build
authorJin Qian <jinqian@google.com>
Sat, 7 Jan 2017 00:30:34 +0000 (16:30 -0800)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 24 May 2017 02:58:04 +0000 (22:58 -0400)
Flag m is not supported on macos sscanf. Fall back to manually
allocate the string.

Use strict format to skip ":" between params.

Change-Id: Ic4f3747708423d0504ea40fb5cb116068f4a7ab8
From AOSP commit: 901472babf4ea5e4d2d44aa16834b1c899c8937f

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/sparse_io.c

index b6168cb..a307859 100644 (file)
@@ -196,16 +196,21 @@ static errcode_t read_sparse_argv(const char *name, bool is_fd,
 {
        int ret;
        sparse_params->fd = -1;
-       sparse_params->file = NULL;
        sparse_params->block_size = 0;
        sparse_params->blocks_count = 0;
 
+       sparse_params->file = malloc(strlen(name) + 1);
+       if (!sparse_params->file) {
+               fprintf(stderr, "failed to alloc %zu\n", strlen(name) + 1);
+               return EXT2_ET_NO_MEMORY;
+       }
+
        if (is_fd) {
                ret = sscanf(name, "%d:%llu:%u", &sparse_params->fd,
                             (unsigned long long *)&sparse_params->blocks_count,
                             &sparse_params->block_size);
        } else {
-               ret = sscanf(name, "%m[^:]:%llu%*[:]%u", &sparse_params->file,
+               ret = sscanf(name, "%[^:]%*[:]%llu%*[:]%u", sparse_params->file,
                             (unsigned long long *)&sparse_params->blocks_count,
                             &sparse_params->block_size);
        }