-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Description
Summary
The implementation of alt_clock_gettime()
in clock.cpp
does not check the return value of host_get_clock_service()
or clock_get_time()
. If either of these system calls fail, the function proceeds to use an uninitialized mach_timespec_t
, resulting in undefined behavior or potential crashes.
Affected Code
https://github.com/zeromq/libzmq/blob/master/src/clock.cpp
int alt_clock_gettime (int clock_id, timespec *ts)
{
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service (mach_host_self (), clock_id, &cclock);
clock_get_time (cclock, &mts);
mach_port_deallocate (mach_task_self (), cclock);
ts->tv_sec = mts.tv_sec;
ts->tv_nsec = mts.tv_nsec;
return 0;
}
Problem
host_get_clock_service()
andclock_get_time()
can fail, returning a non-zerokern_return_t
- No return code is checked before using the result
- If either call fails,
mts.tv_sec
andmts.tv_nsec
are undefined - This can result in corrupted timestamps or segmentation faults
Expected Behavior
- Both system calls should be checked for
KERN_SUCCESS
before usingmts
- If any of them fails,
alt_clock_gettime()
should return-1
as an error signal, consistent withclock_gettime
behavior
Platform
- macOS < 10.12 (this code path is used as fallback)
- Affects users relying on
alt_clock_gettime()
for monotonic time
Impact
Low frequency, but high risk when triggered — undefined time values or potential crash.
Metadata
Metadata
Assignees
Labels
No labels