Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/boringssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Benjamin <davidben@chromium.org>2015-06-28 08:26:10 +0300
committerAdam Langley <agl@google.com>2015-07-01 22:45:43 +0300
commita8653208ec76d228e889082d5c5e6ce781cdcd8d (patch)
tree042c5519983b5e7fd8141e0249423b243fcabcb1 /crypto/bytestring
parentd63307199a9bc39fe86ec46a131d60c694af41f3 (diff)
Add CBB_zero to set a CBB to the zero state.
One tedious thing about using CBB is that you can't safely CBB_cleanup until CBB_init is successful, which breaks the general 'goto err' style of cleanup. This makes it possible: CBB_zero ~ EVP_MD_CTX_init CBB_init ~ EVP_DigestInit CBB_cleanup ~ EVP_MD_CTX_cleanup Change-Id: I085ecc4405715368886dc4de02285a47e7fc4c52 Reviewed-on: https://boringssl-review.googlesource.com/5267 Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/bytestring')
-rw-r--r--crypto/bytestring/bytestring_test.cc11
-rw-r--r--crypto/bytestring/cbb.c4
2 files changed, 14 insertions, 1 deletions
diff --git a/crypto/bytestring/bytestring_test.cc b/crypto/bytestring/bytestring_test.cc
index 870d7c6a..e987e1b9 100644
--- a/crypto/bytestring/bytestring_test.cc
+++ b/crypto/bytestring/bytestring_test.cc
@@ -649,6 +649,14 @@ static bool TestASN1Uint64() {
return true;
}
+static int TestZero() {
+ CBB cbb;
+ CBB_zero(&cbb);
+ // Calling |CBB_cleanup| on a zero-state |CBB| must not crash.
+ CBB_cleanup(&cbb);
+ return 1;
+}
+
int main(void) {
CRYPTO_library_init();
@@ -665,7 +673,8 @@ int main(void) {
!TestCBBASN1() ||
!TestBerConvert() ||
!TestASN1Uint64() ||
- !TestGetOptionalASN1Bool()) {
+ !TestGetOptionalASN1Bool() ||
+ !TestZero()) {
return 1;
}
diff --git a/crypto/bytestring/cbb.c b/crypto/bytestring/cbb.c
index 290d16fa..b9291ce9 100644
--- a/crypto/bytestring/cbb.c
+++ b/crypto/bytestring/cbb.c
@@ -20,6 +20,10 @@
#include <openssl/mem.h>
+void CBB_zero(CBB *cbb) {
+ memset(cbb, 0, sizeof(CBB));
+}
+
static int cbb_init(CBB *cbb, uint8_t *buf, size_t cap) {
struct cbb_buffer_st *base;