Commit 1daeace3 authored by Vincent Pelletier's avatar Vincent Pelletier

Do not call va_arg when open O_DIRECTORY flag is set.

Also, fix build on systems without O_TMPFILE.
parent 0681899b
......@@ -29,6 +29,14 @@
#define ORIGINAL_HOSTS_PATH "/etc/hosts"
/* Standard O_TMPFILE includes O_DIRECTORY bit, but we do not want to call
* va_arg if O_DIRECTORY is set alone. Hence, define a "purer" O_TMPFILE. */
#define PURE_O_TMPFILE (020000000)
/* And sanity-check when O_TMPFILE is defined. */
#if defined(O_TMPFILE) && (O_TMPFILE & PURE_O_TMPFILE) == 0
#error PURE_O_TMPFILE is incorrectly defined
#endif
static int (*original_open)(const char *, int, ...);
static FILE *(*original_fopen)(const char *, const char *);
static const char *replacement_hosts;
......@@ -59,7 +67,7 @@ static void __attribute__ ((constructor)) init(void) {
int open(const char *__file, int __oflag, ...) {
if(strcmp(__file, ORIGINAL_HOSTS_PATH) == 0)
__file = replacement_hosts;
if (__oflag & (O_CREAT | O_TMPFILE)) {
if (__oflag & (O_CREAT | PURE_O_TMPFILE)) {
va_list ap;
mode_t mode;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment