erofs-utils: lib: fix s3erofs_prepare_url()
PATCH 1/2 erofs-utils: lib: fix s3erofs_prepare_url()
mkfs.erofs failed to generate image from Huawei OBS with the following command:
$ mkfs.erofs --s3=<endpoint>,urlstyle=vhost,sig=2 s3.erofs test-bucket
because it mistakenly generated a url with repeated '/':
"https://test-bucket.<endpoint>//<keyname>"
Fix the corresponding logic now.
Reported-by Yifan Zhao <[email protected]>
Signed-off-by Gao Xiang <[email protected]>
--- lib/remotes/s3.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
lib/remotes/s3.c +5 -2
@@ -47,6 +47,7 @@ static int s3erofs_prepare_url(struct s3erofs_curl_request *req, {static const char https[] ="https://" ;const char *schema, *host; +/* an additional slash is added, which wasn't specified by user inputs */ bool slash = false;char *url = req->url;int pos, i;
@@ -82,8 +83,10 @@ static int s3erofs_prepare_url(struct s3erofs_curl_request *req, } }if (key) { - slash |= url[pos -1 ] !='/' ; - pos -= !slash; +if (url[pos -1 ] =='/' ) + --pos; +else + slash = true; pos +=snprintf (url + pos,S3EROFS_URL_LEN - pos,"/%s" , key); }
Signature · 1 line
2.43.5
PATCH 2/2 erofs-utils: lib: add test for s3erofs_prepare_url()
From: Yifan Zhao <[email protected]>
To avoid future regressions.
Signed-off-by Yifan Zhao <[email protected]>
Signed-off-by Gao Xiang <[email protected]>
--- dump/Makefile.am | 4 +- fsck/Makefile.am | 8 +- fuse/Makefile.am | 4 +- lib/Makefile.am | 13 +++- lib/remotes/s3.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++ mkfs/Makefile.am | 5 +- mount/Makefile.am | 4 +- 7 files changed, 211 insertions(+), 20 deletions(-)
dump/Makefile.am +1 -3
@@ -6,6 +6,4 @@ bin_PROGRAMS = dump.erofs AM_CPPFLAGS = ${libuuid_CFLAGS} dump_erofs_SOURCES = main.c dump_erofs_CFLAGS = -Wall -I$(top_srcdir)/include -dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ - ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \ - ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS} +dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la
fsck/Makefile.am +2 -6
@@ -6,16 +6,12 @@ bin_PROGRAMS = fsck.erofs AM_CPPFLAGS = ${libuuid_CFLAGS} fsck_erofs_SOURCES = main.c fsck_erofs_CFLAGS = -Wall -I$(top_srcdir)/include -fsck_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ - ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \ - ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS} +fsck_erofs_LDADD = $(top_builddir)/lib/liberofs.la if ENABLE_FUZZING noinst_PROGRAMS = fuzz_erofsfsck fuzz_erofsfsck_SOURCES = main.c fuzz_erofsfsck_CFLAGS = -Wall -I$(top_srcdir)/include -DFUZZING fuzz_erofsfsck_LDFLAGS = -fsanitize=address,fuzzer -fuzz_erofsfsck_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ - ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \ - ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS} +fuzz_erofsfsck_LDADD = $(top_builddir)/lib/liberofs.la endif
fuse/Makefile.am +1 -3
@@ -6,9 +6,7 @@ bin_PROGRAMS = erofsfuse erofsfuse_SOURCES = main.c erofsfuse_CFLAGS = -Wall -I$(top_srcdir)/include erofsfuse_CFLAGS += ${libfuse2_CFLAGS} ${libfuse3_CFLAGS} ${libselinux_CFLAGS} -erofsfuse_LDADD = $(top_builddir)/lib/liberofs.la ${libfuse2_LIBS} ${libfuse3_LIBS} ${liblz4_LIBS} \ - ${libselinux_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} ${libzstd_LIBS} \ - ${libqpl_LIBS} ${libxxhash_LIBS} ${openssl_LIBS} +erofsfuse_LDADD = $(top_builddir)/lib/liberofs.la ${libfuse2_LIBS} ${libfuse3_LIBS} if ENABLE_STATIC_FUSE lib_LTLIBRARIES = liberofsfuse.la
lib/Makefile.am +12 -1
@@ -44,7 +44,9 @@ liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \ vmdk.c metabox.c global.c importer.c base64.c liberofs_la_CFLAGS = -Wall ${libuuid_CFLAGS} -I$(top_srcdir)/include -liberofs_la_LDFLAGS = +liberofs_la_LDFLAGS = ${libselinux_LIBS} ${libuuid_LIBS} ${liblz4_LIBS} \ + ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} ${libzstd_LIBS} \ + ${libqpl_LIBS} ${libxxhash_LIBS} if ENABLE_LZ4 liberofs_la_CFLAGS += ${liblz4_CFLAGS} liberofs_la_SOURCES += compressor_lz4.c
@@ -74,6 +76,7 @@ endif liberofs_la_CFLAGS += ${libcurl_CFLAGS} ${openssl_CFLAGS} ${libxml2_CFLAGS} if ENABLE_S3 liberofs_la_SOURCES += remotes/s3.c +liberofs_la_LDFLAGS += ${libxml2_LIBS} ${openssl_LIBS} endif if ENABLE_EROFS_MT liberofs_la_LDFLAGS += -lpthread
@@ -81,9 +84,17 @@ liberofs_la_SOURCES += workqueue.c endif if OS_LINUX liberofs_la_CFLAGS += ${libnl3_CFLAGS} +liberofs_la_LDFLAGS += ${libnl3_LIBS} liberofs_la_SOURCES += backends/nbd.c endif liberofs_la_SOURCES += remotes/oci.c liberofs_la_CFLAGS += ${libcurl_CFLAGS} ${json_c_CFLAGS} liberofs_la_LDFLAGS += ${libcurl_LIBS} ${json_c_LIBS} liberofs_la_SOURCES += gzran.c + +if ENABLE_S3 +noinst_PROGRAMS = s3erofs_test +s3erofs_test_SOURCES = remotes/s3.c +s3erofs_test_CFLAGS = -Wall -I$(top_srcdir)/include ${libxml2_CFLAGS} ${openssl_CFLAGS} -DTEST +s3erofs_test_LDADD = liberofs.la +endif
lib/remotes/s3.c +193 -0
196 lines not on this page · raw message
mkfs/Makefile.am +1 -4
@@ -5,7 +5,4 @@ bin_PROGRAMS = mkfs.erofs AM_CPPFLAGS = ${libselinux_CFLAGS} mkfs_erofs_SOURCES = main.c mkfs_erofs_CFLAGS = -Wall -I$(top_srcdir)/include -mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ - ${libuuid_LIBS} ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} \ - ${libdeflate_LIBS} ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} \ - ${libcurl_LIBS} ${openssl_LIBS} ${libxml2_LIBS} +mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la
mount/Makefile.am +1 -3
@@ -7,7 +7,5 @@ sbin_PROGRAMS = mount.erofs AM_CPPFLAGS = ${libuuid_CFLAGS} mount_erofs_SOURCES = main.c mount_erofs_CFLAGS = -Wall -I$(top_srcdir)/include -mount_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ - ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \ - ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} ${libnl3_LIBS} ${openssl_LIBS} +mount_erofs_LDADD = $(top_builddir)/lib/liberofs.la endif
Signature · 1 line
2.43.5