Skip to contentSkip to conversation

tlshd_handshake_parms: Use an empty string, instead of "unknown", for the default value of peername.

PATCH In review Ken Milmore 2 participants 2 messages Jun 8, 2025 Handshake upcall for transport layer security

lore
Share & tools
lore
#0 lore raw

PATCH 3/7 tlshd_handshake_parms: Use an empty string, instead of "unknown", for the default value of peername.

"unknown" could conceivably be a valid hostname.

---
 src/tlshd/log.c     | 6 +++++-
 src/tlshd/netlink.c | 3 ++-
 2 files changed, 7 insertions(+), 2 deletions(-)
src/tlshd/log.c +5 -1
index 3594d52..77e2d29 100644
@@ -57,7 +57,9 @@ void tlshd_log_success(const char *hostname, const struct sockaddr *sap,
 	char buf[NI_MAXHOST];
 
 	getnameinfo(sap, salen, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
-	syslog(LOG_INFO, "Handshake with %s (%s) was successful\n",
+	if (hostname[0] == '\0')
+		hostname = "<unknown>";
+	syslog(LOG_INFO, "Handshake with '%s' (%s) was successful\n",
 		hostname, buf);
 }
 
@@ -75,6 +77,8 @@ void tlshd_log_failure(const char *hostname, const struct sockaddr *sap,
 		char buf[NI_MAXHOST];
 
 		getnameinfo(sap, salen, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
+		if (hostname[0] == '\0')
+			hostname = "<unknown>";
 		syslog(LOG_ERR, "Handshake with '%s' (%s) failed\n",
 		       hostname, buf);
 	} else
src/tlshd/netlink.c +2 -1
index ce8e981..0f4a797 100644
@@ -223,7 +223,7 @@ static void tlshd_parse_certificate(struct tlshd_handshake_parms *parms,
 		parms->x509_privkey = nla_get_s32(tb[HANDSHAKE_A_X509_PRIVKEY]);
 }
 
-static char tlshd_peername[NI_MAXHOST] = "unknown";
+static char tlshd_peername[NI_MAXHOST] = "";
 static struct sockaddr_storage tlshd_peeraddr = { 0 };
 
 static int tlshd_genl_valid_handler(struct nl_msg *msg, void *arg)
@@ -289,6 +289,7 @@ static int tlshd_genl_valid_handler(struct nl_msg *msg, void *arg)
 				  NULL, 0, NI_NAMEREQD);
 		if (err) {
 			tlshd_log_gai_error(err);
+			tlshd_peername[0] = '\0';
 			return NL_STOP;
 		}
 	}
Signature · 1 line
2.47.2
#1 lore raw
Quoted 1 line · Ken Milmore

"unknown" could conceivably be a valid hostname.

If that is the only problem, then a one-line patch changing the initial value of tlshd_peername to "<unknown>" should be sufficient.

Quoted 51 lines
---
 src/tlshd/log.c     | 6 +++++-
 src/tlshd/netlink.c | 3 ++-
 2 files changed, 7 insertions(+), 2 deletions(-)
src/tlshd/log.c +5 -1
index 3594d52..77e2d29 100644
@@ -57,7 +57,9 @@ void tlshd_log_success(const char *hostname, const struct sockaddr *sap,
 	char buf[NI_MAXHOST];
 
 	getnameinfo(sap, salen, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
-	syslog(LOG_INFO, "Handshake with %s (%s) was successful\n",
+	if (hostname[0] == '\0')
+		hostname = "<unknown>";
+	syslog(LOG_INFO, "Handshake with '%s' (%s) was successful\n",
 		hostname, buf);
 }
 
@@ -75,6 +77,8 @@ void tlshd_log_failure(const char *hostname, const struct sockaddr *sap,
 		char buf[NI_MAXHOST];
 
 		getnameinfo(sap, salen, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
+		if (hostname[0] == '\0')
+			hostname = "<unknown>";
 		syslog(LOG_ERR, "Handshake with '%s' (%s) failed\n",
 		       hostname, buf);
 	} else
src/tlshd/netlink.c +2 -1
index ce8e981..0f4a797 100644
@@ -223,7 +223,7 @@ static void tlshd_parse_certificate(struct tlshd_handshake_parms *parms,
 		parms->x509_privkey = nla_get_s32(tb[HANDSHAKE_A_X509_PRIVKEY]);
 }
 
-static char tlshd_peername[NI_MAXHOST] = "unknown";
+static char tlshd_peername[NI_MAXHOST] = "";
 static struct sockaddr_storage tlshd_peeraddr = { 0 };
 
 static int tlshd_genl_valid_handler(struct nl_msg *msg, void *arg)
@@ -289,6 +289,7 @@ static int tlshd_genl_valid_handler(struct nl_msg *msg, void *arg)
 				  NULL, 0, NI_NAMEREQD);
 		if (err) {
 			tlshd_log_gai_error(err);
+			tlshd_peername[0] = '\0';
 			return NL_STOP;
 		}
 	}
Signature · 1 line
Chuck Lever