bug 1197314: Remove PR_snprintf calls in security/manager/ssl/ r=keeler
authorAniket Vyas <vyas45@gmail.com>
Fri, 26 Feb 2016 15:31:43 -0800
changeset 322692 fc43503ff50b2f41b53db0c905a226f14c54df27
parent 322691 e4d6131af17154b3ae92cc185a950d9443f78809
child 322693 145c9bb59b97c62d5e14e4613c6383c68223069e
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskeeler
bugs1197314
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1197314: Remove PR_snprintf calls in security/manager/ssl/ r=keeler MozReview-Commit-ID: Kq5kWzC1UHU
security/manager/ssl/nsNSSCertHelper.cpp
security/manager/ssl/nsNTLMAuthModule.cpp
security/manager/ssl/tests/gtest/OCSPCacheTest.cpp
security/manager/ssl/tests/unit/tlsserver/lib/TLSServer.cpp
--- a/security/manager/ssl/nsNSSCertHelper.cpp
+++ b/security/manager/ssl/nsNSSCertHelper.cpp
@@ -1,29 +1,29 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsNSSCertHelper.h"
 
 #include <algorithm>
 
+#include "mozilla/Snprintf.h"
 #include "mozilla/UniquePtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsCOMPtr.h"
 #include "nsDateTimeFormatCID.h"
 #include "nsIDateTimeFormat.h"
 #include "nsNSSASN1Object.h"
 #include "nsNSSCertificate.h"
 #include "nsNSSCertTrust.h"
 #include "nsNSSCertValidity.h"
 #include "nsNSSComponent.h"
 #include "nsServiceManagerUtils.h"
 #include "prerror.h"
-#include "prprf.h"
 #include "ScopedNSSTypes.h"
 #include "secder.h"
 
 using namespace mozilla;
  
 /* Object Identifier constants */
 #define CONST_OID static const unsigned char
 #define MICROSOFT_OID 0x2b, 0x6, 0x1, 0x4, 0x1, 0x82, 0x37
@@ -205,36 +205,35 @@ GetDefaultOIDFormat(SECItem *oid,
         continue;
     }
 
     if (!invalid) {
       if (first) {
         unsigned long one = std::min(val/40, 2UL); // never > 2
         unsigned long two = val - (one * 40);
 
-        written = PR_snprintf(&buf[len], sizeof(buf)-len, "%lu%c%lu", 
-			      one, separator, two);
+        written = snprintf(&buf[len], sizeof(buf) - len, "%lu%c%lu",
+                           one, separator, two);
       }
       else {
-        written = PR_snprintf(&buf[len], sizeof(buf)-len, "%c%lu", 
-			      separator, val);
+        written = snprintf(&buf[len], sizeof(buf) - len, "%c%lu",
+                           separator, val);
       }
     }
     else {
       nsAutoString unknownText;
       nssComponent->GetPIPNSSBundleString("CertUnknown", 
                                           unknownText);
       if (first) {
-        written = PR_snprintf(&buf[len], sizeof(buf)-len, "%s",
-                              NS_ConvertUTF16toUTF8(unknownText).get());
+        written = snprintf(&buf[len], sizeof(buf) - len, "%s",
+                           NS_ConvertUTF16toUTF8(unknownText).get());
       }
       else {
-        written = PR_snprintf(&buf[len], sizeof(buf)-len, "%c%s",
-                              separator, 
-                              NS_ConvertUTF16toUTF8(unknownText).get());
+        written = snprintf(&buf[len], sizeof(buf) - len, "%c%s",
+                           separator, NS_ConvertUTF16toUTF8(unknownText).get());
       }
 
       if (++invalidCount > 3) {
         // Allow only 3 occurences of Unknown in OID display string to
         // prevent bloat.
         break;
       }
     }
