From 8c11a4e50df3c31a60500c04fed899e3773e9a17 Mon Sep 17 00:00:00 2001 From: Mandar Gokhale Date: Fri, 5 Oct 2018 06:27:33 +0000 Subject: astraceroute: Fix for reading mirrors from file If the file that GeoIP mirror addresses are being read from lacks a terminating newline, then the code that reads them in exhibits an off-by-one error. Example of such a file: $ xxd /etc/netsniff-ng/geoip.conf 00000000: 6765 6f6c 6974 652e 6d61 786d 696e 642e geolite.maxmind. 00000010: 636f 6d com Fix this by explicitly getting the part of the string before the newline using `strcspn`. Signed-off-by: Mandar Gokhale --- geoip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/geoip.c b/geoip.c index edf1497..4b64778 100644 --- a/geoip.c +++ b/geoip.c @@ -630,8 +630,8 @@ static void init_mirrors(void) memset(buff, 0, sizeof(buff)); while (fgets(buff, sizeof(buff), fp) != NULL && i < array_size(servers)) { - buff[sizeof(buff) - 1] = 0; - buff[strlen(buff) - 1] = 0; + buff[strcspn(buff, "\r\n")] = 0; + buff[strcspn(buff, "\r\n")] = 0; if (buff[0] == '#') { memset(buff, 0, sizeof(buff)); -- cgit v1.2.3-54-g00ecf