Skip to content

Commit

Permalink
Merge pull request #287 from os04/master
Browse files Browse the repository at this point in the history
Fix use-after-free when using custom ntp server
  • Loading branch information
arfrie22 authored Jul 24, 2024
2 parents d04f414 + 7fb6d8f commit d2d7828
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion opensprinkler_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,7 @@ void handle_web_request(char *p) {
// othewise, using UDP is much faster for NTP sync
ulong getNtpTime() {
static bool configured = false;
static char customAddress[16];
if(!configured) {
unsigned char ntpip[4] = {
os.iopts[IOPT_NTP_IP1],
Expand All @@ -2297,7 +2298,9 @@ ulong getNtpTime() {
} else {
DEBUG_PRINTLN(F("using custom time server"));
String ntp = IPAddress(ntpip[0],ntpip[1],ntpip[2],ntpip[3]).toString();
configTime(0, 0, ntp.c_str(), "time.google.com", "time.nist.gov");
strncpy(customAddress, ntp.c_str(), sizeof customAddress);
customAddress[sizeof customAddress - 1] = 0;
configTime(0, 0, customAddress, "time.google.com", "time.nist.gov");
}
configured = true;
}
Expand Down

0 comments on commit d2d7828

Please sign in to comment.