Bug 1232219 (part 1) - Fix -Wunused warnings in libmar/. r=bbondy.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 16 Dec 2015 22:24:19 -0800
changeset 278418 3a785337924021ba18a5252775472a2ead8a50f6
parent 278417 290f666471a0177f984f05d5c9933914d2d11443
child 278419 8acbf93a07173240edb5818cf4361036d8f85122
push id29850
push usercbook@mozilla.com
push dateTue, 05 Jan 2016 10:59:10 +0000
treeherdermozilla-central@29258f59e545 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbondy
bugs1232219
milestone46.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 1232219 (part 1) - Fix -Wunused warnings in libmar/. r=bbondy.
modules/libmar/sign/mar_sign.c
modules/libmar/src/mar_read.c
modules/libmar/tool/mar.c
modules/libmar/verify/mar_verify.c
--- a/modules/libmar/sign/mar_sign.c
+++ b/modules/libmar/sign/mar_sign.c
@@ -258,17 +258,17 @@ strip_signature_block(const char *src, c
   uint32_t offsetToIndex, dstOffsetToIndex, indexLength, 
     numSignatures = 0, leftOver;
   int32_t stripAmount = 0;
   int64_t oldPos, sizeOfEntireMAR = 0, realSizeOfSrcMAR, numBytesToCopy,
     numChunks, i;
   FILE *fpSrc = NULL, *fpDest = NULL;
   int rv = -1, hasSignatureBlock;
   char buf[BLOCKSIZE];
-  char *indexBuf = NULL, *indexBufLoc;
+  char *indexBuf = NULL;
 
   if (!src || !dest) {
     fprintf(stderr, "ERROR: Invalid parameter passed in.\n");
     return -1;
   }
 
   fpSrc = fopen(src, "rb");
   if (!fpSrc) {
@@ -428,17 +428,16 @@ strip_signature_block(const char *src, c
   if (ReadAndWrite(fpSrc, fpDest, &indexLength, 
                    sizeof(indexLength), "index length")) {
     goto failure;
   }
   indexLength = ntohl(indexLength);
 
   /* Consume the index and adjust each index by the difference */
   indexBuf = malloc(indexLength);
-  indexBufLoc = indexBuf;
   if (fread(indexBuf, indexLength, 1, fpSrc) != 1) {
     fprintf(stderr, "ERROR: Could not read index\n");
     goto failure;
   }
 
   /* Adjust each entry in the index */
   if (hasSignatureBlock) {
     AdjustIndexContentOffsets(indexBuf, indexLength, -stripAmount);
@@ -832,17 +831,17 @@ mar_repackage_and_sign(const char *NSSCo
     numChunks, i;
   FILE *fpSrc = NULL, *fpDest = NULL;
   int rv = -1, hasSignatureBlock;
   SGNContext *ctxs[MAX_SIGNATURES];
   SECItem secItems[MAX_SIGNATURES];
   char buf[BLOCKSIZE];
   SECKEYPrivateKey *privKeys[MAX_SIGNATURES];
   CERTCertificate *certs[MAX_SIGNATURES];
-  char *indexBuf = NULL, *indexBufLoc;
+  char *indexBuf = NULL;
   uint32_t k;
 
   memset(signatureLengths, 0, sizeof(signatureLengths));
   memset(ctxs, 0, sizeof(ctxs));
   memset(secItems, 0, sizeof(secItems));
   memset(privKeys, 0, sizeof(privKeys));
   memset(certs, 0, sizeof(certs));
 
@@ -1054,17 +1053,16 @@ mar_repackage_and_sign(const char *NSSCo
                                    sizeof(indexLength), ctxs, certCount,
                                    "index length")) {
     goto failure;
   }
   indexLength = ntohl(indexLength);
 
   /* Consume the index and adjust each index by signatureSectionLength */
   indexBuf = malloc(indexLength);
-  indexBufLoc = indexBuf;
   if (fread(indexBuf, indexLength, 1, fpSrc) != 1) {
     fprintf(stderr, "ERROR: Could not read index\n");
     goto failure;
   }
 
   /* Adjust each entry in the index */
   if (hasSignatureBlock) {
     AdjustIndexContentOffsets(indexBuf, indexLength, signatureSectionLength);
--- a/modules/libmar/src/mar_read.c
+++ b/modules/libmar/src/mar_read.c
@@ -401,20 +401,22 @@ mar_read_product_info_block(MarFile *mar
 {
   uint32_t i, offsetAdditionalBlocks, numAdditionalBlocks,
     additionalBlockSize, additionalBlockID;
   int hasAdditionalBlocks;
 
   /* The buffer size is 97 bytes because the MAR channel name < 64 bytes, and 
      product version < 32 bytes + 3 NULL terminator bytes. */
   char buf[97] = { '\0' };
-  int ret = get_mar_file_info_fp(mar->fp, NULL, NULL,
-                                 &hasAdditionalBlocks, 
-                                 &offsetAdditionalBlocks, 
-                                 &numAdditionalBlocks);
+  if (get_mar_file_info_fp(mar->fp, NULL, NULL,
+                           &hasAdditionalBlocks,
+                           &offsetAdditionalBlocks,
+                           &numAdditionalBlocks) != 0) {
+    return -1;
+  }
   for (i = 0; i < numAdditionalBlocks; ++i) {
     /* Read the additional block size */
     if (fread(&additionalBlockSize, 
               sizeof(additionalBlockSize), 
               1, mar->fp) != 1) {
       return -1;
     }
     additionalBlockSize = ntohl(additionalBlockSize) - 
--- a/modules/libmar/tool/mar.c
+++ b/modules/libmar/tool/mar.c
@@ -120,17 +120,20 @@ int main(int argc, char **argv) {
   uint32_t k;
   int rv = -1;
   uint32_t certCount = 0;
   int32_t sigIndex = -1;
 
 #if !defined(NO_SIGN_VERIFY)
   uint32_t fileSizes[MAX_SIGNATURES];
   const uint8_t* certBuffers[MAX_SIGNATURES];
+#if ((!defined(MAR_NSS) && defined(XP_WIN)) || defined(XP_MACOSX)) || \
+    ((defined(XP_WIN) || defined(XP_MACOSX)) && !defined(MAR_NSS))
   char* DERFilePaths[MAX_SIGNATURES];
+#endif
 #if (!defined(XP_WIN) && !defined(XP_MACOSX)) || defined(MAR_NSS)
   CERTCertificate* certs[MAX_SIGNATURES];
 #endif
 #endif
 
   memset((void*)certNames, 0, sizeof(certNames));
 #if defined(XP_WIN) && !defined(MAR_NSS) && !defined(NO_SIGN_VERIFY)
   memset((void*)certBuffers, 0, sizeof(certBuffers));
--- a/modules/libmar/verify/mar_verify.c
+++ b/modules/libmar/verify/mar_verify.c
@@ -189,21 +189,18 @@ failure:
  * @param  keyCount The number of keys pointed to by keys
  * @return 0 on success
 */
 int
 mar_extract_and_verify_signatures_fp(FILE *fp,
                                      CryptoX_ProviderHandle provider,
                                      CryptoX_PublicKey *keys,
                                      uint32_t keyCount) {
-  char buf[5] = {0};
   uint32_t signatureCount, signatureLen, numVerified = 0;
   uint32_t signatureAlgorithmIDs[MAX_SIGNATURES];
-  int rv = -1;
-  int64_t curPos;
   uint8_t *extractedSignatures[MAX_SIGNATURES];
   uint32_t i;
 
   memset(signatureAlgorithmIDs, 0, sizeof(signatureAlgorithmIDs));
   memset(extractedSignatures, 0, sizeof(extractedSignatures));
 
   if (!fp) {
     fprintf(stderr, "ERROR: Invalid file pointer passed.\n");
@@ -281,23 +278,27 @@ mar_extract_and_verify_signatures_fp(FIL
       fprintf(stderr, "ERROR: Unknown signature algorithm ID.\n");
       for (i = 0; i < signatureCount; ++i) {
         free(extractedSignatures[i]);
       }
       return CryptoX_Error;
     }
   }
 
-  curPos = ftello(fp);
-  rv = mar_verify_signatures_for_fp(fp,
-                                    provider,
-                                    keys,
-                                    (const uint8_t * const *)extractedSignatures,
-                                    signatureCount,
-                                    &numVerified);
+  if (ftello(fp) == -1) {
+    return CryptoX_Error;
+  }
+  if (mar_verify_signatures_for_fp(fp,
+                                   provider,
+                                   keys,
+                                   (const uint8_t * const *)extractedSignatures,
+                                   signatureCount,
+                                   &numVerified) == CryptoX_Error) {
+    return CryptoX_Error;
+  }
   for (i = 0; i < signatureCount; ++i) {
     free(extractedSignatures[i]);
   }
 
   /* If we reached here and we verified every
      signature, return success. */
   if (numVerified == signatureCount && keyCount == numVerified) {
     return CryptoX_Success;