From a5d3c5ba686cfeb21d1d679f7ca2dc8f09748b75 Mon Sep 17 00:00:00 2001 From: Jin Qian Date: Fri, 6 Jan 2017 16:30:34 -0800 Subject: [PATCH] AOSP: libext2fs: fix sparse param parsing on mac build 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 --- lib/ext2fs/sparse_io.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ext2fs/sparse_io.c b/lib/ext2fs/sparse_io.c index b6168cb..a307859 100644 --- a/lib/ext2fs/sparse_io.c +++ b/lib/ext2fs/sparse_io.c @@ -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); } -- 1.8.3.1