Closed TGibsonReach closed 2 years ago
What are you doing? It is not NtpClient's methods.
NtpPacket.cs
contains the inline function which is used when setting several of the packet variables?
void SetDateTime64(int offset, DateTime? value)
{
SetUInt64BE(offset, value == null ? 0 : Convert.ToUInt64((value.Value.Ticks - epoch.Ticks) * (0.0000001 * (1L << 32))));
}
I can confirm that GuerrillaNtp is not Y2038 safe. It needs to implement correct rollover.
This is actually Y2036 bug, not Y2038 bug. I have fixed the library. The fix will be included in 3.0 release that is coming in the next few days.
Passing in a time >= year 2037 to function:
void SetDateTime64(int offset, DateTime? value) { SetUInt64BE(offset, value == null ? 0 : Convert.ToUInt64((value.Value.Ticks - epoch.Ticks) * (0.0000001 * (1L << 32)))); }
causes the conversion to UInt64 to overflow.Test Program:
Output: System.OverflowException: Arithmetic operation resulted in an overflow. at System.Convert.ToUInt64(Double value) at ConsoleApp1.Program.Main(String[] args) in MyProgram