Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getNtpTime() doesn't handle zero from NTP server response #174

Open
Anton-V-K opened this issue Nov 9, 2022 · 1 comment
Open

getNtpTime() doesn't handle zero from NTP server response #174

Anton-V-K opened this issue Nov 9, 2022 · 1 comment

Comments

@Anton-V-K
Copy link

The code of getNtpTime() in https://github.com/PaulStoffregen/Time/blob/master/examples/TimeNTP/TimeNTP.ino doesn't check the correctness of UDP packet's content (obtained from NTP server), and can potentially set invalid date (in future - 07-Feb-2036).
I'm referring to this code fragment:

if (size >= NTP_PACKET_SIZE) {
      Serial.println("Receive NTP Response");
      Udp.read(packetBuffer, NTP_PACKET_SIZE);  // read packet into the buffer
      unsigned long secsSince1900;
      // convert four bytes starting at location 40 to a long integer
      secsSince1900 =  (unsigned long)packetBuffer[40] << 24;
      secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
      secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
      secsSince1900 |= (unsigned long)packetBuffer[43];
      return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
}

Here secsSince1900 can be zero, when in certain cases ( like "rate limiting" - mentioned in arduino-libraries/NTPClient#84 ) NTP responds with zero time.

@gednz
Copy link

gednz commented Jan 12, 2024

I am having this issue too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants