From c8ed32faae0dcbb60004b4e517d28355b1b7a1de Mon Sep 17 00:00:00 2001 From: Babneet Singh Date: Thu, 3 May 2018 21:38:22 -0400 Subject: [PATCH] Properly handle NULL values for oldOSHandler omrsig_set_single_async_signal_handler and omrsig_register_os_handler have been updated to properly handle NULL values for oldOSHandler. Function description has been updated for both of them. A trace point was accessing oldOSHandler without a NULL check. A NULL check has been added before the trace point accesses oldOSHandler. Signed-off-by: Babneet Singh --- port/common/omrsignal.c | 15 +++++++++++---- port/unix/omrsignal.c | 13 +++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/port/common/omrsignal.c b/port/common/omrsignal.c index e5616967d84..09e262f8b76 100644 --- a/port/common/omrsignal.c +++ b/port/common/omrsignal.c @@ -180,8 +180,12 @@ omrsig_set_async_signal_handler(struct OMRPortLibrary *portLibrary, omrsig_handl * entry corresponding to omrsig_handler_fn is removed, and related resources are freed. portlibSignalFlag can only * have one signal flag set; otherwise, OMRPORT_SIG_ERROR is returned. One omrsig_handler_fn handler is registered * with a signal at any time instead of multiple handlers. When associating a new omrsig_handler_fn with a signal, - * prior omrsig_handler_fn(s) are dissociated from the signal. The address of the old signal handler function is - * stored in oldOSHandler. This function supports all signals listed in OMRPORT_SIG_FLAG_SIGALLASYNC. + * prior omrsig_handler_fn(s) are dissociated from the signal. This function supports all signals listed in + * OMRPORT_SIG_FLAG_SIGALLASYNC. + * + * The address of the old signal handler function is stored in *oldOSHandler. In case of error, *oldOSHandler will + * not be updated. If NULL is provided for oldOSHandler, then *oldOSHandler will not be updated to reflect the old + * signal handler function. * * @param[in] portLibrary The port library * @param[in] handler the function to call if an asynchronous signal arrives @@ -228,8 +232,11 @@ omrsig_map_portlib_signal_to_os_signal(struct OMRPortLibrary *portLibrary, uint3 /** * @brief Register a handler with the OS. For an invalid portlibSignalFlag, an error is returned. * portlibSignalFlag is invalid if it is zero or if multiple signal bits are specified. If - * OS fails to register newOSHandler for the specified signal, then an error is returned. In - * error cases, oldOSHandler won't be updated. + * OS fails to register newOSHandler for the specified signal, then an error is returned. + * + * The address of the old signal handler function is stored in *oldOSHandler. In case of error, + * *oldOSHandler will not be updated. If NULL is provided for oldOSHandler, then *oldOSHandler + * will not be updated to reflect the old signal handler function. * * This function may override a master handler which was previously set by omrsig_protect or * omrsig_set_*_async_signal_handler variant. The records associated with the master handler diff --git a/port/unix/omrsignal.c b/port/unix/omrsignal.c index d281d8d232d..f43d142c067 100644 --- a/port/unix/omrsignal.c +++ b/port/unix/omrsignal.c @@ -575,7 +575,12 @@ omrsig_set_single_async_signal_handler(struct OMRPortLibrary *portLibrary, omrsi omrthread_monitor_exit(asyncMonitor); - Trc_PRT_signal_omrsig_set_single_async_signal_handler_exiting(rc, handler, handler_arg, portlibSignalFlag, *oldOSHandler); + if (NULL != oldOSHandler) { + Trc_PRT_signal_omrsig_set_single_async_signal_handler_exiting(rc, handler, handler_arg, portlibSignalFlag, *oldOSHandler); + } else { + Trc_PRT_signal_omrsig_set_single_async_signal_handler_exiting(rc, handler, handler_arg, portlibSignalFlag, NULL); + } + return rc; } @@ -626,7 +631,11 @@ omrsig_register_os_handler(struct OMRPortLibrary *portLibrary, uint32_t portlibS omrthread_monitor_exit(registerHandlerMonitor); } - Trc_PRT_signal_omrsig_register_os_handler_exiting(rc, portlibSignalFlag, newOSHandler, *oldOSHandler); + if (NULL != oldOSHandler) { + Trc_PRT_signal_omrsig_register_os_handler_exiting(rc, portlibSignalFlag, newOSHandler, *oldOSHandler); + } else { + Trc_PRT_signal_omrsig_register_os_handler_exiting(rc, portlibSignalFlag, newOSHandler, NULL); + } return rc; }