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.
v4: - Updated the commit message of Patch 1 and some comments - Renamed safe_vararg_macros.h -> tst_safe_vararg_macros.h - Renamed SAFE_WRAPPER_COND_HANDLER -> SAFE_COND_HANDLER - Improved alignment to make macros more readable
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 | 13 +++++++++-- include/safe_macros_fn.h | 3 ++- include/tst_safe_file_at.h | 16 ++++++++++---- include/tst_safe_macros.h | 12 ++++++++-- include/tst_safe_sysv_ipc.h | 19 +++++++++++----- include/tst_safe_vararg_macros.h | 38 ++++++++++++++++++++++++++++++++ lib/safe_macros.c | 13 +---------- lib/tst_safe_file_at.c | 11 +++------ lib/tst_safe_sysv_ipc.c | 10 +-------- 9 files changed, 92 insertions(+), 43 deletions(-) create mode 100644 include/tst_safe_vararg_macros.h