From cadebfd6398e017addaae4878662aadb42f60bda Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sun, 4 Feb 2024 23:27:14 -0500 Subject: Consistently open files in binary mode on Windows BIO_*_filename, in upstream OpenSSL, opens in binary mode on Windows, not text mode. We seem to have lost those ifdefs in the fork. But since C mandates the 'b' suffix (POSIX just ignores it), apply it consistently to all OSes for simplicity. This fixes X509_FILETYPE_ASN1 in X509_STORE's file-based machinery on Windows. Also fix the various BIO_new_file calls to all specify binary mode. Looking through them, I don't think any of them care (they're all parsing PEM), but let's just apply it across the board so we don't have to think about this. Update-Note: BIO_read_filename, etc., now open in binary mode on Windows. This matches OpenSSL behavior. Change-Id: I7e555085d5c66ad2f205b476d0317570075bbadb Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/66009 Commit-Queue: David Benjamin Reviewed-by: Bob Beck --- include/openssl/bio.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/openssl/bio.h b/include/openssl/bio.h index 33b020b..93f3c0c 100644 --- a/include/openssl/bio.h +++ b/include/openssl/bio.h @@ -492,22 +492,26 @@ OPENSSL_EXPORT int BIO_set_fp(BIO *bio, FILE *file, int close_flag); // BIO_read_filename opens |filename| for reading and sets the result as the // |FILE| for |bio|. It returns one on success and zero otherwise. The |FILE| -// will be closed when |bio| is freed. +// will be closed when |bio| is freed. On Windows, the file is opened in binary +// mode. OPENSSL_EXPORT int BIO_read_filename(BIO *bio, const char *filename); // BIO_write_filename opens |filename| for writing and sets the result as the // |FILE| for |bio|. It returns one on success and zero otherwise. The |FILE| -// will be closed when |bio| is freed. +// will be closed when |bio| is freed. On Windows, the file is opened in binary +// mode. OPENSSL_EXPORT int BIO_write_filename(BIO *bio, const char *filename); // BIO_append_filename opens |filename| for appending and sets the result as // the |FILE| for |bio|. It returns one on success and zero otherwise. The -// |FILE| will be closed when |bio| is freed. +// |FILE| will be closed when |bio| is freed. On Windows, the file is opened in +// binary mode. OPENSSL_EXPORT int BIO_append_filename(BIO *bio, const char *filename); // BIO_rw_filename opens |filename| for reading and writing and sets the result // as the |FILE| for |bio|. It returns one on success and zero otherwise. The -// |FILE| will be closed when |bio| is freed. +// |FILE| will be closed when |bio| is freed. On Windows, the file is opened in +// binary mode. OPENSSL_EXPORT int BIO_rw_filename(BIO *bio, const char *filename); // BIO_tell returns the file offset of |bio|, or a negative number on error or -- cgit v1.1