Commit b5b34d32cb for openssl.org
commit b5b34d32cb98341434dd8b88a13182b0131d9344
Author: olszomal <Malgorzata.Olszowka@stunnel.org>
Date: Tue Aug 5 12:00:03 2025 +0200
BIO: avoid returning internal FILE * with UPLINK-enabled builds on Windows
On Windows with UPLINK enabled, BIO_get_fp() may return a FILE * pointer
incompatible with the C runtime. Ensure that it returns NULL instead,
preventing undefined behavior in applications. Update the documentation
to include the missing return type for BIO_[gs]et_fp() and remove
the mention that BIO_get_fp() never returns 0, as it does so now
when NULL fp is returned.
Signed-off-by: olszomal <Malgorzata.Olszowka@stunnel.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
MergeDate: Wed Jul 8 09:47:40 2026
(Merged from https://github.com/openssl/openssl/pull/28172)
diff --git a/crypto/bio/bss_file.c b/crypto/bio/bss_file.c
index 11e96a23d7..7aed585342 100644
--- a/crypto/bio/bss_file.c
+++ b/crypto/bio/bss_file.c
@@ -332,7 +332,13 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
/* the ptr parameter is actually a FILE ** in this case. */
if (ptr != NULL) {
fpp = (FILE **)ptr;
- *fpp = (FILE *)b->ptr;
+ if (BIO_FLAGS_UPLINK_INTERNAL == 0
+ || b->flags & BIO_FLAGS_UPLINK_INTERNAL) {
+ *fpp = (FILE *)b->ptr;
+ } else { /* avoid returning internal FILE * to the app */
+ *fpp = NULL;
+ ret = 0;
+ }
}
break;
case BIO_CTRL_GET_CLOSE:
diff --git a/doc/man3/BIO_s_file.pod b/doc/man3/BIO_s_file.pod
index 5dcd4bbbca..6cd1da02a3 100644
--- a/doc/man3/BIO_s_file.pod
+++ b/doc/man3/BIO_s_file.pod
@@ -14,8 +14,8 @@ BIO_rw_filename - FILE bio
BIO *BIO_new_file(const char *filename, const char *mode);
BIO *BIO_new_fp(FILE *stream, int flags);
- BIO_set_fp(BIO *b, FILE *fp, int flags);
- BIO_get_fp(BIO *b, FILE **fpp);
+ long BIO_set_fp(BIO *b, FILE *fp, int flags);
+ long BIO_get_fp(BIO *b, FILE **fpp);
int BIO_read_filename(BIO *b, char *name);
int BIO_write_filename(BIO *b, char *name);
@@ -87,8 +87,7 @@ BIO_s_file() returns the file BIO method.
BIO_new_file() and BIO_new_fp() return a file BIO or NULL if an error
occurred.
-BIO_set_fp() and BIO_get_fp() return 1 for success or <=0 for failure
-(although the current implementation never return 0).
+BIO_set_fp() and BIO_get_fp() return 1 for success or <=0 for failure.
BIO_seek() returns 0 for success or negative values for failure.