getdata: make a lease address detection more robust

The commit 805d353584 did not fix all
possible problem cases.  This commit attempts to address remaining
issues.

Reported-by: Joey D. <jobewan@gmail.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2013-04-22 22:28:49 +01:00
parent 1a7649beb3
commit b24fc42ec8

View file

@ -40,6 +40,7 @@
#include <config.h> #include <config.h>
#include "dhcpd-pools.h" #include "dhcpd-pools.h"
#include "defaults.h"
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
@ -160,10 +161,20 @@ int
xstrstr(const char *restrict a, const char *restrict b, const int len) xstrstr(const char *restrict a, const char *restrict b, const int len)
{ {
int i; 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; return false;
} }
/* two spaces are very common in lease file, after them /* two spaces are very common in lease file, after them
* nearly everything differs */ * nearly everything differs */
if (likely(a[2] != b[2])) { if (likely(a[2] != b[2])) {