Skip to content

Commit 29f96fb

Browse files
committed
Fix potential leaks when writing to BIO fails
When the BIO is created but writing fails, these can leak. Closes GH-18186.
1 parent 90f582b commit 29f96fb

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Diff for: NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ PHP NEWS
1818
- OpenSSL:
1919
. Fix memory leak in openssl_sign() when passing invalid algorithm.
2020
(nielsdos)
21+
. Fix potential leaks when writing to BIO fails. (nielsdos)
2122

2223
- Standard:
2324
. Fixed bug GH-18145 (php8ts crashes in php_clear_stat_cache()).

Diff for: ext/openssl/openssl.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -5742,8 +5742,8 @@ PHP_FUNCTION(openssl_pkcs7_read)
57425742
BIO_get_mem_ptr(bio_out, &bio_buf);
57435743
ZVAL_STRINGL(&zcert, bio_buf->data, bio_buf->length);
57445744
add_index_zval(zout, i, &zcert);
5745-
BIO_free(bio_out);
57465745
}
5746+
BIO_free(bio_out);
57475747
}
57485748
}
57495749

@@ -5757,8 +5757,8 @@ PHP_FUNCTION(openssl_pkcs7_read)
57575757
BIO_get_mem_ptr(bio_out, &bio_buf);
57585758
ZVAL_STRINGL(&zcert, bio_buf->data, bio_buf->length);
57595759
add_index_zval(zout, i, &zcert);
5760-
BIO_free(bio_out);
57615760
}
5761+
BIO_free(bio_out);
57625762
}
57635763
}
57645764

@@ -6383,8 +6383,8 @@ PHP_FUNCTION(openssl_cms_read)
63836383
BIO_get_mem_ptr(bio_out, &bio_buf);
63846384
ZVAL_STRINGL(&zcert, bio_buf->data, bio_buf->length);
63856385
add_index_zval(zout, i, &zcert);
6386-
BIO_free(bio_out);
63876386
}
6387+
BIO_free(bio_out);
63886388
}
63896389
}
63906390

@@ -6398,8 +6398,8 @@ PHP_FUNCTION(openssl_cms_read)
63986398
BIO_get_mem_ptr(bio_out, &bio_buf);
63996399
ZVAL_STRINGL(&zcert, bio_buf->data, bio_buf->length);
64006400
add_index_zval(zout, i, &zcert);
6401-
BIO_free(bio_out);
64026401
}
6402+
BIO_free(bio_out);
64036403
}
64046404
}
64056405

0 commit comments

Comments
 (0)