FORTIFY_SOURCE: add open() checks
Add a FORTIFY_SOURCE check which requires that you pass a
"mode" argument when calling open(..., O_CREAT). If a mode isn't
passed, then the file is created with "undefined" permissions.
Change-Id: I4427be4f9ce170c69da01af5b00fb05b03613a28
diff --git a/libc/unistd/open.c b/libc/unistd/open.c
index 03cba45..56602db 100644
--- a/libc/unistd/open.c
+++ b/libc/unistd/open.c
@@ -28,6 +28,8 @@
#include <unistd.h>
#include <fcntl.h>
#include <stdarg.h>
+#include <stdlib.h>
+#include <private/logd.h>
extern int __open(const char*, int, int);
@@ -49,3 +51,15 @@
return __open(pathname, flags, mode);
}
+int __open_2(const char *pathname, int flags) {
+ if (flags & O_CREAT) {
+ __libc_android_log_print(ANDROID_LOG_FATAL, "libc",
+ "*** open(O_CREAT) called without specifying a mode ***\n");
+ abort();
+ }
+
+ flags |= O_LARGEFILE;
+
+ return __open(pathname, flags, 0);
+}
+