# 2024-08-05 # NOTE: Upstream Samba commit 9f63fad392f3 removed the static array defining Linux and FreeBSD # fdescfs paths and hardcoded a Linux-specific /proc path, with the note that if any # others need to be added, they can be done so via #ifdef's. This patch attempts to # do that, but in a way that minimizes the necessary #ifdefs by defining a simplistic # #define macro to generate the appropriate path for fdescfs based on the running OS. # # See: https://git.samba.org/?p=samba.git;a=commitdiff;h=9f63fad392f3cff34d6a8e318e0427499170c417 diff -Naurp a/lib/fuzzing/fuzz_regfio.c b/lib/fuzzing/fuzz_regfio.c --- a/lib/fuzzing/fuzz_regfio.c 2024-02-02 04:33:50.952488000 -0500 +++ b/lib/fuzzing/fuzz_regfio.c 2024-08-05 20:41:16.624793000 -0400 @@ -31,7 +31,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) { fp = tmpfile(); - (void)snprintf(filename, sizeof(filename), "/proc/self/fd/%d", fileno(fp)); + (void)snprintf(filename, sizeof(filename), PROC_FD_PATH_MKSTR(%d), fileno(fp)); return 0; } diff -Naurp a/lib/replace/closefrom.c b/lib/replace/closefrom.c --- a/lib/replace/closefrom.c 2024-02-02 04:33:50.984488200 -0500 +++ b/lib/replace/closefrom.c 2024-08-05 20:41:16.625141000 -0400 @@ -53,7 +53,7 @@ static int closefrom_procfs(int lower) size_t i; int ret = ENOMEM; - dirp = opendir("/proc/self/fd"); + dirp = opendir(PROC_FD_PATH_MKSTR()); if (dirp == NULL) { return errno; } diff -Naurp a/source3/include/proto.h b/source3/include/proto.h --- a/source3/include/proto.h 2024-08-05 20:40:38.434560000 -0400 +++ b/source3/include/proto.h 2024-08-05 20:41:26.063626000 -0400 @@ -205,8 +205,21 @@ int sys_get_number_of_cores(void); int sys_get_number_of_cores(void); #endif +#ifdef __FreeBSD__ +#define PROC_FD_PATH_STR "/compat/linux/dev/fd/" +#define PROC_FD_PATH_SZ 42 +#else /* Linux */ +#define PROC_FD_PATH_STR "/proc/self/fd/" +#define PROC_FD_PATH_SZ 35 +#endif + +#define _S(_t) #_t +#define _V(...) _S(__VA_ARGS__) +#define _X(_t) _t +#define PROC_FD_PATH_MKSTR(_fd) _V(_X(PROC_FD_PATH_STR)_X(_fd)) + struct sys_proc_fd_path_buf { - char buf[35]; /* "/proc/self/fd/" + strlen(2^64) + 0-terminator */ + char buf[PROC_FD_PATH_SZ]; /* strlen(PROC_FD_PATH_STR) + strlen(2^64) + 0-terminator */ }; bool sys_have_proc_fds(void); char *sys_proc_fd_path(int fd, struct sys_proc_fd_path_buf *buf); diff -Naurp a/source3/lib/system.c b/source3/lib/system.c --- a/source3/lib/system.c 2024-08-05 20:40:38.434801000 -0400 +++ b/source3/lib/system.c 2024-08-05 20:41:16.625938000 -0400 @@ -1068,7 +1068,7 @@ char *sys_proc_fd_path(int fd, struct sys_proc_fd_path char *sys_proc_fd_path(int fd, struct sys_proc_fd_path_buf *buf) { int written = - snprintf(buf->buf, sizeof(buf->buf), "/proc/self/fd/%d", fd); + snprintf(buf->buf, sizeof(buf->buf), PROC_FD_PATH_MKSTR(%d), fd); SMB_ASSERT(sys_have_proc_fds() && (written >= 0));