[nsd-users] NSD 4.9.0rc1 pre-release

Florian Obser florian at openbsd.org
Mon Apr 1 17:44:42 UTC 2024


Hi,

over at OpenBSD we are not too fond of strcat/strcpy to put it mildly.

I hope this is acceptable.

Sorry for the inline patch, I no longer use GitHub,
Florian

>From b61c840c7f30b9e56a0da2fd6e30a836efcd5a9c Mon Sep 17 00:00:00 2001
From: Florian Obser <florian at narrans.de>
Date: Mon, 1 Apr 2024 19:39:55 +0200
Subject: [PATCH] snprintf concatenates strings and checks the length in one
 go.

This is safer and easier to understand.
---
 options.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git options.c options.c
index 1cfeeb94..75b8e183 100644
--- options.c
+++ options.c
@@ -463,14 +463,13 @@ zone_list_member_zone_insert(struct nsd_options* opt, const char* nm,
 			"zone value provided in zone '%s' or pattern '%s'",
 			mem_idnm, nm, patnm);
 
-	else if(strlen(pat->catalog_producer_zone)
-	      + strlen(mem_idnm) + 9 > sizeof(member_id_str))
+	else if(snprintf(member_id_str, sizeof(member_id_str),
+	    "%s.zones.%s", mem_idnm, pat->catalog_producer_zone) >=
+	    sizeof(member_id_str))
 		log_msg(LOG_ERR, "syntax error in member ID '%s.zones.%s' for "
 			"zone '%s'", mem_idnm, pat->catalog_producer_zone, nm);
 
-	else if(!(cmz->member_id = dname_parse(opt->region, strcat(strcat(
-				strcpy(member_id_str, mem_idnm),".zones."),
-					pat->catalog_producer_zone))))
+	else if(!(cmz->member_id = dname_parse(opt->region, member_id_str)))
 		log_msg(LOG_ERR, "parse error in member ID '%s' for "
 			"zone '%s'", member_id_str, nm);
 	return zone;
-- 
2.44.0




-- 
In my defence, I have been left unsupervised.


More information about the nsd-users mailing list