aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2022-07-15 14:10:53 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2022-11-22 14:31:25 +0000
commit868b753880f56e598c62c5345769064d35cf9687 (patch)
tree12da8f98909e7ba3025a93713e01169ff81e169a /sysdeps/unix
parent04d2fec011b657210a410e95ec61783f77987648 (diff)
downloadglibc-868b753880f56e598c62c5345769064d35cf9687.zip
glibc-868b753880f56e598c62c5345769064d35cf9687.tar.gz
glibc-868b753880f56e598c62c5345769064d35cf9687.tar.bz2
aarch64: morello: fix missing variadic argument in fcntl
In fcntl va_arg is currently used even if the caller did not pass any variadic arguments. This is undefined behaviour and does not work with the Morello purecap ABI, so use a helper macro. When the argument is missing, the result of the helper macro is arbitrary as it will be ignored by the kernel, we just have to ensure it does not cause a runtime crash.
Diffstat (limited to 'sysdeps/unix')
-rw-r--r--sysdeps/unix/sysv/linux/aarch64/morello/sysdep.h2
-rw-r--r--sysdeps/unix/sysv/linux/fcntl64.c6
-rw-r--r--sysdeps/unix/sysv/linux/fcntl_nocancel.c6
3 files changed, 12 insertions, 2 deletions
diff --git a/sysdeps/unix/sysv/linux/aarch64/morello/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/morello/sysdep.h
index 5db89b0..bad64a0 100644
--- a/sysdeps/unix/sysv/linux/aarch64/morello/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/morello/sysdep.h
@@ -105,6 +105,8 @@ typedef __intcap_t __sysarg_t;
LOAD_ARGS_6 (c0, c1, c2, c3, c4, c5) \
register __sysarg_t _x6 asm ("c6") = _x6tmp;
+# define FCNTL_VA_ARG(a, t) (a ? va_arg(a, t) : 0)
+
#endif /* __ASSEMBLER__ */
/* Disable pointer mangling for purecap ABI. */
diff --git a/sysdeps/unix/sysv/linux/fcntl64.c b/sysdeps/unix/sysv/linux/fcntl64.c
index 5192b2d..0b6afd3 100644
--- a/sysdeps/unix/sysv/linux/fcntl64.c
+++ b/sysdeps/unix/sysv/linux/fcntl64.c
@@ -29,6 +29,10 @@
# define __NR_fcntl64 __NR_fcntl
#endif
+#ifndef FCNTL_VA_ARG
+# define FCNTL_VA_ARG(a, t) va_arg(a, t)
+#endif
+
#ifndef FCNTL_ADJUST_CMD
# define FCNTL_ADJUST_CMD(__cmd) __cmd
#endif
@@ -40,7 +44,7 @@ __libc_fcntl64 (int fd, int cmd, ...)
void *arg;
va_start (ap, cmd);
- arg = va_arg (ap, void *);
+ arg = FCNTL_VA_ARG (ap, void *);
va_end (ap);
cmd = FCNTL_ADJUST_CMD (cmd);
diff --git a/sysdeps/unix/sysv/linux/fcntl_nocancel.c b/sysdeps/unix/sysv/linux/fcntl_nocancel.c
index 7c38e22..f21b56d 100644
--- a/sysdeps/unix/sysv/linux/fcntl_nocancel.c
+++ b/sysdeps/unix/sysv/linux/fcntl_nocancel.c
@@ -26,6 +26,10 @@
# define __NR_fcntl64 __NR_fcntl
#endif
+#ifndef FCNTL_VA_ARG
+# define FCNTL_VA_ARG(a, t) va_arg(a, t)
+#endif
+
#ifndef FCNTL_ADJUST_CMD
# define FCNTL_ADJUST_CMD(__cmd) __cmd
#endif
@@ -37,7 +41,7 @@ __fcntl64_nocancel (int fd, int cmd, ...)
void *arg;
va_start (ap, cmd);
- arg = va_arg (ap, void *);
+ arg = FCNTL_VA_ARG (ap, void *);
va_end (ap);
cmd = FCNTL_ADJUST_CMD (cmd);