From 1d22abcec280a2d5be067c94761034a436ef4230 Mon Sep 17 00:00:00 2001 From: Cykesiopka Date: Mon, 16 May 2016 09:04:09 -0700 Subject: [PATCH] Bug 1271953 - Remove nss_addEscape(). r=mgoodwin The function basically duplicates existing Mozilla string class functionality. MozReview-Commit-ID: 9IFEXuT9cW1 --HG-- extra : rebase_source : 0d0c4492a63f7a168b6092fdb2e1bf8ec09d5308 --- .../certverifier/NSSCertDBTrustDomain.cpp | 42 +++---------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/security/certverifier/NSSCertDBTrustDomain.cpp b/security/certverifier/NSSCertDBTrustDomain.cpp index 37fb25d303c1..04509a3337bd 100644 --- a/security/certverifier/NSSCertDBTrustDomain.cpp +++ b/security/certverifier/NSSCertDBTrustDomain.cpp @@ -959,40 +959,6 @@ NSSCertDBTrustDomain::NetscapeStepUpMatchesServerAuth(Time notBefore, return Result::FATAL_ERROR_LIBRARY_FAILURE; } -namespace { - -static char* -nss_addEscape(const char* string, char quote) -{ - char* newString = 0; - size_t escapes = 0, size = 0; - const char* src; - char* dest; - - for (src = string; *src; src++) { - if ((*src == quote) || (*src == '\\')) { - escapes++; - } - size++; - } - - newString = (char*) PORT_ZAlloc(escapes + size + 1u); - if (!newString) { - return nullptr; - } - - for (src = string, dest = newString; *src; src++, dest++) { - if ((*src == quote) || (*src == '\\')) { - *dest++ = '\\'; - } - *dest = *src; - } - - return newString; -} - -} // unnamed namespace - SECStatus InitializeNSS(const char* dir, bool readOnly, bool loadPKCS11Modules) { @@ -1038,9 +1004,11 @@ LoadLoadableRoots(/*optional*/ const char* dir, const char* modNameUTF8) return SECFailure; } - UniquePORTString escapedFullLibraryPath(nss_addEscape(fullLibraryPath.get(), - '\"')); - if (!escapedFullLibraryPath) { + // Escape the \ and " characters. + nsAutoCString escapedFullLibraryPath(fullLibraryPath.get()); + escapedFullLibraryPath.ReplaceSubstring("\\", "\\\\"); + escapedFullLibraryPath.ReplaceSubstring("\"", "\\\""); + if (escapedFullLibraryPath.IsEmpty()) { return SECFailure; }