Hi,

Sorry for being late to respond.

On 18-10-17 20:36, Jeremie Courreges-Anglas wrote:
> - there are other places when a time_t is printed in openvpn.  Usually
>   it is cast to (int), which is not a nice thing to do if you plan to
>   support dates after 2038.
> 
>   I also stumbled upon this in src/openvpn/common.h
> 
>   /*
>    * Printf formats for special types
>    */
>   #ifdef _WIN64
>   #define ptr_format              "0x%I64x"
>   #else
>   #define ptr_format              "0x%08lx"
>   #endif
>   #define time_format             "%lu"
>   #define fragment_header_format  "0x%08x"
>   
>   /* these are used to cast the arguments
>    * and MUST match the formats above */
>   typedef unsigned long time_type;
>   #ifdef _WIN64
>   typedef unsigned long long ptr_type;
>   #else
>   typedef unsigned long ptr_type;
>   #endif
> 
>   time_format and time_type are indeed used in a few places where
>   a time_t is printed.  Technically, "unsigned long" suffers from the
>   same problem as "long" on platforms with a 32 bits "long", pushing the
>   limit to 2106 instead of 2038.
> 
>   I would suggest using "long long" here too, but do you folks think
>   that the whole "time_format/time_type" indirection makes sense?
>   After all, those are currently the same on all platforms.
> 
>   I have a diff to fix places in src/openvpn where time_t variables are
>   cast to (int), but it kinda depends on the approach you folks prefer
>   to use.

Not sure about the other devs, but I think we should get rid of this
indirection.  Someone who forgets to cast to long long will likely also
not use the time_format define.  Better be consistent in casting to long
long and printing using %lld (which is obviously correct for a long
long).  Patch is definitely welcome.

>>> While we are at it, note that tv.tv_usec, per POSIX, is a SIGNED integer
>>> type capable of representing numbers in the range [-1; 1,000,000] so
>>> casting tv_usec to unsigned long without checking if it's -1 is
>>> technically wrong, although I'd be surprised to see gettimeofday()
>>> return a negative tv_usec - but UINT_MAX or ULONG_MAX likewise.
>>
>> It makes sense to respect the fact that suseconds_t can store a negative
>> value.  But then the same can be said about time_t (since its signedness
>> is not defined by posix).
> 
> I guess it makes sense to also choose a generic way to print
> suseconds_t, whose size isn't defined by posix either, and deal with
> both types at once.  I would suggest using %ld and a cast to (long), as
> this is the underlying type on at least OpenBSD and Linux.

Sounds good to me.

-Steffan

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to