From b24fc42ec875246820fc191e1d4e40e1231548d7 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Mon, 22 Apr 2013 22:28:49 +0100 Subject: [PATCH] getdata: make a lease address detection more robust The commit 805d353584a74e874df3f077dbe1d6239bb50d3f did not fix all possible problem cases. This commit attempts to address remaining issues. Reported-by: Joey D. Signed-off-by: Sami Kerola --- src/other.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/other.c b/src/other.c index fbdb3c0..45229cf 100644 --- a/src/other.c +++ b/src/other.c @@ -40,6 +40,7 @@ #include #include "dhcpd-pools.h" +#include "defaults.h" #include #include @@ -160,10 +161,20 @@ int xstrstr(const char *restrict a, const char *restrict b, const int len) { int i; - /* Skip when config.dhcp_version == VERSION_UNKNOWN -> len is zero. */ - if (len == 0) { + + /* Needed when dhcpd.conf has zero range definitions. */ + if (config.dhcp_version == VERSION_UNKNOWN) { + if (!strcmp(prefixes[VERSION_4][PREFIX_LEASE], a)) { + config.dhcp_version = VERSION_4; + return true; + } + if (!strcmp(prefixes[VERSION_6][PREFIX_LEASE], a)) { + config.dhcp_version = VERSION_6; + return true; + } return false; } + /* two spaces are very common in lease file, after them * nearly everything differs */ if (likely(a[2] != b[2])) {