[lttng-dev] [PATCH lttng-tools 1/2] Fix: Connect timeout arithmetic in inet/inet6 (v2)

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Sat Nov 10 09:13:44 EST 2018


----- On Nov 9, 2018, at 6:43 PM, Jonathan Rajotte jonathan.rajotte-julien at efficios.com wrote:

>> diff --git a/src/common/utils.c b/src/common/utils.c
>> index 3442bef8..5b4e1d3c 100644
>> --- a/src/common/utils.c
>> +++ b/src/common/utils.c

[...]

>> +LTTNG_HIDDEN
>> +int timespec_to_ms(struct timespec ts, unsigned long *ms)
>> +{
>> +	unsigned long res;
>> +
>> +	if (ts.tv_sec + 1 > ULONG_MAX / MSEC_PER_SEC) {
>> +		return -1;
>> +	}
> 
> This is not accurate. It return -1 for the all the following valid timespec:
> 
>   tv_sec = 4294967
>   0 < tv_nsec < 295000000
> 
> You will need to check multiplication and addition separately.

Good point! Changing the check for:

        if (ts.tv_sec + ts.tv_nsec / NSEC_PER_SEC > ULONG_MAX / MSEC_PER_SEC) {
                return -1;
        }

Indeed it appears to be valid to have tv_nsec greater than (1000000000-1)

Thanks,

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list