From ab50be5eff078dfe4612ed160ec84fbd16d07f82 Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 23 Jul 2014 21:26:25 +0000 Subject: [PATCH] Make queries using the search list for hostname lookups fail with NO_DATA/EAI_NODATA when the hostname param is an empty string. So far, they were using the entries in the search list with no additional component, which is not really expected. reported by jsing@ and a few others ok deraadt@, "makes sense" jsing@ --- lib/libc/asr/getaddrinfo_async.c | 8 +++++++- lib/libc/asr/gethostnamadr_async.c | 11 +++++++++-- lib/libc/asr/getnetnamadr_async.c | 9 ++++++++- lib/libc/asr/res_search_async.c | 8 +++++++- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/libc/asr/getaddrinfo_async.c b/lib/libc/asr/getaddrinfo_async.c index 94b071ae052..1a4e7330214 100644 --- a/lib/libc/asr/getaddrinfo_async.c +++ b/lib/libc/asr/getaddrinfo_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo_async.c,v 1.28 2014/05/10 21:21:09 chl Exp $ */ +/* $OpenBSD: getaddrinfo_async.c,v 1.29 2014/07/23 21:26:25 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot * @@ -157,6 +157,12 @@ getaddrinfo_async_run(struct asr_query *as, struct asr_result *ar) break; } + if (as->as.ai.hostname && as->as.ai.hostname[0] == '\0') { + ar->ar_gai_errno = EAI_NODATA; + async_set_state(as, ASR_STATE_HALT); + break; + } + ai = &as->as.ai.hints; if (ai->ai_addrlen || diff --git a/lib/libc/asr/gethostnamadr_async.c b/lib/libc/asr/gethostnamadr_async.c index f94d4109a3d..218c055b7e4 100644 --- a/lib/libc/asr/gethostnamadr_async.c +++ b/lib/libc/asr/gethostnamadr_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gethostnamadr_async.c,v 1.29 2014/05/13 11:57:35 eric Exp $ */ +/* $OpenBSD: gethostnamadr_async.c,v 1.30 2014/07/23 21:26:25 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot * @@ -173,8 +173,15 @@ gethostnamadr_async_run(struct asr_query *as, struct asr_result *ar) break; } - /* Name might be an IP address string */ if (as->as_type == ASR_GETHOSTBYNAME) { + + if (as->as.hostnamadr.name[0] == '\0') { + ar->ar_h_errno = NO_DATA; + async_set_state(as, ASR_STATE_HALT); + break; + } + + /* Name might be an IP address string */ for (c = as->as.hostnamadr.name; *c; c++) if (!isdigit((unsigned char)*c) && *c != '.' && *c != ':') diff --git a/lib/libc/asr/getnetnamadr_async.c b/lib/libc/asr/getnetnamadr_async.c index f030ca92997..77f77ccf8bf 100644 --- a/lib/libc/asr/getnetnamadr_async.c +++ b/lib/libc/asr/getnetnamadr_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnetnamadr_async.c,v 1.15 2014/05/13 11:57:35 eric Exp $ */ +/* $OpenBSD: getnetnamadr_async.c,v 1.16 2014/07/23 21:26:25 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot * @@ -125,6 +125,13 @@ getnetnamadr_async_run(struct asr_query *as, struct asr_result *ar) break; } + if (as->as_type == ASR_GETNETBYNAME && + as->as.netnamadr.name[0] == '\0') { + ar->ar_h_errno = NO_DATA; + async_set_state(as, ASR_STATE_HALT); + break; + } + async_set_state(as, ASR_STATE_NEXT_DB); break; diff --git a/lib/libc/asr/res_search_async.c b/lib/libc/asr/res_search_async.c index d040655bc28..38c32126b4d 100644 --- a/lib/libc/asr/res_search_async.c +++ b/lib/libc/asr/res_search_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_search_async.c,v 1.13 2014/03/26 18:13:15 eric Exp $ */ +/* $OpenBSD: res_search_async.c,v 1.14 2014/07/23 21:26:25 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot * @@ -94,6 +94,12 @@ res_search_async_run(struct asr_query *as, struct asr_result *ar) case ASR_STATE_INIT: + if (as->as.search.name[0] == '\0') { + ar->ar_h_errno = NO_DATA; + async_set_state(as, ASR_STATE_HALT); + break; + } + as->as.search.saved_h_errno = HERRNO_UNSET; async_set_state(as, ASR_STATE_NEXT_DOMAIN); break; -- 2.20.1