From dd9c4607533ed24bccb50988adbf5c1c28ae5d4a Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Tue, 9 Mar 2021 19:19:20 -0800
Subject: [PATCH] De-duplicate the lists returned by iniGet/ReadSectionList()

I noticed a duplicate area name (AGN_MODS) in a filefix %LIST response
from my FidoNet hub that's running TickIt/TickFix, and I thought to myself:
Self, that shouldn't be possible. But alas, if one does have duplicate
sections in a .ini file (e.g. tickit.ini), the iniGet/ReadSectionList()
function would indeed return duplicate items in the list. Since the second
section with the same name is not actually accessible, it shouldn't be counted
as a valid section and thus not returned as part of the section list. Section
names are not case sensitive, so the names are compared case-insensitively for
de-duplication purposes too.
---
 src/xpdev/ini_file.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c
index a7d62c6478..b347d72cba 100644
--- a/src/xpdev/ini_file.c
+++ b/src/xpdev/ini_file.c
@@ -1086,6 +1086,8 @@ str_list_t iniReadSectionList(FILE* fp, const char* prefix)
 		if(prefix!=NULL)
 			if(strnicmp(p,prefix,strlen(prefix))!=0)
 				continue;
+		if(strListFind(lp, p, /* case_sensitive */FALSE) >= 0)
+			continue;
 		if(strListAppend(&lp,p,items++)==NULL)
 			break;
 	}
@@ -1115,6 +1117,8 @@ str_list_t iniGetSectionList(str_list_t list, const char* prefix)
 		if(prefix!=NULL)
 			if(strnicmp(p,prefix,strlen(prefix))!=0)
 				continue;
+		if(strListFind(lp, p, /* case_sensitive */FALSE) >= 0)
+			continue;
 		if(strListAppend(&lp,p,items++)==NULL)
 			break;
 	}
-- 
GitLab