Skip to content

Commit 867ad1c

Browse files
committed
mbedtls: fix CURLOPT_SSLCERT_BLOB
The memory passed to mbedTLS for this needs to be null terminated. Reported-by: Florian Van Heghe Closes #8146
1 parent 64e8bf9 commit 867ad1c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/vtls/mbedtls.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,17 @@ mbed_connect_step1(struct Curl_easy *data, struct connectdata *conn,
379379
}
380380

381381
if(ssl_cert_blob) {
382-
const unsigned char *blob_data =
383-
(const unsigned char *)ssl_cert_blob->data;
384-
ret = mbedtls_x509_crt_parse(&backend->clicert, blob_data,
382+
/* Unfortunately, mbedtls_x509_crt_parse() requires the data to be null
383+
terminated even when provided the exact length, forcing us to waste
384+
extra memory here. */
385+
unsigned char *newblob = malloc(ssl_cert_blob->len + 1);
386+
if(!newblob)
387+
return CURLE_OUT_OF_MEMORY;
388+
memcpy(newblob, ssl_cert_blob->data, ssl_cert_blob->len);
389+
newblob[ssl_cert_blob->len] = 0; /* null terminate */
390+
ret = mbedtls_x509_crt_parse(&backend->clicert, newblob,
385391
ssl_cert_blob->len);
392+
free(newblob);
386393

387394
if(ret) {
388395
mbedtls_strerror(ret, errorbuf, sizeof(errorbuf));

0 commit comments

Comments
 (0)