NTPClient icon indicating copy to clipboard operation
NTPClient copied to clipboard

NTP client crashes if you pass an ntp server that the dns does not resolve

Open mr-miky opened this issue 6 years ago • 1 comments
trafficstars

I am using the library with ESP32 and I found that if you put an incorrect ntp server (I assume it happens even if the connection to the internet is absent) the esp 32 restarts. What I found is that in NTPClient :: sendNTPPacket () the packet is sent to the ntp server but it is not checked whether this -> _ udp-> beginPacket (this -> _ poolServerName, 123)) was successful. Even if beginPacket () fails immediately after you try to send the package with the request that causes the reboot.

Since

    // Start building up a packet to send to the remote host specific in host and port
    // Returns 1 if successful, 0 if there was a problem resolving the hostname or port
    virtual int beginPacket(const char *host, uint16_t port) =0;

I'd suggest checking this -> _ udp-> beginPacket (....).

// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
if (this->_udp->beginPacket(this->_poolServerName, 123)) {  //NTP requests are to port 123
	  this->_udp->write(this->_packetBuffer, NTP_PACKET_SIZE);
	  this->_udp->endPacket();
}

mr-miky avatar Aug 08 '19 11:08 mr-miky

I'm using a fork of this library, so my cure dump probably won't make much sense. Does this error show itself in WiFiUDP::endPacket()?

thefatmoop avatar Mar 05 '20 19:03 thefatmoop