Skip to content

Commit

Permalink
Properly handle NULL values for oldOSHandler
Browse files Browse the repository at this point in the history
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 <sbabneet@ca.ibm.com>
  • Loading branch information
babsingh committed May 4, 2018
1 parent 621826d commit c8ed32f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
15 changes: 11 additions & 4 deletions port/common/omrsignal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions port/unix/omrsignal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c8ed32f

Please sign in to comment.