Accessing elements in an empty va_list is undefined behaviour. Therefore, remove the variadicness from safe_* wrappers that always call the functions with the optional argument included.
Adapt the SAFE_OPEN, SAFE_OPENAT, SAFE_SEMCTL macros to handle the change by passing a default arguments if they're omitted.
v3: - Combined the open/openat patch with the semctl one into a single series. - Split the open/openat patch into two patches. - Introduced a new PATCH (i.e. 1/4) that implements a common handler chooser for open/openat/semctl cases. - Removed an unused va_list variable.
v2: - Added parenthesis around macro arguments
Review branch: https://git.morello-project.org/tudcre01/morello-linux-ltp/-/commits/review/...
Tudor Cretu (4): safe_macros: Introduce macro to avoid undefined behaviour in variadic safe functions safe_open: Fix undefined behaviour in vararg handling safe_openat: Fix undefined behaviour in vararg handling safe_semctl: Fix undefined behaviour in vararg handling
include/old/safe_macros.h | 12 ++++++++++-- include/safe_macros_fn.h | 3 ++- include/safe_vararg_macros.h | 37 ++++++++++++++++++++++++++++++++++++ include/tst_safe_file_at.h | 19 ++++++++++++++---- include/tst_safe_macros.h | 11 +++++++++-- include/tst_safe_sysv_ipc.h | 14 +++++++++++--- lib/safe_macros.c | 13 +------------ lib/tst_safe_file_at.c | 11 +++-------- lib/tst_safe_sysv_ipc.c | 10 +--------- 9 files changed, 89 insertions(+), 41 deletions(-) create mode 100644 include/safe_vararg_macros.h