@@ -637,17 +636,17 @@ ProcessRawBytes(nsINSSComponent *nssComp
   // This prints the value of the byte out into a 
   // string that can later be displayed as a byte
   // string.  We place a new line after 24 bytes
   // to break up extermaly long sequence of bytes.
 
   uint32_t i;
   char buffer[5];
   for (i=0; i<data->len; i++) {
-    PR_snprintf(buffer, 5, "%02x ", data->data[i]);
+    snprintf_literal(buffer, "%02x ", data->data[i]);
     AppendASCIItoUTF16(buffer, text);
     if ((i+1)%16 == 0) {
       text.AppendLiteral(SEPARATOR);
     }
   }
   return NS_OK;
 }    
 
@@ -974,20 +973,20 @@ ProcessGeneralName(const UniquePLArenaPo
 	SECItem guid;
 	nssComponent->GetPIPNSSBundleString("CertDumpMSDomainGUID", key);
         if (SEC_ASN1DecodeItem(arena.get(), &guid,
 			       SEC_ASN1_GET(SEC_OctetStringTemplate),
 			       &current->name.OthName.name) == SECSuccess
 	    && guid.len == 16) {
 	  char buf[40];
 	  unsigned char *d = guid.data;
-	  PR_snprintf(buf, sizeof(buf), 
-		      "{%.2x%.2x%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x}",
-		      d[3], d[2], d[1], d[0], d[5], d[4], d[7], d[6],
-		      d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
+          snprintf_literal(buf,
+            "{%.2x%.2x%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x}",
+            d[3], d[2], d[1], d[0], d[5], d[4], d[7], d[6],
+            d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
 	  value.AssignASCII(buf);
 	} else {
 	  ProcessRawBytes(nssComponent, &current->name.OthName.name, value);
 	}
     } else {
       rv = GetDefaultOIDFormat(&current->name.OthName.oid, nssComponent, key, ' ');
       if (NS_FAILED(rv)) {
         return rv;
@@ -1202,17 +1201,17 @@ ProcessUserNotice(SECItem* derNotice, ns
       break;
     }
     text.AppendLiteral(" - ");
     SECItem** itemList = notice->noticeReference.noticeNumbers;
     while (*itemList) {
       unsigned long number;
       char buffer[60];
       if (SEC_ASN1DecodeInteger(*itemList, &number) == SECSuccess) {
-        PR_snprintf(buffer, sizeof(buffer), "#%d", number);
+        snprintf_literal(buffer, "#%d", number);
         if (itemList != notice->noticeReference.noticeNumbers)
           text.AppendLiteral(", ");
         AppendASCIItoUTF16(buffer, text);
       }
       itemList++;
     }
   }
   if (notice->displayText.len != 0) {
@@ -1492,17 +1491,17 @@ ProcessMSCAVersion(SECItem  *extData,
 
   rv = GetIntValue(&decoded, &version);
   free(decoded.data);
   if (NS_FAILED(rv))
     /* Value out of range, display raw bytes */
     return ProcessRawBytes(nssComponent, extData, text);
 
   /* Apparently, the encoding is <minor><major>, with 16 bits each */
-  PR_snprintf(buf, sizeof(buf), "%d.%d", version & 0xFFFF, version>>16);
+  snprintf_literal(buf, "%d.%d", version & 0xFFFF, version >> 16);
   text.AppendASCII(buf);
   return NS_OK;
 }
 
 static nsresult
 ProcessExtensionData(SECOidTag oidTag, SECItem *extData, 
                      nsAString &text, 
                      SECOidTag ev_oid_tag, // SEC_OID_UNKNOWN means: not EV
--- a/security/manager/ssl/nsNTLMAuthModule.cpp
+++ b/security/manager/ssl/nsNTLMAuthModule.cpp
@@ -7,16 +7,17 @@
 
 #include <time.h>
 
 #include "md4.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/Endian.h"
 #include "mozilla/Likely.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/Snprintf.h"
 #include "mozilla/Telemetry.h"
 #include "nsCOMPtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsICryptoHash.h"
 #include "nsICryptoHMAC.h"
 #include "nsIKeyModule.h"
 #include "nsKeyModule.h"
 #include "nsNativeCharsetUtils.h"
@@ -183,33 +184,33 @@ LogBuf(const char *tag, const uint8_t *b
     int count = bufLen;
     if (count > 8)
       count = 8;
 
     strcpy(line, "    ");
     for (i=0; i<count; ++i)
     {
       int len = strlen(line);
-      PR_snprintf(line + len, sizeof(line) - len, "0x%02x ", int(buf[i]));
+      snprintf(line + len, sizeof(line) - len, "0x%02x ", int(buf[i]));
     }
     for (; i<8; ++i)
     {
       int len = strlen(line);
-      PR_snprintf(line + len, sizeof(line) - len, "     ");
+      snprintf(line + len, sizeof(line) - len, "     ");
     }
 
     int len = strlen(line);
-    PR_snprintf(line + len, sizeof(line) - len, "   ");
+    snprintf(line + len, sizeof(line) - len, "   ");
     for (i=0; i<count; ++i)
     {
       len = strlen(line);
       if (isprint(buf[i]))
-        PR_snprintf(line + len, sizeof(line) - len, "%c", buf[i]);
+        snprintf(line + len, sizeof(line) - len, "%c", buf[i]);
       else
-        PR_snprintf(line + len, sizeof(line) - len, ".");
+        snprintf(line + len, sizeof(line) - len, ".");
     }
     PR_LogPrint("%s\n", line);
 
     bufLen -= count;
     buf += count;
   }
 }
 
--- a/security/manager/ssl/tests/gtest/OCSPCacheTest.cpp
+++ b/security/manager/ssl/tests/gtest/OCSPCacheTest.cpp
@@ -2,21 +2,21 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "CertVerifier.h"
 #include "OCSPCache.h"
 #include "gtest/gtest.h"
+#include "mozilla/Snprintf.h"
 #include "nss.h"
 #include "pkix/pkixtypes.h"
 #include "pkixtestutil.h"
 #include "prerr.h"
-#include "prprf.h"
 #include "secerr.h"
 
 using namespace mozilla::pkix;
 using namespace mozilla::pkix::test;
 using namespace mozilla::psm;
 
 template <size_t N>
 inline Input
@@ -80,17 +80,17 @@ TEST_F(OCSPCacheTest, TestPutAndGet)
                          resultOut, timeOut));
 }
 
 TEST_F(OCSPCacheTest, TestVariousGets)
 {
   SCOPED_TRACE("");
   for (int i = 0; i < MaxCacheEntries; i++) {
     uint8_t serialBuf[8];
-    PR_snprintf(reinterpret_cast<char*>(serialBuf), sizeof(serialBuf), "%04d", i);
+    snprintf(reinterpret_cast<char*>(serialBuf), sizeof(serialBuf), "%04d", i);
     Input fakeSerial;
     ASSERT_EQ(Success, fakeSerial.Init(serialBuf, 4));
     Time timeIn(now);
     ASSERT_EQ(Success, timeIn.AddSeconds(i));
     PutAndGet(cache, CertID(fakeIssuer1, fakeKey000, fakeSerial),
               Success, timeIn);
   }
 
@@ -129,17 +129,17 @@ TEST_F(OCSPCacheTest, TestVariousGets)
 
 TEST_F(OCSPCacheTest, TestEviction)
 {
   SCOPED_TRACE("");
   // By putting more distinct entries in the cache than it can hold,
   // we cause the least recently used entry to be evicted.
   for (int i = 0; i < MaxCacheEntries + 1; i++) {
     uint8_t serialBuf[8];
-    PR_snprintf(reinterpret_cast<char*>(serialBuf), sizeof(serialBuf), "%04d", i);
+    snprintf(reinterpret_cast<char*>(serialBuf), sizeof(serialBuf), "%04d", i);
     Input fakeSerial;
     ASSERT_EQ(Success, fakeSerial.Init(serialBuf, 4));
     Time timeIn(now);
     ASSERT_EQ(Success, timeIn.AddSeconds(i));
     PutAndGet(cache, CertID(fakeIssuer1, fakeKey000, fakeSerial),
               Success, timeIn);
   }
 
@@ -154,17 +154,17 @@ TEST_F(OCSPCacheTest, TestNoEvictionForR
   SCOPED_TRACE("");
   CertID notEvicted(fakeIssuer1, fakeKey000, fakeSerial0000);
   Time timeIn(now);
   PutAndGet(cache, notEvicted, Result::ERROR_REVOKED_CERTIFICATE, timeIn);
   // By putting more distinct entries in the cache than it can hold,
   // we cause the least recently used entry that isn't revoked to be evicted.
   for (int i = 1; i < MaxCacheEntries + 1; i++) {
     uint8_t serialBuf[8];
-    PR_snprintf(reinterpret_cast<char*>(serialBuf), sizeof(serialBuf), "%04d", i);
+    snprintf(reinterpret_cast<char*>(serialBuf), sizeof(serialBuf), "%04d", i);
     Input fakeSerial;
     ASSERT_EQ(Success, fakeSerial.Init(serialBuf, 4));
     Time timeIn(now);
     ASSERT_EQ(Success, timeIn.AddSeconds(i));
     PutAndGet(cache, CertID(fakeIssuer1, fakeKey000, fakeSerial),
               Success, timeIn);
   }
   Result resultOut;
@@ -180,17 +180,17 @@ TEST_F(OCSPCacheTest, TestNoEvictionForR
 
 TEST_F(OCSPCacheTest, TestEverythingIsRevoked)
 {
   SCOPED_TRACE("");
   Time timeIn(now);
   // Fill up the cache with revoked responses.
   for (int i = 0; i < MaxCacheEntries; i++) {
     uint8_t serialBuf[8];
-    PR_snprintf(reinterpret_cast<char*>(serialBuf), sizeof(serialBuf), "%04d", i);
+    snprintf(reinterpret_cast<char*>(serialBuf), sizeof(serialBuf), "%04d", i);
     Input fakeSerial;
     ASSERT_EQ(Success, fakeSerial.Init(serialBuf, 4));
     Time timeIn(now);
     ASSERT_EQ(Success, timeIn.AddSeconds(i));
     PutAndGet(cache, CertID(fakeIssuer1, fakeKey000, fakeSerial),
               Result::ERROR_REVOKED_CERTIFICATE, timeIn);
   }
   static const Input fakeSerial1025(LiteralInput("1025"));
--- a/security/manager/ssl/tests/unit/tlsserver/lib/TLSServer.cpp
+++ b/security/manager/ssl/tests/unit/tlsserver/lib/TLSServer.cpp
@@ -5,16 +5,17 @@
 #include "TLSServer.h"
 
 #include <stdio.h>
 #include <string>
 #include <vector>
 
 #include "ScopedNSSTypes.h"
 #include "base64.h"
+#include "mozilla/Snprintf.h"
 #include "nspr.h"
 #include "nss.h"
 #include "plarenas.h"
 #include "prenv.h"
 #include "prerror.h"
 #include "prnetdb.h"
 #include "prtime.h"
 #include "ssl.h"
@@ -64,18 +65,18 @@ PrintPRError(const char *aPrefix)
   }
 }
 
 template <size_t N>
 SECStatus
 ReadFileToBuffer(const char* basePath, const char* filename, char (&buf)[N])
 {
   static_assert(N > 0, "input buffer too small for ReadFileToBuffer");
-  if (PR_snprintf(buf, N - 1, "%s/%s", basePath, filename) == 0) {
-    PrintPRError("PR_snprintf failed");
+  if (snprintf(buf, N - 1, "%s/%s", basePath, filename) == 0) {
+    PrintPRError("snprintf failed");
     return SECFailure;
   }
   ScopedPRFileDesc fd(PR_OpenFile(buf, PR_RDONLY, 0));
   if (!fd) {
     PrintPRError("PR_Open failed");
     return SECFailure;
   }
   int32_t fileSize = PR_Available(fd);