Commits

Anonymous committed 9e6f709

tkr38: fixed broken error text print out if nss init fails (PR_GetErrorText doesn't allow NULL parameter)

Comments (0)

Files changed (1)

xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx

     }
 }
 
+namespace{
+	void getAndPrintPRErrorText()
+	{
+		char error[1024] = "Cannot get error text from function PR_GetErrorText().";
+		PRInt32 size = PR_GetErrorTextLength();
+		if (size < (int) sizeof(error))
+		{
+			PR_GetErrorText(error);
+		}
+		xmlsec_trace("%s",error);   
+	}
+}
+
 //Older versions of Firefox (FF), for example FF2, and Thunderbird (TB) 2 write
 //the roots certificate module (libnssckbi.so), which they use, into the
 //profile. This module will then already be loaded during NSS_Init (and the
         if( NSS_InitReadWrite( token ) != SECSuccess )
         {
             xmlsec_trace("Initializing NSS with profile failed.");
-            char * error = NULL;
-            
-            PR_GetErrorText(error);
-            if (error)
-                xmlsec_trace("%s",error);
+            getAndPrintPRErrorText();
             return false ;
         }
     }
         if ( NSS_NoDB_Init(NULL) != SECSuccess )
         {
             xmlsec_trace("Initializing NSS without profile failed.");
-            char * error = NULL;
-            PR_GetErrorText(error);
-            if (error)
-                xmlsec_trace("%s",error);
+            getAndPrintPRErrorText();
             return false ;
         }
     }
     return return_value;
 }
 
-
 // must be extern "C" because we pass the function pointer to atexit
 extern "C" void nsscrypto_finalize()
 {
             rtl::OUString ouCertDir;
 
 
-
             if ( getMozillaCurrentProfile(mxMSF, ouCertDir) )
                 *pDefaultCertDir = rtl::OString(ouCertDir, ouCertDir.getLength(), RTL_TEXTENCODING_ASCII_US);
         }
         sCertDir = *pDefaultCertDir;
         
     }
-
     if( ! *initNSS( sCertDir.getStr() ) )
     {
         return NULL;
     }
-
     pCertHandle = CERT_GetDefaultCertDB() ;
 
     try 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.