path: root/src/corelib
diff options
authorThiago Macieira <>2018-07-13 00:26:30 -0700
committerThiago Macieira <>2018-07-17 22:23:06 +0000
commit1d33493989eae774bafc124f9d3ee68d7a017a10 (patch)
treefbae955b046e45b3d7b979f71e4a9999c4f72a99 /src/corelib
parente20307dcfbd30fbc4f43dfb3626f440a48567416 (diff)
Linux: Bypass glibc's broken open() implementation
Glibc 2.21 and earlier have a bug that leaves the mode parameter unset when O_TMPFILE is used. So we bypass the glibc implementation and go directly for the syscall. We do this only for 32-bit x86, since of the current, modern platforms, it's the only one that passes parameters on the stack. Technically speaking, the glibc bug applies to all platforms, but it turns out that on all others, it appears to work. By doing this, we have two minor differences: 1) open() is a cancellation point, but syscall() isn't 2) if anyone tries to intercept open() calls via LD_PRELOAD, they're not going to catch Qt's. [ChangeLog][QtCore][QTemporaryFile] Worked around a bug in the GNU C Library versions 2.21 and earlier (used on Linux) that caused temporary files to be created with permissions 000. Task-number: QTBUG-69436 Change-Id: I20fd00e600264ff98c6afffd1540dceea89fa91f Reviewed-by: Simon Hausmann <>
Diffstat (limited to 'src/corelib')
2 files changed, 28 insertions, 0 deletions
diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp
index eb98cbef8f..18c031f137 100644
--- a/src/corelib/kernel/qcore_unix.cpp
+++ b/src/corelib/kernel/qcore_unix.cpp
@@ -44,6 +44,12 @@
#include <stdlib.h>
+#ifdef __GLIBC__
+# include <sys/syscall.h>
+# include <pthread.h>
+# include <unistd.h>
#ifdef Q_OS_MAC
#include <mach/mach_time.h>
@@ -79,6 +85,20 @@ QByteArray qt_readlink(const char *path)
return buf;
+#if defined(Q_PROCESSOR_X86_32) && defined(__GLIBC__)
+# if !__GLIBC_PREREQ(2, 22)
+// glibc prior to release 2.22 had a bug that suppresses the third argument to
+// open() / open64() / openat(), causing file creation with O_TMPFILE to have
+// the wrong permissions. So we bypass the glibc implementation and go straight
+// for the syscall. See
+int qt_open64(const char *pathname, int flags, mode_t mode)
+ return syscall(SYS_open, pathname, flags | O_LARGEFILE, mode);
+# endif
#if QT_CONFIG(poll_pollts)
diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h
index e538a7e22b..cb98bef347 100644
--- a/src/corelib/kernel/qcore_unix_p.h
+++ b/src/corelib/kernel/qcore_unix_p.h
@@ -176,6 +176,14 @@ inline void qt_ignore_sigpipe()
+#if defined(Q_PROCESSOR_X86_32) && defined(__GLIBC__)
+# if !__GLIBC_PREREQ(2, 22)
+int qt_open64(const char *pathname, int flags, mode_t);
+# undef QT_OPEN
+# define QT_OPEN qt_open64
+# endif
// don't call QT_OPEN or ::open
// call qt_safe_open
static inline int qt_safe_open(const char *pathname, int flags, mode_t mode = 0777)