diff options
author | Darren Tucker <dtucker@dtucker.net> | 2018-03-05 19:28:08 +1100 |
---|---|---|
committer | Darren Tucker <dtucker@dtucker.net> | 2018-03-05 19:28:08 +1100 |
commit | 58fd4c5c0140f6636227ca7acbb149ab0c2509b9 (patch) | |
tree | 51a79fa23c4140148ba59f9c43107fedefe9bbae /openbsd-compat | |
parent | 71e48bc7945f867029e50e06c665c66aed6d3c64 (diff) |
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.
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/bsd-misc.c | 16 | ||||
-rw-r--r-- | openbsd-compat/bsd-misc.h | 4 |
2 files changed, 20 insertions, 0 deletions
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 */ |