BIO_new_mem_buf should take const void *
BIO_FLAGS_MEM_RDONLY keeps the invariant. (Imported from upstream's a38a159bfcbc94214dda00e0e6b1fc6454a23b78) Change-Id: I4cb35615d76b77929915e370dbb7fec1455da069 Reviewed-on: https://boringssl-review.googlesource.com/7214 Reviewed-by: David Benjamin <davidben@google.com>
This commit is contained in:
committed by
David Benjamin
parent
a5ee83f67e
commit
d8eea14443
@@ -64,7 +64,7 @@
|
||||
#include <openssl/mem.h>
|
||||
|
||||
|
||||
BIO *BIO_new_mem_buf(void *buf, int len) {
|
||||
BIO *BIO_new_mem_buf(const void *buf, int len) {
|
||||
BIO *ret;
|
||||
BUF_MEM *b;
|
||||
const size_t size = len < 0 ? strlen((char *)buf) : (size_t)len;
|
||||
@@ -80,7 +80,8 @@ BIO *BIO_new_mem_buf(void *buf, int len) {
|
||||
}
|
||||
|
||||
b = (BUF_MEM *)ret->ptr;
|
||||
b->data = buf;
|
||||
/* BIO_FLAGS_MEM_RDONLY ensures |b->data| is not written to. */
|
||||
b->data = (void *)buf;
|
||||
b->length = size;
|
||||
b->max = size;
|
||||
|
||||
|
||||
@@ -331,7 +331,7 @@ static bool TestPrintf() {
|
||||
|
||||
static bool ReadASN1(bool should_succeed, const uint8_t *data, size_t data_len,
|
||||
size_t expected_len, size_t max_len) {
|
||||
ScopedBIO bio(BIO_new_mem_buf(const_cast<uint8_t*>(data), data_len));
|
||||
ScopedBIO bio(BIO_new_mem_buf(data, data_len));
|
||||
|
||||
uint8_t *out;
|
||||
size_t out_len;
|
||||
|
||||
@@ -708,7 +708,7 @@ static bool Test(const char *name, const uint8_t *der, size_t der_len) {
|
||||
}
|
||||
|
||||
static bool TestCompat(const uint8_t *der, size_t der_len) {
|
||||
ScopedBIO bio(BIO_new_mem_buf((void*) der, der_len));
|
||||
ScopedBIO bio(BIO_new_mem_buf(der, der_len));
|
||||
if (!bio) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -596,7 +596,7 @@ static int test_crl_reparse(const uint8_t *der_bytes, size_t der_len) {
|
||||
}
|
||||
|
||||
static int test_pem_certs(const char *pem) {
|
||||
BIO *bio = BIO_new_mem_buf((char *) pem, strlen(pem));
|
||||
BIO *bio = BIO_new_mem_buf(pem, strlen(pem));
|
||||
STACK_OF(X509) *certs = sk_X509_new_null();
|
||||
|
||||
if (!PKCS7_get_PEM_certificates(certs, bio)) {
|
||||
@@ -618,7 +618,7 @@ static int test_pem_certs(const char *pem) {
|
||||
}
|
||||
|
||||
static int test_pem_crls(const char *pem) {
|
||||
BIO *bio = BIO_new_mem_buf((char *) pem, strlen(pem));
|
||||
BIO *bio = BIO_new_mem_buf(pem, strlen(pem));
|
||||
STACK_OF(X509_CRL) *crls = sk_X509_CRL_new_null();
|
||||
|
||||
if (!PKCS7_get_PEM_CRLs(crls, bio)) {
|
||||
@@ -653,4 +653,3 @@ int main(void) {
|
||||
printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ static const char kForgeryPEM[] =
|
||||
// CertFromPEM parses the given, NUL-terminated PEM block and returns an
|
||||
// |X509*|.
|
||||
static X509* CertFromPEM(const char *pem) {
|
||||
ScopedBIO bio(BIO_new_mem_buf(const_cast<char*>(pem), strlen(pem)));
|
||||
ScopedBIO bio(BIO_new_mem_buf(pem, strlen(pem)));
|
||||
return PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -368,12 +368,12 @@ OPENSSL_EXPORT int BIO_read_asn1(BIO *bio, uint8_t **out, size_t *out_len,
|
||||
/* BIO_s_mem returns a |BIO_METHOD| that uses a in-memory buffer. */
|
||||
OPENSSL_EXPORT const BIO_METHOD *BIO_s_mem(void);
|
||||
|
||||
/* BIO_new_mem_buf creates BIO that reads and writes from |len| bytes at |buf|.
|
||||
/* BIO_new_mem_buf creates read-only BIO that reads from |len| bytes at |buf|.
|
||||
* It does not take ownership of |buf|. It returns the BIO or NULL on error.
|
||||
*
|
||||
* If |len| is negative, then |buf| is treated as a NUL-terminated string, but
|
||||
* don't depend on this in new code. */
|
||||
OPENSSL_EXPORT BIO *BIO_new_mem_buf(void *buf, int len);
|
||||
OPENSSL_EXPORT BIO *BIO_new_mem_buf(const void *buf, int len);
|
||||
|
||||
/* BIO_mem_contents sets |*out_contents| to point to the current contents of
|
||||
* |bio| and |*out_len| to contain the length of that data. It returns one on
|
||||
|
||||
+2
-3
@@ -1001,8 +1001,7 @@ static ScopedX509 GetTestCertificate() {
|
||||
"T5oQpHL9z/cCDLAKCKRa4uV0fhEdOWBqyR9p8y5jJtye72t6CuFUV5iqcpF4BH4f\n"
|
||||
"j2VNHwsSrJwkD4QUGlUtH7vwnQmyCFxZMmWAJg==\n"
|
||||
"-----END CERTIFICATE-----\n";
|
||||
ScopedBIO bio(
|
||||
BIO_new_mem_buf(const_cast<char *>(kCertPEM), strlen(kCertPEM)));
|
||||
ScopedBIO bio(BIO_new_mem_buf(kCertPEM, strlen(kCertPEM)));
|
||||
return ScopedX509(PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr));
|
||||
}
|
||||
|
||||
@@ -1023,7 +1022,7 @@ static ScopedEVP_PKEY GetTestKey() {
|
||||
"tfDwbqkta4xcux67//khAkEAvvRXLHTaa6VFzTaiiO8SaFsHV3lQyXOtMrBpB5jd\n"
|
||||
"moZWgjHvB2W9Ckn7sDqsPB+U2tyX0joDdQEyuiMECDY8oQ==\n"
|
||||
"-----END RSA PRIVATE KEY-----\n";
|
||||
ScopedBIO bio(BIO_new_mem_buf(const_cast<char *>(kKeyPEM), strlen(kKeyPEM)));
|
||||
ScopedBIO bio(BIO_new_mem_buf(kKeyPEM, strlen(kKeyPEM)));
|
||||
return ScopedEVP_PKEY(
|
||||
PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user