twekkel / htpdate

HTTP Time protocol
https://www.vervest.org/htp
Other
50 stars 13 forks source link

double free detected in tcache 2 error #18

Closed seanpmaddox closed 2 years ago

seanpmaddox commented 2 years ago

In getHTTPdate() if the call to getaddrinfo() returns a nonzero error code the freeaddrinfo(res) that follows results in a 'free(): double free detected in tcache 2' error which crashes htpdate when in daemon mode.

Looking at the getaddrinfo programming info at https://man7.org/linux/man-pages/man3/getaddrinfo.3.html and the example code there freeaddrinfo() is not called if the call to getaddrinfo() returns a nonzero error code. I've commented out the freeaddrinfo(res) in getHTTPdate(), recompiled and can confirm this resolves the fatal error/crash.

I'm compiling with https support, running in daemon mode and using https://www.google.com, https://firebase.google.com, https://azure.microsoft.com & https://aws.amazon.com as the time sources. Occasionally the call to getaddrinfo() for one of these will return a nonzero error code (not clear yet as to why) and this was killing the htpdate service. I am running htpdate as a service under systemd, full Exec_Startup;

path=/usr/sbin/htpdate ; argv[]=/usr/sbin/htpdate -F -4 -a -l -s -t -d https://www.google.com https://firebase.google.com https://azure.microsoft.com https://aws.amazon.com ; ignore_errors=no

twekkel commented 2 years ago

Yep it is a bug, thanks for finding and reporting. Fixed in https://github.com/twekkel/htpdate/commit/c9410e052644a6089523bd37140a9e41e29d8682

twekkel commented 2 years ago

fix included in version 1.3.4

seanpmaddox commented 2 years ago

Much appreciated, thank you and thanks for the package and maintaining it