[openssh-commits] [openssh] 01/03: Check for and work around buggy fflush(NULL).

git+noreply at mindrot.org git+noreply at mindrot.org
Thu Mar 8 10:42:24 AEDT 2018


This is an automated email from the git hooks/post-receive script.

dtucker pushed a commit to branch master
in repository openssh.

commit 58fd4c5c0140f6636227ca7acbb149ab0c2509b9
Author: Darren Tucker <dtucker at dtucker.net>
Date:   Mon Mar 5 19:28:08 2018 +1100

    Check for and work around buggy fflush(NULL).
    
    Some really old platforms (eg SunOS4) segfault on fflush(NULL) so check
    for and work around.  With klausz at haus-gisela.de.
---
 configure.ac              | 10 ++++++++++
 openbsd-compat/bsd-misc.c | 16 ++++++++++++++++
 openbsd-compat/bsd-misc.h |  4 ++++
 3 files changed, 30 insertions(+)

diff --git a/configure.ac b/configure.ac
index 70e72be7..d2fb4469 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2059,6 +2059,16 @@ AC_CHECK_FUNCS([realpath], [
 	)
 ])
 
+AC_MSG_CHECKING([for working fflush(NULL)])
+AC_RUN_IFELSE(
+	[AC_LANG_PROGRAM([[#include <stdio.h>]], [[fflush(NULL); exit(0);]])],
+	AC_MSG_RESULT([yes]),
+	[AC_MSG_RESULT([no])
+	 AC_DEFINE([FFLUSH_NULL_BUG], [1],
+	    [define if fflush(NULL) does not work])],
+	AC_MSG_WARN([cross compiling: assuming working])
+)
+
 dnl    Checks for time functions
 AC_CHECK_FUNCS([gettimeofday time])
 dnl    Checks for utmp functions
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c
index f7187daf..3daf6107 100644
--- a/openbsd-compat/bsd-misc.c
+++ b/openbsd-compat/bsd-misc.c
@@ -308,3 +308,19 @@ getsid(pid_t pid)
 }
 #endif
 
+#ifdef FFLUSH_NULL_BUG
+#undef fflush
+int _ssh_compat_fflush(FILE *f)
+{
+	int r1, r2, r3;
+
+	if (f == NULL) {
+		r2 = fflush(stdout);
+		r3 = fflush(stderr);
+		if (r1 == -1 || r2 == -1 || r3 == -1)
+			return -1;
+		return 0;
+	}
+	return fflush(f);
+}
+#endif
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h
index fb81e6c7..52ec5285 100644
--- a/openbsd-compat/bsd-misc.h
+++ b/openbsd-compat/bsd-misc.h
@@ -153,4 +153,8 @@ pid_t getsid(pid_t);
 int flock(int, int);
 #endif
 
+#ifdef FFLUSH_NULL_BUG
+# define fflush(x)	(_ssh_compat_fflush(x))
+#endif
+
 #endif /* _BSD_MISC_H */

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list