hello libc hackers,

the following ISO C conforming program is broken on latest OpenBSD:

#include <stdio.h>
int close() { puts("XXX"); return 0;}
int main() { fclose(stdout); return 0;}

the program is expected to not produce any output, however on OpenBSD it prints "XXX".
this bug affects real-world programs [0].

the attached patch is incomplete, since i cannot find the definition of close() in the OpenBSD source tree.

--- a/lib/libc/stdio/stdio.c
+++ b/lib/libc/stdio/stdio.c
@@ -82,8 +82,10 @@ __sseek(void *cookie, fpos_t offset, int whence)
        return (ret);
 }

+extern int __close(int);
+
 int
 __sclose(void *cookie)
 {
-       return (close(((FILE *)cookie)->_file));
+       return (__close(((FILE *)cookie)->_file));
 }


the hypothetical file close.c needs the following change

- int close(int fd) {
+ int __close(int fd) {
 ...
 }
+ __weak_alias(close, __close)

Please CC me on replies, since i am not subscribed to the list.

[0] https://github.com/rofl0r/proxychains-ng/issues/95

Best regards,
--JS

Reply via email to