From 437d0850ff5e9cf554cfb2790235e5c0b30f94b3 Mon Sep 17 00:00:00 2001 From: pyr <> Date: Thu, 4 Jun 2009 21:38:29 +0000 Subject: simplify the 'family' option parser and make it more evident what we're now doing. ok deraadt@ --- src/lib/libc/net/res_init.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/lib/libc/net/res_init.c') diff --git a/src/lib/libc/net/res_init.c b/src/lib/libc/net/res_init.c index 5cb597dad8..aafa9bbc87 100644 --- a/src/lib/libc/net/res_init.c +++ b/src/lib/libc/net/res_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_init.c,v 1.38 2009/06/04 18:06:35 pyr Exp $ */ +/* $OpenBSD: res_init.c,v 1.39 2009/06/04 21:38:29 pyr Exp $ */ /* * ++Copyright++ 1985, 1989, 1993 @@ -281,6 +281,9 @@ _res_init(int usercall) (line[sizeof(name) - 1] == ' ' || \ line[sizeof(name) - 1] == '\t')) + /* initialize family lookup preference: inet4 first */ + _resp->family[0] = AF_INET; + _resp->family[1] = AF_INET6; if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { strlcpy(_resp->lookups, "bf", sizeof _resp->lookups); @@ -312,6 +315,9 @@ _res_init(int usercall) strlen("inet4"))) { _resp->family[findex] = AF_INET; cp += strlen("inet4"); + } else { + _resp->family[0] = -1; + break; } if (*cp != ' ' && *cp != '\t' && *cp != '\0') { _resp->family[findex] = -1; @@ -321,6 +327,11 @@ _res_init(int usercall) cp += strspn(cp, " \t"); } + if (_resp->family[0] == -1) { + /* line contains errors, reset to defaults */ + _resp->family[0] = AF_INET; + _resp->family[1] = AF_INET6; + } if (_resp->family[0] == _resp->family[1]) _resp->family[1] = -1; } -- cgit v1.2.3-55-g6feb