From 2426de44158aef4ebeb3f84afdcf92768c0d0eeb Mon Sep 17 00:00:00 2001 From: Jake Waksbaum Date: Wed, 14 Jun 2017 01:42:30 -0400 Subject: [PATCH] src/freon.c: Check before extracting mode in open Fixes #3140 --- src/freon.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/freon.c b/src/freon.c index 53c9426f0..355f24c34 100644 --- a/src/freon.c +++ b/src/freon.c @@ -218,9 +218,11 @@ static int _open(int (*origfunc)(const char *pathname, int flags, mode_t mode), int open(const char *pathname, int flags, ...) { if (!orig_open) preload_init(); + mode_t mode = 0; va_list argp; va_start(argp, flags); - mode_t mode = va_arg(argp, mode_t); + if (flags & (O_CREAT | O_TMPFILE)) + mode = va_arg(argp, mode_t); va_end(argp); return _open(orig_open, "open", pathname, flags, mode); @@ -229,9 +231,11 @@ int open(const char *pathname, int flags, ...) { int open64(const char *pathname, int flags, ...) { if (!orig_open64) preload_init(); + mode_t mode = 0; va_list argp; va_start(argp, flags); - mode_t mode = va_arg(argp, mode_t); + if (flags & (O_CREAT | O_TMPFILE)) + mode = va_arg(argp, mode_t); va_end(argp); return _open(orig_open64, "open64", pathname, flags, mode);