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

Fix use-after-free when using custom ntp server #287

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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