Bug 1521360 - Ensure that Prio early cleanup runs correctly. r=henrycg, a=lizzard
authorRobert Helmer <rhelmer@mozilla.com>
Fri, 08 Feb 2019 22:52:56 +0000
changeset 516045 c5bcd3213da631ccba03d2ed8a16bd1519c424e4
parent 516044 26383c993190b7ba1b9360771efe404025ae01ad
child 516046 42c46d6cd486fca17442648ef856b8f700c13391
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershenrycg, lizzard
bugs1521360
milestone66.0
Bug 1521360 - Ensure that Prio early cleanup runs correctly. r=henrycg, a=lizzard Differential Revision: https://phabricator.services.mozilla.com/D17309
third_party/prio/prio/client.c
third_party/prio/prio/serial.c
--- a/third_party/prio/prio/client.c
+++ b/third_party/prio/prio/client.c
@@ -282,27 +282,27 @@ PrioClient_encode(const_PrioConfig cfg, 
                   unsigned char** for_server_b, unsigned int* bLen)
 {
   SECStatus rv = SECSuccess;
   PrioPacketClient pA = NULL;
   PrioPacketClient pB = NULL;
   *for_server_a = NULL;
   *for_server_b = NULL;
 
-  P_CHECKA(pA = PrioPacketClient_new(cfg, PRIO_SERVER_A));
-  P_CHECKA(pB = PrioPacketClient_new(cfg, PRIO_SERVER_B));
-
   msgpack_sbuffer sbufA, sbufB;
   msgpack_packer packerA, packerB;
 
   msgpack_sbuffer_init(&sbufA);
   msgpack_sbuffer_init(&sbufB);
   msgpack_packer_init(&packerA, &sbufA, msgpack_sbuffer_write);
   msgpack_packer_init(&packerB, &sbufB, msgpack_sbuffer_write);
 
+  P_CHECKA(pA = PrioPacketClient_new(cfg, PRIO_SERVER_A));
+  P_CHECKA(pB = PrioPacketClient_new(cfg, PRIO_SERVER_B));
+
   P_CHECKC(PrioPacketClient_set_data(cfg, data_in, pA, pB));
   P_CHECKC(serial_write_packet_client(&packerA, pA, cfg));
   P_CHECKC(serial_write_packet_client(&packerB, pB, cfg));
 
   P_CHECKC(PublicKey_encryptSize(sbufA.size, aLen));
   P_CHECKC(PublicKey_encryptSize(sbufB.size, bLen));
 
   P_CHECKA(*for_server_a = malloc(*aLen));
@@ -338,17 +338,19 @@ cleanup:
 
 SECStatus
 PrioPacketClient_decrypt(PrioPacketClient p, const_PrioConfig cfg,
                          PrivateKey server_priv, const unsigned char* data_in,
                          unsigned int data_len)
 {
   SECStatus rv = SECSuccess;
   msgpack_unpacker upk;
-  P_CHECKCB(msgpack_unpacker_init(&upk, data_len));
+  if (!msgpack_unpacker_init(&upk, data_len)) {
+    return SECFailure;
+  }
 
   // Decrypt the ciphertext into dec_buf
   unsigned int bytes_decrypted;
   P_CHECKC(PrivateKey_decrypt(server_priv,
                               (unsigned char*)msgpack_unpacker_buffer(&upk),
                               &bytes_decrypted, data_len, data_in, data_len));
   msgpack_unpacker_buffer_consumed(&upk, bytes_decrypted);
 
--- a/third_party/prio/prio/serial.c
+++ b/third_party/prio/prio/serial.c
@@ -53,42 +53,46 @@ object_to_mp_int(msgpack_object* obj, mp
 cleanup:
   return rv;
 }
 
 static SECStatus
 serial_read_mp_int(msgpack_unpacker* upk, mp_int* n, const mp_int* max)
 {
   SECStatus rv = SECSuccess;
+
+  msgpack_unpacked res;
+  msgpack_unpacked_init(&res);
+
   P_CHECKCB(upk != NULL);
   P_CHECKCB(n != NULL);
   P_CHECKCB(max != NULL);
 
-  msgpack_unpacked res;
-  msgpack_unpacked_init(&res);
   UP_CHECK(msgpack_unpacker_next(upk, &res))
 
   msgpack_object obj = res.data;
   P_CHECKC(object_to_mp_int(&obj, n, max));
 
 cleanup:
   msgpack_unpacked_destroy(&res);
 
   return rv;
 }
 
 static SECStatus
 serial_read_int(msgpack_unpacker* upk, int* n)
 {
   SECStatus rv = SECSuccess;
+
+  msgpack_unpacked res;
+  msgpack_unpacked_init(&res);
+
   P_CHECKCB(upk != NULL);
   P_CHECKCB(n != NULL);
 
-  msgpack_unpacked res;
-  msgpack_unpacked_init(&res);
   UP_CHECK(msgpack_unpacker_next(upk, &res))
 
   msgpack_object obj = res.data;
   P_CHECKCB(obj.type == MSGPACK_OBJECT_POSITIVE_INTEGER);
 
   *n = obj.via.i64;
 
 cleanup:
@@ -113,22 +117,24 @@ cleanup:
   return rv;
 }
 
 static SECStatus
 serial_read_mp_array(msgpack_unpacker* upk, MPArray arr, size_t len,
                      const mp_int* max)
 {
   SECStatus rv = SECSuccess;
+
+  msgpack_unpacked res;
+  msgpack_unpacked_init(&res);
+
   P_CHECKCB(upk != NULL);
   P_CHECKCB(arr != NULL);
   P_CHECKCB(max != NULL);
 
-  msgpack_unpacked res;
-  msgpack_unpacked_init(&res);
   UP_CHECK(msgpack_unpacker_next(upk, &res))
 
   msgpack_object obj = res.data;
   P_CHECKCB(obj.type == MSGPACK_OBJECT_ARRAY);
 
   msgpack_object_array objarr = obj.via.array;
   P_CHECKCB(objarr.size == len);
 
@@ -218,21 +224,23 @@ serial_write_prg_seed(msgpack_packer* pk
 cleanup:
   return rv;
 }
 
 static SECStatus
 serial_read_prg_seed(msgpack_unpacker* upk, PrioPRGSeed* seed)
 {
   SECStatus rv = SECSuccess;
+
+  msgpack_unpacked res;
+  msgpack_unpacked_init(&res);
+
   P_CHECKCB(upk != NULL);
   P_CHECKCB(seed != NULL);
 
-  msgpack_unpacked res;
-  msgpack_unpacked_init(&res);
   UP_CHECK(msgpack_unpacker_next(upk, &res))
 
   msgpack_object obj = res.data;
   P_CHECKCB(obj.type == MSGPACK_OBJECT_STR);
 
   msgpack_object_str s = obj.via.str;
   P_CHECKCB(s.size == PRG_SEED_LENGTH);
   memcpy(seed, s.ptr, PRG_SEED_LENGTH);
@@ -317,20 +325,23 @@ cleanup:
   return rv;
 }
 
 SECStatus
 serial_read_packet_client(msgpack_unpacker* upk, PrioPacketClient p,
                           const_PrioConfig cfg)
 {
   SECStatus rv = SECSuccess;
+
+  msgpack_unpacked res;
+  msgpack_unpacked_init(&res);
+
   P_CHECKCB(upk != NULL);
   P_CHECKCB(p != NULL);
-  msgpack_unpacked res;
-  msgpack_unpacked_init(&res);
+
   UP_CHECK(msgpack_unpacker_next(upk, &res))
 
   msgpack_object obj = res.data;
   P_CHECKCB(obj.type == MSGPACK_OBJECT_STR);
 
   msgpack_object_str s = obj.via.str;
   P_CHECKCB(s.size == cfg->batch_id_len);
   P_CHECKCB(!memcmp(s.ptr, (char*)cfg->batch_id, cfg->batch_id_len));