Skip to content

Commit e8ef027

Browse files
committed
Simplify base64 decoding in script.c
1 parent 0a07617 commit e8ef027

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

script.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,10 @@ static PKCS7 *script_pkcs7_extract(FILE_FORMAT_CTX *ctx)
316316
{
317317
const char *signature_data = ctx->options->indata + ctx->script_ctx->sigpos;
318318
size_t signature_len = ctx->script_ctx->fileend - ctx->script_ctx->sigpos;
319-
size_t base64_len, der_max_length, der_length;
319+
size_t base64_len;
320320
char *ptr;
321321
BIO *bio_mem, *bio_b64 = NULL;
322322
char *base64_data = NULL;
323-
char *der_data = NULL;
324-
const char *der_tmp;
325323
char *clean_base64 = NULL;
326324
int clean_base64_len = 0;
327325
const char *open_tag = ctx->script_ctx->comment_text->open;
@@ -403,26 +401,12 @@ static PKCS7 *script_pkcs7_extract(FILE_FORMAT_CTX *ctx)
403401
BIO_push(bio_b64, bio_mem);
404402
BIO_set_flags(bio_b64, BIO_FLAGS_BASE64_NO_NL);
405403

406-
/* allocate memory for DER output */
407-
der_max_length = BIO_ctrl_pending(bio_b64);
408-
der_data = OPENSSL_malloc(der_max_length);
409-
if (!der_data)
410-
goto cleanup;
411-
412-
/* decode Base64 to DER */
413-
if (!BIO_read_ex(bio_b64, der_data, der_max_length, &der_length))
414-
goto cleanup;
415-
if (der_length <= 0)
416-
goto cleanup;
417-
418404
/* decode DER */
419-
der_tmp = der_data;
420-
retval = d2i_PKCS7(NULL, (const unsigned char **)&der_tmp, (int)der_length);
405+
retval = d2i_PKCS7_bio(bio_b64, NULL);
421406

422407
cleanup:
423408
OPENSSL_free(base64_data);
424409
OPENSSL_free(clean_base64);
425-
OPENSSL_free(der_data);
426410
BIO_free_all(bio_b64);
427411
return retval;
428412
}

0 commit comments

Comments
 (0)