From 9d6e4c27b73a3608ecf6899027995e84a40f0e19 Mon Sep 17 00:00:00 2001 From: Guilherme Janczak Date: Thu, 7 Dec 2023 04:00:49 +0000 Subject: [PATCH] remove unnecessary workaround for fclose() on OpenBSD proxychains-ng didn't call fclose() in a particular FILE on OpenBSD if a test in the Makefile noticed that OpenBSD's fclose() called close() on the underlying fd of the FILE. The test hasn't worked for 8 years because an OpenBSD commit prevented the test from overriding the libc close(): https://cvsweb.openbsd.org/src/lib/libc/stdio/fclose.c?rev=1.10&content-type=text/x-cvsweb-markup >let internal calls resolve directly and not be overridable For all this time, the workaround wasn't doing anything. Additionally, behavior equivalent to calling close() on a fd is mandatory in POSIX: https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/ >The fclose() function shall perform the equivalent of a close() >on the file descriptor And finally, at least NetBSD 9.3 also uses the close() function to do the same, but there's no workaround, and no reported misbehavior when running on NetBSD to work around. Even if the test did work, all the workaround appears to do is leak a FILE. --- configure | 3 --- src/libproxychains.c | 6 ++---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/configure b/configure index 7ceb122..46738b3 100755 --- a/configure +++ b/configure @@ -220,9 +220,6 @@ check_define __FreeBSD__ && bsd_detected=true check_define __OpenBSD__ && { bsd_detected=true echo "CFLAGS+=-DIS_OPENBSD">>config.mak -check_compile_run 'whether OpenBSDs fclose() (illegally) calls close()' \ -'#include \n#include\nint close(int x){exit(0);}int main(){fclose(stdin);return 1;}' && \ -OUR_CPPFLAGS="$OUR_CPPFLAGS -DBROKEN_FCLOSE" } check_define __sun && check_define __SVR4 && solaris_detected=true check_define __HAIKU__ && haiku_detected=true diff --git a/src/libproxychains.c b/src/libproxychains.c index 84a8f00..38f4c15 100644 --- a/src/libproxychains.c +++ b/src/libproxychains.c @@ -115,7 +115,7 @@ typedef struct { unsigned int first, last, flags; } close_range_args_t; -/* If there is some `close` or `close_range` system call before do_init, +/* If there is some `close` or `close_range` system call before do_init, we buffer it, and actually execute them in do_init. */ static int close_fds[16]; static int close_fds_cnt = 0; @@ -560,9 +560,7 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ } } } -#ifndef BROKEN_FCLOSE fclose(file); -#endif if(!count) { fprintf(stderr, "error: no valid proxy found in config\n"); exit(1); @@ -639,7 +637,7 @@ HOOKFUNC(int, close_range, unsigned first, unsigned last, int flags) { int protected_fds[] = {req_pipefd[0], req_pipefd[1], resp_pipefd[0], resp_pipefd[1]}; intsort(protected_fds, 4); /* We are skipping protected_fds while calling true_close_range() - * If protected_fds cut the range into some sub-ranges, we close sub-ranges BEFORE cut point in the loop. + * If protected_fds cut the range into some sub-ranges, we close sub-ranges BEFORE cut point in the loop. * [first, cut1-1] , [cut1+1, cut2-1] , [cut2+1, cut3-1] * Finally, we delete the remaining sub-range, outside the loop. [cut3+1, tail] */