summaryrefslogtreecommitdiffstats
path: root/openbsd-compat/kludge-fd_set.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2014-10-01 09:43:07 +1000
committerDamien Miller <djm@mindrot.org>2014-10-01 09:43:07 +1000
commit703b98a26706f5083801d11059486d77491342ae (patch)
treef579b652709063fc828788830e50a83c16ff1ca3 /openbsd-compat/kludge-fd_set.c
parent0fa0ed061bbfedb0daa705e220748154a84c3413 (diff)
- (djm) [openbsd-compat/Makefile.in openbsd-compat/kludge-fd_set.c]
[openbsd-compat/openbsd-compat.h] Kludge around bad glibc _FORTIFY_SOURCE check that doesn't grok heap-allocated fd_sets; ok dtucker@
Diffstat (limited to 'openbsd-compat/kludge-fd_set.c')
-rw-r--r--openbsd-compat/kludge-fd_set.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/openbsd-compat/kludge-fd_set.c b/openbsd-compat/kludge-fd_set.c
new file mode 100644
index 00000000..6c2ffb64
--- /dev/null
+++ b/openbsd-compat/kludge-fd_set.c
@@ -0,0 +1,28 @@
+/* Placed in the public domain. */
+
+/*
+ * _FORTIFY_SOURCE includes a misguided check for FD_SET(n)/FD_ISSET(b)
+ * where n > FD_SETSIZE. This breaks OpenSSH and other programs that
+ * explicitly allocate fd_sets. To avoid this, we wrap FD_SET in a
+ * function compiled without _FORTIFY_SOURCE.
+ */
+
+#include "config.h"
+
+#if defined(HAVE_FEATURES_H) && defined(_FORTIFY_SOURCE)
+# include <features.h>
+# if defined(__GNU_LIBRARY__) && defined(__GLIBC_PREREQ)
+# if __GLIBC_PREREQ(2, 15) && (_FORTIFY_SOURCE > 0)
+# undef _FORTIFY_SOURCE
+# undef __USE_FORTIFY_LEVEL
+# include <sys/socket.h>
+void kludge_FD_SET(int n, fd_set *set) {
+ FD_SET(n, set);
+}
+int kludge_FD_ISSET(int n, fd_set *set) {
+ return FD_ISSET(n, set);
+}
+# endif /* __GLIBC_PREREQ(2, 15) && (_FORTIFY_SOURCE > 0) */
+# endif /* __GNU_LIBRARY__ && __GLIBC_PREREQ */
+#endif /* HAVE_FEATURES_H && _FORTIFY_SOURCE */
+