Skip to content

Commit 98a3f76

Browse files
committed
Change i to long and add overflow check before return
1 parent 5ec46ff commit 98a3f76

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

crypto/pem/pem_lib.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ int PEM_write(FILE *fp, const char *name, const char *header,
483483

484484
int PEM_write_bio(BIO *bp, const char *name, const char *header,
485485
const unsigned char *data, long len) {
486-
int nlen, n, i, outl;
487-
long j;
486+
int nlen, n, outl;
487+
long i, j;
488488
unsigned char *buf = NULL;
489489
EVP_ENCODE_CTX ctx;
490490
int reason = ERR_R_BUF_LIB;
@@ -534,7 +534,11 @@ int PEM_write_bio(BIO *bp, const char *name, const char *header,
534534
(BIO_write(bp, "-----\n", 6) != 6)) {
535535
goto err;
536536
}
537-
return i + outl;
537+
if (i + outl > INT_MAX) {
538+
reason = ERR_R_OVERFLOW;
539+
goto err;
540+
}
541+
return (int)(i + outl);
538542
err:
539543
if (buf) {
540544
OPENSSL_free(buf);

0 commit comments

Comments
 (0)