Skip to content

Commit

Permalink
nwrap: correctly track EAI_ADDRINFO in nwrap_files_getaddrinfo
Browse files Browse the repository at this point in the history
When looping through the entry list and remember the
EAI_ADDRINFO case, so that we can differentiate
the cases
- no entry found at all
- an entry found buy wrong address type

Adapt return codes accordingly.

Signed-off-by: Michael Adam <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
  • Loading branch information
obnoxxx committed Jan 11, 2016
1 parent 0dc34ea commit 154080c
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib/nss_wrapper/nss_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -3562,6 +3562,7 @@ static int nwrap_files_getaddrinfo(const char *name,
bool skip_canonname = false;
ENTRY e = { 0 };
ENTRY *e_p = NULL;
int rc;
bool ok;

ok = nwrap_files_cache_reload(nwrap_he_global.cache);
Expand Down Expand Up @@ -3595,27 +3596,32 @@ static int nwrap_files_getaddrinfo(const char *name,
NWRAP_LOG(NWRAP_LOG_DEBUG, "Name: %s found.", h_name_lower);
SAFE_FREE(h_name_lower);

rc = EAI_NONAME;
for (el = (struct nwrap_entlist *)e_p->data; el != NULL; el = el->next)
{
int rc;
int rc2;

he = &(el->ed->ht);

if (hints->ai_family != AF_UNSPEC &&
he->h_addrtype != hints->ai_family) {
he->h_addrtype != hints->ai_family)
{
NWRAP_LOG(NWRAP_LOG_DEBUG,
"Entry found but with wrong AF - "
"remembering EAI_ADDRINFO.");
rc = EAI_ADDRFAMILY;
continue;
}

/* Function allocates memory and returns it in ai. */
rc = nwrap_convert_he_ai(he,
rc2 = nwrap_convert_he_ai(he,
port,
hints,
&_ai,
skip_canonname);
if (rc != 0) {
NWRAP_LOG(NWRAP_LOG_ERROR,
"Error in converting he to ai! Skipping.");
return rc;
if (rc2 != 0) {
NWRAP_LOG(NWRAP_LOG_ERROR, "Error converting he to ai");
return rc2;
}
skip_canonname = true;

Expand All @@ -3628,9 +3634,14 @@ static int nwrap_files_getaddrinfo(const char *name,
ai_prev = _ai;
}

if (ai_head != NULL) {
rc = 0;
}

*ai = ai_head;
*ai_tail = _ai;
return 0;

return rc;
}

static struct hostent *nwrap_files_gethostbyaddr(const void *addr,
Expand Down

0 comments on commit 154080c

Please sign in to comment.