Bug 1313123 - Merge UBSan runs back with ASan and fix remaining test suites r=franziskus
authorTim Taubert <ttaubert@mozilla.com>
Wed, 26 Oct 2016 20:00:19 +0200
changeset 12767 87927a9d502ed68eb3360ed11fd53b19d23dd2af
parent 12766 7934f9deeeda0359fa7413bb1f27e0f584fc519b
child 12768 24232beee1f204c690b2be50845f779dc751ee98
push id1709
push userttaubert@mozilla.com
push dateWed, 26 Oct 2016 18:04:46 +0000
reviewersfranziskus
bugs1313123
Bug 1313123 - Merge UBSan runs back with ASan and fix remaining test suites r=franziskus Differential Revision: https://nss-dev.phacility.com/D125
automation/taskcluster/graph/src/extend.js
automation/taskcluster/graph/src/try_syntax.js
lib/crmf/crmfpop.c
lib/freebl/alg2268.c
lib/freebl/camellia.c
lib/freebl/sha_fast.c
lib/smime/cmsencode.c
lib/softoken/legacydb/lgutil.c
lib/softoken/pkcs11.c
--- a/automation/taskcluster/graph/src/extend.js
+++ b/automation/taskcluster/graph/src/extend.js
@@ -9,24 +9,20 @@ const LINUX_IMAGE = {name: "linux", path
 
 const WINDOWS_CHECKOUT_CMD =
   "bash -c \"hg clone -r $NSS_HEAD_REVISION $NSS_HEAD_REPOSITORY nss || " +
     "(sleep 2; hg clone -r $NSS_HEAD_REVISION $NSS_HEAD_REPOSITORY nss) || " +
     "(sleep 5; hg clone -r $NSS_HEAD_REVISION $NSS_HEAD_REPOSITORY nss)\"";
 
 /*****************************************************************************/
 
-function isSanitizer(task) {
-  return task.collection == "asan" || task.collection == "ubsan";
-}
-
 queue.filter(task => {
   if (task.group == "Builds") {
     // Remove extra builds on {A,UB}San and ARM.
-    if (isSanitizer(task) || task.collection == "arm-debug") {
+    if (task.collection == "asan" || task.collection == "arm-debug") {
       return false;
     }
 
     // Remove extra builds w/o libpkix for non-linux64-debug.
     if (task.symbol == "noLibpkix" &&
         (task.platform != "linux64" || task.collection != "debug")) {
       return false;
     }
@@ -39,27 +35,21 @@ queue.filter(task => {
     }
 
     // No BoGo tests on ARM.
     if (task.collection == "arm-debug") {
       return false;
     }
   }
 
-  // Filter test suites that currently fail with UBSan.
-  if (task.collection == "ubsan" &&
-      ["crmf", "cipher", "fips", "merge", "smime"].includes(task.tests)) {
-    return false;
-  }
-
   return true;
 });
 
 queue.map(task => {
-  if (isSanitizer(task)) {
+  if (task.collection == "asan") {
     // CRMF and FIPS tests still leak, unfortunately.
     if (task.tests == "crmf" || task.tests == "fips") {
       task.env.ASAN_OPTIONS = "detect_leaks=0";
     }
 
     // SSL(standard) runs on ASan take some time.
     if (task.tests == "ssl" && task.cycle == "standard") {
       task.maxRunTime = 7200;
@@ -117,41 +107,27 @@ export default async function main() {
     env: {USE_64: "1"},
     platform: "linux64",
     collection: "gyp",
     image: LINUX_IMAGE
   });
 
   await scheduleLinux("Linux 64 (ASan, debug)", {
     env: {
-      NSS_DISABLE_ARENA_FREE_LIST: "1",
-      NSS_DISABLE_UNLOAD: "1",
-      CC: "clang",
-      CCC: "clang++",
-      USE_ASAN: "1",
-      USE_64: "1"
-    },
-    platform: "linux64",
-    collection: "asan",
-    image: LINUX_IMAGE
-  });
-
-  await scheduleLinux("Linux 64 (ASan+UBSan, debug)", {
-    env: {
       UBSAN_OPTIONS: "print_stacktrace=1",
       NSS_DISABLE_ARENA_FREE_LIST: "1",
       NSS_DISABLE_UNLOAD: "1",
       CC: "clang",
       CCC: "clang++",
       USE_UBSAN: "1",
       USE_ASAN: "1",
       USE_64: "1"
     },
     platform: "linux64",
-    collection: "ubsan",
+    collection: "asan",
     image: LINUX_IMAGE
   });
 
   await scheduleWindows("Windows 2012 64 (opt)", {
     env: {BUILD_OPT: "1"}
   });
 
   await scheduleWindows("Windows 2012 64 (debug)", {
--- a/automation/taskcluster/graph/src/try_syntax.js
+++ b/automation/taskcluster/graph/src/try_syntax.js
@@ -108,17 +108,17 @@ function filter(opts) {
         "arm": "linux32"
       };
 
       // Check the platform name.
       let keep = (task.platform == (aliases[platform] || platform));
 
       // Additional checks.
       if (platform == "linux64-asan") {
-        keep &= coll("asan") || coll("ubsan");
+        keep &= coll("asan");
       } else if (platform == "arm") {
         keep &= coll("arm-opt") || coll("arm-debug");
       } else if (platform == "linux64-gyp") {
         keep &= coll("gyp");
       } else if (platform == "linux64-fuzz") {
         keep &= coll("fuzz");
       } else {
         keep &= coll("opt") || coll("debug");
@@ -127,18 +127,18 @@ function filter(opts) {
       return keep;
     });
 
     if (!found) {
       return false;
     }
 
     // Finally, filter by build type.
-    let isDebug = coll("debug") || coll("asan") || coll("ubsan") ||
-                  coll("arm-debug") || coll("gyp") || coll("fuzz");
+    let isDebug = coll("debug") || coll("asan") || coll("arm-debug") ||
+                  coll("gyp") || coll("fuzz");
     return (isDebug && opts.builds.includes("d")) ||
            (!isDebug && opts.builds.includes("o"));
   }
 }
 
 export function initFilter() {
   let comment = process.env.TC_COMMENT || "";
 
--- a/lib/crmf/crmfpop.c
+++ b/lib/crmf/crmfpop.c
@@ -120,17 +120,19 @@ crmf_generic_encoder_callback(void *arg,
             /* I really want to return an error code here */
             PORT_Assert(0);
             return;
         }
         encoderArg->buffer->data = dummy;
         encoderArg->allocatedLen = newSize;
     }
     cursor = &(encoderArg->buffer->data[encoderArg->buffer->len]);
-    PORT_Memcpy(cursor, buf, len);
+    if (len) {
+        PORT_Memcpy(cursor, buf, len);
+    }
     encoderArg->buffer->len += len;
 }
 
 static SECStatus
 crmf_encode_certreq(CRMFCertRequest *inCertReq, SECItem *derDest)
 {
     struct crmfEncoderArg encoderArg;
     SECStatus rv;
--- a/lib/freebl/alg2268.c
+++ b/lib/freebl/alg2268.c
@@ -359,51 +359,51 @@ rc2_Decrypt1Block(RC2Context *cx, RC2Blo
 
     /* output results */
     output->s[0] = R0;
     output->s[1] = R1;
     output->s[2] = R2;
     output->s[3] = R3;
 }
 
-static SECStatus
+static SECStatus NO_SANITIZE_ALIGNMENT
 rc2_EncryptECB(RC2Context *cx, unsigned char *output,
                const unsigned char *input, unsigned int inputLen)
 {
     RC2Block iBlock;
 
     while (inputLen > 0) {
         LOAD(iBlock.s)
         rc2_Encrypt1Block(cx, &iBlock, &iBlock);
         STORE(iBlock.s)
         output += RC2_BLOCK_SIZE;
         input += RC2_BLOCK_SIZE;
         inputLen -= RC2_BLOCK_SIZE;
     }
     return SECSuccess;
 }
 
-static SECStatus
+static SECStatus NO_SANITIZE_ALIGNMENT
 rc2_DecryptECB(RC2Context *cx, unsigned char *output,
                const unsigned char *input, unsigned int inputLen)
 {
     RC2Block iBlock;
 
     while (inputLen > 0) {
         LOAD(iBlock.s)
         rc2_Decrypt1Block(cx, &iBlock, &iBlock);
         STORE(iBlock.s)
         output += RC2_BLOCK_SIZE;
         input += RC2_BLOCK_SIZE;
         inputLen -= RC2_BLOCK_SIZE;
     }
     return SECSuccess;
 }
 
-static SECStatus
+static SECStatus NO_SANITIZE_ALIGNMENT
 rc2_EncryptCBC(RC2Context *cx, unsigned char *output,
                const unsigned char *input, unsigned int inputLen)
 {
     RC2Block iBlock;
 
     while (inputLen > 0) {
 
         LOAD(iBlock.s)
--- a/lib/freebl/camellia.c
+++ b/lib/freebl/camellia.c
@@ -1073,17 +1073,17 @@ camellia_setup192(const unsigned char *k
     camellia_setup256(kk, subkey);
     return;
 }
 
 /**
  * Stuff related to camellia encryption/decryption
  *
  */
-SECStatus
+SECStatus NO_SANITIZE_ALIGNMENT
 camellia_encrypt128(const PRUint32 *subkey,
                     unsigned char *output,
                     const unsigned char *input)
 {
     PRUint32 il, ir, t0, t1;
     PRUint32 io[4];
 #if defined(CAMELLIA_NEED_TMP_VARIABLE)
     PRUint32 tmp;
@@ -1180,17 +1180,17 @@ camellia_encrypt128(const PRUint32 *subk
     PUTU32(output, io[0]);
     PUTU32(output + 4, io[1]);
     PUTU32(output + 8, io[2]);
     PUTU32(output + 12, io[3]);
 
     return SECSuccess;
 }
 
-SECStatus
+SECStatus NO_SANITIZE_ALIGNMENT
 camellia_decrypt128(const PRUint32 *subkey,
                     unsigned char *output,
                     const unsigned char *input)
 {
     PRUint32 il, ir, t0, t1; /* temporary valiables */
     PRUint32 io[4];
 #if defined(CAMELLIA_NEED_TMP_VARIABLE)
     PRUint32 tmp;
@@ -1290,17 +1290,17 @@ camellia_decrypt128(const PRUint32 *subk
     PUTU32(output + 12, io[3]);
 
     return SECSuccess;
 }
 
 /**
  * stuff for 192 and 256bit encryption/decryption
  */
-SECStatus
+SECStatus NO_SANITIZE_ALIGNMENT
 camellia_encrypt256(const PRUint32 *subkey,
                     unsigned char *output,
                     const unsigned char *input)
 {
     PRUint32 il, ir, t0, t1; /* temporary valiables */
     PRUint32 io[4];
 #if defined(CAMELLIA_NEED_TMP_VARIABLE)
     PRUint32 tmp;
@@ -1421,17 +1421,17 @@ camellia_encrypt256(const PRUint32 *subk
     PUTU32(output, io[0]);
     PUTU32(output + 4, io[1]);
     PUTU32(output + 8, io[2]);
     PUTU32(output + 12, io[3]);
 
     return SECSuccess;
 }
 
-SECStatus
+SECStatus NO_SANITIZE_ALIGNMENT
 camellia_decrypt256(const PRUint32 *subkey,
                     unsigned char *output,
                     const unsigned char *input)
 {
     PRUint32 il, ir, t0, t1; /* temporary valiables */
     PRUint32 io[4];
 #if defined(CAMELLIA_NEED_TMP_VARIABLE)
     PRUint32 tmp;
--- a/lib/freebl/sha_fast.c
+++ b/lib/freebl/sha_fast.c
@@ -135,17 +135,17 @@ SHA1_Update(SHA1Context *ctx, const unsi
     if (len) {
         memcpy(ctx->B, dataIn, len);
     }
 }
 
 /*
  *  SHA: Generate hash value from context
  */
-void
+void NO_SANITIZE_ALIGNMENT
 SHA1_End(SHA1Context *ctx, unsigned char *hashout,
          unsigned int *pDigestLen, unsigned int maxDigestLen)
 {
     register PRUint64 size;
     register PRUint32 lenB;
 
     static const unsigned char bulk_pad[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
--- a/lib/smime/cmsencode.c
+++ b/lib/smime/cmsencode.c
@@ -100,17 +100,19 @@ nss_cms_encoder_out(void *arg, const cha
 	if (dest == NULL)
 	    /* oops */
 	    return;
 
 	output->dest->data = dest;
 	output->dest->len += len;
 
 	/* copy it in */
-	PORT_Memcpy(output->dest->data + offset, buf, len);
+        if (len) {
+            PORT_Memcpy(output->dest->data + offset, buf, len);
+        }
     }
 }
 
 /*
  * nss_cms_encoder_notify - ASN.1 encoder callback
  *
  * this function is called by the ASN.1 encoder before and after the encoding of
  * every object. here, it is used to keep track of data structures, set up
--- a/lib/softoken/legacydb/lgutil.c
+++ b/lib/softoken/legacydb/lgutil.c
@@ -62,17 +62,19 @@ lg_Attribute2SecItem(PLArenaPool *arena,
         item->data = (unsigned char *)PORT_ArenaAlloc(arena, len);
     } else {
         item->data = (unsigned char *)PORT_Alloc(len);
     }
     if (item->data == NULL) {
         return CKR_HOST_MEMORY;
     }
     item->len = len;
-    PORT_Memcpy(item->data, attribute->pValue, len);
+    if (item->len) {
+        PORT_Memcpy(item->data, attribute->pValue, len);
+    }
     return CKR_OK;
 }
 
 /*
  * copy an unsigned attribute into a SECItem. Secitem is allocated in
  * the specified arena.
  */
 CK_RV
--- a/lib/softoken/pkcs11.c
+++ b/lib/softoken/pkcs11.c
@@ -4001,17 +4001,19 @@ NSC_Login(CK_SESSION_HANDLE hSession, CK
         return ulPinLen ? CKR_PIN_INCORRECT : CKR_OK;
     }
     slot->ssoLoggedIn = PR_FALSE;
 
     if (ulPinLen > SFTK_MAX_PIN)
         return CKR_PIN_LEN_RANGE;
 
     /* convert to null terminated string */
-    PORT_Memcpy(pinStr, pPin, ulPinLen);
+    if (ulPinLen) {
+        PORT_Memcpy(pinStr, pPin, ulPinLen);
+    }
     pinStr[ulPinLen] = 0;
 
     handle = sftk_getKeyDB(slot);
     if (handle == NULL) {
         return CKR_USER_TYPE_INVALID;
     }
 
     /*