Codebase list openssl / 43a8f91
apps/dgst.c: allocate a new signature buffer ... if the fixed-size buffer is too small. Fixes #9732 Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Patrick Steuer <patrick.steuer@de.ibm.com> (Merged from https://github.com/openssl/openssl/pull/10276) (cherry picked from commit 7c2d95d47ccb3797f0da6bd4446747c6eee07b87) Pavel Karagodin authored 4 years ago Patrick Steuer committed 4 years ago
1 changed file(s) with 25 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
500500 const char *sig_name, const char *md_name,
501501 const char *file)
502502 {
503 size_t len;
504 int i, backslash = 0;
503 size_t len = BUFSIZE;
504 int i, backslash = 0, ret = 1;
505 unsigned char *sigbuf = NULL;
505506
506507 while (BIO_pending(bp) || !BIO_eof(bp)) {
507508 i = BIO_read(bp, (char *)buf, BUFSIZE);
508509 if (i < 0) {
509510 BIO_printf(bio_err, "Read Error in %s\n", file);
510511 ERR_print_errors(bio_err);
511 return 1;
512 goto end;
512513 }
513514 if (i == 0)
514515 break;
521522 BIO_printf(out, "Verified OK\n");
522523 } else if (i == 0) {
523524 BIO_printf(out, "Verification Failure\n");
524 return 1;
525 goto end;
525526 } else {
526527 BIO_printf(bio_err, "Error Verifying Data\n");
527528 ERR_print_errors(bio_err);
528 return 1;
529 }
530 return 0;
529 goto end;
530 }
531 ret = 0;
532 goto end;
531533 }
532534 if (key != NULL) {
533535 EVP_MD_CTX *ctx;
536 int pkey_len;
534537 BIO_get_md_ctx(bp, &ctx);
535 len = BUFSIZE;
538 pkey_len = EVP_PKEY_size(key);
539 if (pkey_len > BUFSIZE) {
540 len = pkey_len;
541 sigbuf = app_malloc(len, "Signature buffer");
542 buf = sigbuf;
543 }
536544 if (!EVP_DigestSignFinal(ctx, buf, &len)) {
537545 BIO_printf(bio_err, "Error Signing Data\n");
538546 ERR_print_errors(bio_err);
539 return 1;
547 goto end;
540548 }
541549 } else {
542550 len = BIO_gets(bp, (char *)buf, BUFSIZE);
543551 if ((int)len < 0) {
544552 ERR_print_errors(bio_err);
545 return 1;
553 goto end;
546554 }
547555 }
548556
577585 }
578586 BIO_printf(out, "\n");
579587 }
580 return 0;
588
589 ret = 0;
590 end:
591 if (sigbuf != NULL)
592 OPENSSL_clear_free(sigbuf, len);
593
594 return ret;
581595 }