From 753f3872370a076628c272612da51963f4996ca4 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 1 Aug 2017 10:58:50 +0200 Subject: swrap: Improve argument handling for libc_vopen*() Signed-off-by: Andreas Schneider Reviewed-by: Stefan Metzmacher --- src/socket_wrapper.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index 0a7dacf..d95dbc0 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -859,13 +859,14 @@ static FILE *libc_fopen64(const char *name, const char *mode) static int libc_vopen(const char *pathname, int flags, va_list ap) { - long int mode = 0; + int mode = 0; int fd; swrap_bind_symbol_libc(open); - mode = va_arg(ap, long int); - + if (flags & O_CREAT) { + mode = va_arg(ap, int); + } fd = swrap.libc.symbols._libc_open.f(pathname, flags, (mode_t)mode); return fd; @@ -886,13 +887,14 @@ static int libc_open(const char *pathname, int flags, ...) #ifdef HAVE_OPEN64 static int libc_vopen64(const char *pathname, int flags, va_list ap) { - long int mode = 0; + int mode = 0; int fd; swrap_bind_symbol_libc(open64); - mode = va_arg(ap, long int); - + if (flags & O_CREAT) { + mode = va_arg(ap, int); + } fd = swrap.libc.symbols._libc_open64.f(pathname, flags, (mode_t)mode); return fd; @@ -901,14 +903,18 @@ static int libc_vopen64(const char *pathname, int flags, va_list ap) static int libc_vopenat(int dirfd, const char *path, int flags, va_list ap) { - long int mode = 0; + int mode = 0; int fd; swrap_bind_symbol_libc(openat); - mode = va_arg(ap, long int); - - fd = swrap.libc.symbols._libc_openat.f(dirfd, path, flags, (mode_t)mode); + if (flags & O_CREAT) { + mode = va_arg(ap, int); + } + fd = swrap.libc.symbols._libc_openat.f(dirfd, + path, + flags, + (mode_t)mode); return fd; } -- cgit