From 79f7428bf8561f13b8cac37b0b9c455861f82f6b Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 13 Nov 2023 23:56:42 +0100 Subject: bindfs.c|usermap.c: Address warning -Wsign-compare MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For example: > src/bindfs.c: In function ‘getattr_common’: > src/bindfs.c:449:26: error: comparison of integer expressions of different signedness: ‘uid_t’ {aka ‘unsigned int’} and ‘int’ [-Werror=sign-compare] > 449 | if (settings.new_uid != -1) > | ^~ > --- src/bindfs.c | 16 ++++++++-------- src/usermap.c | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/bindfs.c b/src/bindfs.c index b4a1f5a..43d769d 100644 --- a/src/bindfs.c +++ b/src/bindfs.c @@ -446,9 +446,9 @@ static int getattr_common(const char *procpath, struct stat *stbuf) } /* Report user-defined owner/group if specified */ - if (settings.new_uid != -1) + if (settings.new_uid != (uid_t)-1) stbuf->st_uid = settings.new_uid; - if (settings.new_gid != -1) + if (settings.new_gid != (gid_t)-1) stbuf->st_gid = settings.new_gid; /* Mirrored user? */ @@ -549,12 +549,12 @@ static int chown_new_file(const char *path, struct fuse_context *fc, int (*chown } } - if (settings.create_for_uid != -1) + if (settings.create_for_uid != (uid_t)-1) file_owner = settings.create_for_uid; - if (settings.create_for_gid != -1) + if (settings.create_for_gid != (gid_t)-1) file_group = settings.create_for_gid; - if ((file_owner != -1) || (file_group != -1)) { + if ((file_owner != (uid_t)-1) || (file_group != (gid_t)-1)) { if (chown_func(path, file_owner, file_group) == -1) { DPRINTF("Failed to chown new file or directory (%d)", errno); } @@ -1182,7 +1182,7 @@ static int bindfs_chown(const char *path, uid_t uid, gid_t gid) int res; char *real_path; - if (uid != -1) { + if (uid != (uid_t)-1) { switch (settings.chown_policy) { case CHOWN_NORMAL: uid = usermap_get_uid_or_default(settings.usermap_reverse, uid, uid); @@ -1198,7 +1198,7 @@ static int bindfs_chown(const char *path, uid_t uid, gid_t gid) } } - if (gid != -1) { + if (gid != (gid_t)-1) { switch (settings.chgrp_policy) { case CHGRP_NORMAL: gid = usermap_get_gid_or_default(settings.usermap_reverse, gid, gid); @@ -1214,7 +1214,7 @@ static int bindfs_chown(const char *path, uid_t uid, gid_t gid) } } - if (uid != -1 || gid != -1) { + if (uid != (uid_t)-1 || gid != (gid_t)-1) { real_path = process_path(path, true); if (real_path == NULL) return -errno; diff --git a/src/usermap.c b/src/usermap.c index f745e74..eb7b61c 100644 --- a/src/usermap.c +++ b/src/usermap.c @@ -52,7 +52,7 @@ UsermapStatus usermap_add_uid(UserMap *map, uid_t from, uid_t to) map->user_from = (uid_t*)realloc(map->user_from, map->user_capacity * sizeof(uid_t)); map->user_to = (uid_t*)realloc(map->user_to, map->user_capacity * sizeof(uid_t)); } - if (usermap_get_uid_or_default(map, from, -1) != -1) { + if (usermap_get_uid_or_default(map, from, -1) != (uid_t)-1) { return usermap_status_duplicate_key; } i = map->user_size; @@ -77,7 +77,7 @@ UsermapStatus usermap_add_gid(UserMap *map, gid_t from, gid_t to) map->group_from = (gid_t*)realloc(map->group_from, map->group_capacity * sizeof(gid_t)); map->group_to = (gid_t*)realloc(map->group_to, map->group_capacity * sizeof(gid_t)); } - if (usermap_get_gid_or_default(map, from, -1) != -1) { + if (usermap_get_gid_or_default(map, from, -1) != (gid_t)-1) { return usermap_status_duplicate_key; } i = map->group_size; -- cgit v1.2.3 From 3ec75d6ec08ce7be8b40be03cd5285532c285af4 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Tue, 14 Nov 2023 00:54:07 +0100 Subject: bindfs.c: Address warning -Wunused-parameter --- src/bindfs.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/bindfs.c b/src/bindfs.c index 43d769d..5f52395 100644 --- a/src/bindfs.c +++ b/src/bindfs.c @@ -750,6 +750,7 @@ static void *bindfs_init() static void bindfs_destroy(void *private_data) { + (void)private_data; } #ifdef HAVE_FUSE_3 @@ -761,6 +762,9 @@ static int bindfs_getattr(const char *path, struct stat *stbuf) { int res; char *real_path; +#ifdef HAVE_FUSE_3 + (void)fi; +#endif real_path = process_path(path, true); if (real_path == NULL) @@ -827,6 +831,11 @@ static int bindfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) #endif { + (void)offset; + (void)fi; +#ifdef HAVE_FUSE_3 + (void)flags; +#endif char *real_path = process_path(path, true); if (real_path == NULL) { return -errno; @@ -1116,6 +1125,9 @@ static int bindfs_chmod(const char *path, mode_t mode) struct stat st; mode_t diff = 0; char *real_path; +#ifdef HAVE_FUSE_3 + (void)fi; +#endif real_path = process_path(path, true); if (real_path == NULL) @@ -1181,6 +1193,9 @@ static int bindfs_chown(const char *path, uid_t uid, gid_t gid) { int res; char *real_path; +#ifdef HAVE_FUSE_3 + (void)fi; +#endif if (uid != (uid_t)-1) { switch (settings.chown_policy) { @@ -1237,6 +1252,9 @@ static int bindfs_truncate(const char *path, off_t size) { int res; char *real_path; +#ifdef HAVE_FUSE_3 + (void)fi; +#endif real_path = process_path(path, true); if (real_path == NULL) @@ -1273,6 +1291,9 @@ static int bindfs_utimens(const char *path, const struct timespec ts[2]) { int res; char *real_path; +#ifdef HAVE_FUSE_3 + (void)fi; +#endif real_path = process_path(path, true); if (real_path == NULL) @@ -1437,6 +1458,7 @@ static int bindfs_write(const char *path, const char *buf, size_t size, static int bindfs_lock(const char *path, struct fuse_file_info *fi, int cmd, struct flock *lock) { + (void)path; int res = fcntl(fi->fh, cmd, lock); if (res == -1) { return -errno; @@ -1447,6 +1469,7 @@ static int bindfs_lock(const char *path, struct fuse_file_info *fi, int cmd, /* This callback is only installed if lock forwarding is enabled. */ static int bindfs_flock(const char *path, struct fuse_file_info *fi, int op) { + (void)path; int res = flock(fi->fh, op); if (res == -1) { return -errno; @@ -1464,6 +1487,9 @@ static int bindfs_ioctl(const char *path, int cmd, void *arg, void *data) #endif { + (void)path; + (void)arg; + (void)flags; int res = ioctl(fi->fh, cmd, data); if (res == -1) { return -errno; @@ -1891,6 +1917,8 @@ enum OptionKey { static int process_option(void *data, const char *arg, int key, struct fuse_args *outargs) { + (void)data; + (void)outargs; switch ((enum OptionKey)key) { case OPTKEY_HELP: @@ -2322,6 +2350,7 @@ static void setup_signal_handling() static void signal_handler(int sig) { + (void)sig; invalidate_user_cache(); } -- cgit v1.2.3 From 20d8d5eef009d29df457abe8fb40ea615971dedc Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Tue, 14 Nov 2023 00:09:34 +0100 Subject: misc.c: Address warning -Wsign-compare MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The symptom: > src/misc.c: In function ‘path_starts_with’: > src/misc.c:169:45: error: operand of ‘?:’ changes signedness from ‘long int’ to ‘long unsigned int’ due to unsignedness of other operand [-Werror=sign-compare] > 169 | size_t path_part_len = path_slash ? path_slash - path_part : path_len - (path_part - path); > | ^~~~~~~~~~~~~~~~~~~~~~ --- src/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/misc.c b/src/misc.c index 122497d..b937075 100644 --- a/src/misc.c +++ b/src/misc.c @@ -166,7 +166,7 @@ bool path_starts_with(const char *path, const char* prefix, size_t prefix_len) const char* path_part = path + (prefix_part - prefix); const char* path_slash = strchr(path_part, '/'); - size_t path_part_len = path_slash ? path_slash - path_part : path_len - (path_part - path); + size_t path_part_len = path_slash ? (size_t)(path_slash - path_part) : path_len - (path_part - path); return prefix_part_len == path_part_len; } -- cgit v1.2.3 From 09cc3d484d4c31578bc786e984bd90c9181acabb Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Tue, 14 Nov 2023 00:13:20 +0100 Subject: misc.c: Fix overflow detection zombie in function grow_memory_block MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Started out with this warning: > src/misc.c: In function ‘grow_memory_block’: > src/misc.c:333:25: error: comparison of unsigned expression in ‘< 0’ is always false [-Werror=type-limits] > 333 | if (new_cap < 0) { // Overflow > | ^ --- src/misc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/misc.c b/src/misc.c index b937075..fdebff9 100644 --- a/src/misc.c +++ b/src/misc.c @@ -19,6 +19,7 @@ #include "misc.h" #include +#include #include #include #include @@ -328,12 +329,12 @@ void grow_memory_block(struct memory_block *a, size_t amount) if (new_cap == 0) { new_cap = 8; } else { + if (new_cap > SIZE_MAX / 2) { + fprintf(stderr, "Memory block too large."); + abort(); + } new_cap *= 2; } - if (new_cap < 0) { // Overflow - fprintf(stderr, "Memory block too large."); - abort(); - } } a->ptr = (char *)realloc(a->ptr, new_cap); a->capacity = new_cap; -- cgit v1.2.3 From 49281a6d1a1ed1b1711261468ec3db2c5df0b833 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Tue, 14 Nov 2023 00:19:34 +0100 Subject: odirect_write.c: Address warning -Wsign-compare MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Symptom was: > tests/odirect_write.c: In function ‘main’: > tests/odirect_write.c:58:17: error: comparison of integer expressions of different signedness: ‘ssize_t’ {aka ‘long int’} and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] > 58 | if (res != buf_size) { > | ^~ --- tests/odirect_write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/odirect_write.c b/tests/odirect_write.c index 10b63f9..bc9040f 100644 --- a/tests/odirect_write.c +++ b/tests/odirect_write.c @@ -55,7 +55,7 @@ int main(int argc, char** argv) { perror("failed to write"); return 1; } - if (res != buf_size) { + if ((size_t)res != buf_size) { // Too lazy to write a loop here unless it turns out to be necessary. fprintf(stderr, "Failed to write exactly %lu bytes", (unsigned long)amt_read); } -- cgit v1.2.3 From 8a5dd381253eb52f44b3b0396143b99bc56faf13 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Tue, 14 Nov 2023 00:23:24 +0100 Subject: configure.ac: Add -Wextra --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 00f8ebc..0598619 100644 --- a/configure.ac +++ b/configure.ac @@ -35,7 +35,7 @@ AM_CONDITIONAL([BUILD_OS_IS_DARWIN], [case $build_os in darwin* ) true ;; * ) fa # _DARWIN_BETTER_REALPATH fixes MacOS realpath() broken around Catalina (#83). my_CPPFLAGS="-D_REENTRANT -D_FILE_OFFSET_BITS=64 -D_XOPEN_SOURCE=700 -D__BSD_VISIBLE=1 -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_DARWIN_BETTER_REALPATH" -my_CFLAGS="-std=c99 -Wall -Wpedantic -fno-common" +my_CFLAGS="-std=c99 -Wall -Wextra -Wpedantic -fno-common" my_LDFLAGS="-pthread" AC_SUBST([my_CPPFLAGS]) AC_SUBST([my_CFLAGS]) -- cgit v1.2.3 From 557548b352134c9859aa92e969f9a7970bbbcb2c Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Tue, 14 Nov 2023 00:26:44 +0100 Subject: linux.yml: Cover compilation with FUSE 2 --- .github/workflows/linux.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index cef2939..71e0759 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -12,27 +12,38 @@ on: jobs: linux: - name: Build (${{ matrix.cc }} on ${{ matrix.runs-on }}) + name: Build (${{ matrix.cc }} and ${{ matrix.fuse_package }} on ${{ matrix.runs-on }}) runs-on: ${{ matrix.runs-on }} strategy: fail-fast: false matrix: include: + # FUSE 2 - cc: gcc-13 cxx: g++-13 clang_major_version: null clang_repo_suffix: null runs-on: ubuntu-22.04 + fuse_package: libfuse-dev + # FUSE 3 + - cc: gcc-13 + cxx: g++-13 + clang_major_version: null + clang_repo_suffix: null + runs-on: ubuntu-22.04 + fuse_package: libfuse3-dev - cc: clang-17 cxx: clang++-17 clang_major_version: 17 clang_repo_suffix: -17 runs-on: ubuntu-22.04 + fuse_package: libfuse3-dev - cc: clang-18 cxx: clang++-18 clang_major_version: 18 clang_repo_suffix: runs-on: ubuntu-22.04 + fuse_package: libfuse3-dev steps: - name: Add Clang/LLVM repositories if: "${{ contains(matrix.cxx, 'clang') }}" @@ -48,7 +59,7 @@ jobs: sudo apt-get install --yes --no-install-recommends \ autoconf \ automake \ - libfuse3-dev \ + ${{ matrix.fuse_package }} \ libtool \ pkg-config -- cgit v1.2.3 From f35228177112c1bce0016dbdd0471aca35608b2b Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Tue, 14 Nov 2023 00:53:00 +0100 Subject: permchain.c: Handle malloc failure in add_chmod_rule_to_permchain --- src/permchain.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/permchain.c b/src/permchain.c index b95bd8b..ad32f9d 100644 --- a/src/permchain.c +++ b/src/permchain.c @@ -67,6 +67,8 @@ static int add_chmod_rule_to_permchain(const char *start, const char *end, int len = end - start; char *buf = malloc((len + 1) * sizeof(char)); + if (buf == NULL) + return -1; const char *p = buf; enum {LHS, RHS} state = LHS; -- cgit v1.2.3 From 1136f5bd18ce5b1657347dc26b0aa8e3153786ce Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Tue, 14 Nov 2023 00:54:15 +0100 Subject: permchain.c: Address warning -Wunused-parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fix is a near 1:1 copy of what add_chmod_rule_to_permchain already does about the same problem. Symptom was: > src/permchain.c: In function ‘add_octal_rule_to_permchain’: > src/permchain.c:151:71: error: unused parameter ‘end’ [-Werror=unused-parameter] > 151 | static int add_octal_rule_to_permchain(const char *start, const char *end, > | --- src/permchain.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/permchain.c b/src/permchain.c index ad32f9d..d101aa1 100644 --- a/src/permchain.c +++ b/src/permchain.c @@ -151,8 +151,18 @@ error: static int add_octal_rule_to_permchain(const char *start, const char *end, struct permchain *pc) { + // Make [start..end[ available as a null-terminated string to `strtol` + const int len = end - start; + char * const buf = malloc((len + 1) * sizeof(char)); + if (buf == NULL) + return -1; + memcpy(buf, start, len); + buf[len] = '\0'; + struct permchain *newpc = permchain_create(); - long mode = strtol(start, NULL, 8); + + long mode = strtol(buf, NULL, 8); + free(buf); if (mode < 0 || mode > 0777) { permchain_destroy(newpc); -- cgit v1.2.3