Skip to content

Commit

Permalink
src/freon.c: Check before extracting mode in open
Browse files Browse the repository at this point in the history
Fixes #3140
  • Loading branch information
jbaum98 committed Nov 20, 2017
1 parent 99877ea commit 51ffe99
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/freon.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#define _GNU_SOURCE
#include <dlfcn.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/file.h>
#include <sys/types.h>
Expand Down Expand Up @@ -228,9 +229,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);
Expand All @@ -239,9 +242,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);
Expand Down

0 comments on commit 51ffe99

Please sign in to comment.