[monitoring-plugins] parse_ini: correct string length

Lorenz Kästle git at monitoring-plugins.org
Fri Jan 9 14:20:13 CET 2026


 Module: monitoring-plugins
 Branch: master
 Commit: db0349ae13af260687347064b71127e53b03b0b0
 Author: Lorenz Kästle <12514511+RincewindsHat at users.noreply.github.com>
   Date: Fri Jan  9 14:03:32 2026 +0100
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=db0349ae

parse_ini: correct string length

---

 lib/parse_ini.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/parse_ini.c b/lib/parse_ini.c
index db337622..196cac79 100644
--- a/lib/parse_ini.c
+++ b/lib/parse_ini.c
@@ -352,15 +352,17 @@ static int add_option(FILE *filePointer, np_arg_list **optlst) {
 	optnew->next = NULL;
 
 	read_pos = 0;
-	optnew->arg = malloc(cfg_len + 1);
+	size_t arg_length = cfg_len + 1;
+	optnew->arg = malloc(arg_length);
 	/* 1-character params needs only one dash */
 	if (opt_len == 1) {
-		strncpy(&optnew->arg[read_pos], "-", 1);
+		strncpy(&optnew->arg[read_pos], "-", arg_length);
 		read_pos += 1;
 	} else {
-		strncpy(&optnew->arg[read_pos], "--", 2);
+		strncpy(&optnew->arg[read_pos], "--", arg_length);
 		read_pos += 2;
 	}
+
 	strncpy(&optnew->arg[read_pos], optptr, opt_len);
 	read_pos += opt_len;
 	if (value) {



More information about the Commits mailing list