Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure text mode file BIOs are buffered on Windows #24249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions crypto/bio/bss_file.c
Expand Up @@ -85,6 +85,11 @@ BIO *BIO_new_file(const char *filename, const char *mode)
/* we did fopen -> we disengage UPLINK */
BIO_clear_flags(ret, BIO_FLAGS_UPLINK_INTERNAL);
BIO_set_fp(ret, file, fp_flags);
#if defined(OPENSSL_SYS_WINDOWS)
/* see corresponding setvbuf call */
if ((fp_flags & BIO_FP_TEXT) != 0)
ret = BIO_push(BIO_new(BIO_f_buffer()), ret);
#endif
return ret;
}

Expand Down Expand Up @@ -241,6 +246,8 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
* https://developercommunity.visualstudio.com/content/problem/425878/fseek-ftell-fail-in-text-mode-for-unix-style-text.html
* The suggested work-around from Microsoft engineering is to
* turn off buffering until the bug is resolved.
* When this is removed, removing the corresponding BIO_f_buffer
* call in BIO_new_file.
*/
if ((num & BIO_FP_TEXT) != 0)
setvbuf((FILE *)ptr, NULL, _IONBF, 0);
Expand Down