Skip to contentSkip to conversation

statd: make statd_canonical_name return the presentation address if it maps to an empty hostname

PATCH In review Scott Mayhew 2 participants 2 messages Dec 7, 2015 – Dec 12, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 statd: make statd_canonical_name return the presentation address if it maps to an empty hostname

Certain name resolution misconfigurations (for example, a hosts file entry with an ip address but no hostnames) can cause get_nameinfo() to return an empty string in buf, which will lead to this cryptic failure:

Dec  7 09:37:44 hostname rpc.statd[8024]: Failed to insert: creating
/var/lib/nfs/statd/sm/: Is a directory
Dec  7 09:37:44 hostname rpc.statd[8024]: STAT_FAIL to
hostname.example.com for SM_MON of 192.168.1.2
Dec  7 09:37:44 hostname kernel: lockd: cannot monitor 192.168.1.2

It's better in that case to just go ahead and use the presentation address instead.

---
 utils/statd/hostname.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
utils/statd/hostname.c +1 -4
index c61087c..8cccdb8 100644
@@ -180,9 +180,6 @@ get_nameinfo(const struct sockaddr *sap,
  * Incoming hostnames are looked up to determine the canonical hostname,
  * and incoming presentation addresses are converted to canonical
  * hostnames.
- *
- * We won't monitor peers that don't have a reverse map.  The canonical
- * name gives us a key for our monitor list.
  */
 __attribute__((__malloc__))
 char *
@@ -207,7 +204,7 @@ statd_canonical_name(const char *hostname)
 		result = get_nameinfo(ai->ai_addr, ai->ai_addrlen,
 					buf, (socklen_t)sizeof(buf));
 		freeaddrinfo(ai);
-		if (!result)
+		if (!result || buf[0] == '\0')
 			/* OK to use presentation address,
 			 * if no reverse map exists */
 			return strdup(hostname);
Signature · 1 line
2.4.3
#1 lore raw
Quoted 10 lines · Scott Mayhew

Certain name resolution misconfigurations (for example, a hosts file entry with an ip address but no hostnames) can cause get_nameinfo() to return an empty string in buf, which will lead to this cryptic failure:

Dec  7 09:37:44 hostname rpc.statd[8024]: Failed to insert: creating
/var/lib/nfs/statd/sm/: Is a directory
Dec  7 09:37:44 hostname rpc.statd[8024]: STAT_FAIL to
hostname.example.com for SM_MON of 192.168.1.2
Dec  7 09:37:44 hostname kernel: lockd: cannot monitor 192.168.1.2
Quoted 4 lines

It's better in that case to just go ahead and use the presentation address instead.

Committed...

steved.

Quoted 28 lines
---
 utils/statd/hostname.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
utils/statd/hostname.c +1 -4
index c61087c..8cccdb8 100644
@@ -180,9 +180,6 @@ get_nameinfo(const struct sockaddr *sap,
  * Incoming hostnames are looked up to determine the canonical hostname,
  * and incoming presentation addresses are converted to canonical
  * hostnames.
- *
- * We won't monitor peers that don't have a reverse map.  The canonical
- * name gives us a key for our monitor list.
  */
 __attribute__((__malloc__))
 char *
@@ -207,7 +204,7 @@ statd_canonical_name(const char *hostname)
 		result = get_nameinfo(ai->ai_addr, ai->ai_addrlen,
 					buf, (socklen_t)sizeof(buf));
 		freeaddrinfo(ai);
-		if (!result)
+		if (!result || buf[0] == '\0')
 			/* OK to use presentation address,
 			 * if no reverse map exists */
 			return strdup(hostname);