1
0
mirror of https://github.com/roytam1/UXP.git synced 2026-05-26 13:58:49 +00:00

[NSS] Fix maxSize calculation in NSSUTIL_AddNSSFlagToModuleSpec.

This commit is contained in:
John Schanck
2026-05-25 06:43:53 +02:00
committed by roytam1
parent b3f801743b
commit c36357a954
+22 -1
View File
@@ -913,6 +913,23 @@ NSSUTIL_MkModuleSpec(char *dllName, char *commonName, char *parameters,
return NSSUTIL_MkModuleSpecEx(dllName, commonName, parameters, NSS, NULL);
}
/* Count the number of name=value parameters in a parameter string. */
static size_t
nssutil_CountParams(const char *params)
{
size_t count = 0;
const char *p = params;
while (*p) {
p = NSSUTIL_ArgStrip(p);
if (!*p) {
break;
}
p = NSSUTIL_ArgSkipParameter(p);
count++;
}
return count;
}
/************************************************************************
* add a single flag to the Flags= section inside the spec's NSS= section */
char *
@@ -946,7 +963,11 @@ NSSUTIL_AddNSSFlagToModuleSpec(char *spec, char *addFlag)
} else {
const char *iNss = nss;
PRBool alreadyAdded = PR_FALSE;
size_t maxSize = strlen(nss) + strlen(addFlag) + prefixLen + 2; /* space and null terminator */
// Allocate enough space for the current string, space delimiters
// between all existing parameters, a space before the new flags
// parameter, and a null terminator.
size_t nParams = nssutil_CountParams(nss);
size_t maxSize = strlen(nss) + nParams + strlen(addFlag) + prefixLen + 2;
nss2 = PORT_Alloc(maxSize);
*nss2 = 0;
while (*iNss) {