summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-06-06 15:43:16 -0400
committerRich Felker <dalias@aerifal.cx>2014-06-06 15:43:16 -0400
commit9c2d437cb343a9a9e1c2d5dea4e0ae6a7d4fa0be (patch)
tree947945c14468d53e39742cfe33834a6d9f7bd26f /src
parent7765706c0584ed4a30e0b7a3ada742e490ef02b0 (diff)
downloadmusl-9c2d437cb343a9a9e1c2d5dea4e0ae6a7d4fa0be.tar.gz
musl-9c2d437cb343a9a9e1c2d5dea4e0ae6a7d4fa0be.tar.bz2
musl-9c2d437cb343a9a9e1c2d5dea4e0ae6a7d4fa0be.tar.xz
musl-9c2d437cb343a9a9e1c2d5dea4e0ae6a7d4fa0be.zip
avoid invalid use of va_arg in open
reading the variadic mode argument is only valid when the O_CREAT flag is present. this probably does not matter, but is needed for formal correctness, and could affect LTO or other full-program analysis.
Diffstat (limited to 'src')
-rw-r--r--src/fcntl/open.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/fcntl/open.c b/src/fcntl/open.c
index 088a28f7..5e5be1d7 100644
--- a/src/fcntl/open.c
+++ b/src/fcntl/open.c
@@ -5,11 +5,14 @@
int open(const char *filename, int flags, ...)
{
- mode_t mode;
- va_list ap;
- va_start(ap, flags);
- mode = va_arg(ap, mode_t);
- va_end(ap);
+ mode_t mode = 0;
+
+ if (flags & O_CREAT) {
+ va_list ap;
+ va_start(ap, flags);
+ mode = va_arg(ap, mode_t);
+ va_end(ap);
+ }
int fd = __sys_open_cp(filename, flags, mode);
if (fd>=0 && (flags & O_CLOEXEC))