Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mentha/55c33e963347a27935f89fce73e64b0d to your computer and use it in GitHub Desktop.
Save mentha/55c33e963347a27935f89fce73e64b0d to your computer and use it in GitHub Desktop.
patch for libvirt-nss 9.3.0, fixing issues where guest names resolving to hosts on other networks when the application prefers ipv6
From 18c1445c291ecab84700f6806ff90b4151586e96 Mon Sep 17 00:00:00 2001
From: Jiang XueQian <[email protected]>
Date: Mon, 10 Jul 2023 15:06:59 +0800
Subject: [PATCH] nss: return success when host is found but no data available
---
tools/nss/libvirt_nss.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c
index ec7763224b..970e65d545 100644
--- a/tools/nss/libvirt_nss.c
+++ b/tools/nss/libvirt_nss.c
@@ -279,16 +279,14 @@ NSS_NAME(gethostbyname3)(const char *name, int af, struct hostent *result,
*errnop = ESRCH;
*herrnop = HOST_NOT_FOUND;
return NSS_STATUS_NOTFOUND;
- } else if (!naddr) {
- /* Found, but no data */
- *errnop = ENXIO;
- *herrnop = NO_DATA;
- return NSS_STATUS_UNAVAIL;
}
/* Found and have data */
- alen = FAMILY_ADDRESS_SIZE(addr[0].af);
+ if (naddr > 0)
+ alen = FAMILY_ADDRESS_SIZE(addr[0].af);
+ else
+ alen = 0;
nameLen = strlen(name);
/* We need space for:
@@ -354,7 +352,8 @@ NSS_NAME(gethostbyname3)(const char *name, int af, struct hostent *result,
ret = NSS_STATUS_SUCCESS;
cleanup:
- free(addr);
+ if (addr)
+ free(addr);
return ret;
}
@@ -389,11 +388,6 @@ NSS_NAME(gethostbyname4)(const char *name, struct gaih_addrtuple **pat,
*errnop = ESRCH;
*herrnop = HOST_NOT_FOUND;
return NSS_STATUS_NOTFOUND;
- } else if (!naddr) {
- /* Found, but no data */
- *errnop = ENXIO;
- *herrnop = NO_DATA;
- return NSS_STATUS_UNAVAIL;
}
/* Found and have data */
@@ -448,7 +442,8 @@ NSS_NAME(gethostbyname4)(const char *name, struct gaih_addrtuple **pat,
*herrnop = NETDB_SUCCESS;
ret = NSS_STATUS_SUCCESS;
cleanup:
- free(addr);
+ if (addr)
+ free(addr);
return ret;
}
#endif /* WITH_STRUCT_GAIH_ADDRTUPLE */
--
2.39.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment