aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2020-10-20 06:48:10 +0200
committerRichard Levitte <levitte@openssl.org>2020-10-21 08:02:55 +0200
commit8300a8742b2abc487594a09b5e6ee726dbd30771 (patch)
tree19cb8eac9282c4a21607f648fc226c84c25366c3
parent0a737e16b2bc333cc3a8727458acc5460be10e0e (diff)
downloadopenssl-8300a8742b2abc487594a09b5e6ee726dbd30771.zip
openssl-8300a8742b2abc487594a09b5e6ee726dbd30771.tar.gz
openssl-8300a8742b2abc487594a09b5e6ee726dbd30771.tar.bz2
Work around Windows ftell() bug as per Microsoft engineering's suggestion
See https://developercommunity.visualstudio.com/content/problem/425878/fseek-ftell-fail-in-text-mode-for-unix-style-text.html Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/13190)
-rw-r--r--crypto/bio/bss_file.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/crypto/bio/bss_file.c b/crypto/bio/bss_file.c
index a57bd97..986fba8 100644
--- a/crypto/bio/bss_file.c
+++ b/crypto/bio/bss_file.c
@@ -237,6 +237,15 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
_setmode(fd, _O_TEXT);
else
_setmode(fd, _O_BINARY);
+ /*
+ * Reports show that ftell() isn't trustable in text mode.
+ * This has been confirmed as a bug in the Universal C RTL, see
+ * 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.
+ */
+ if ((num & BIO_FP_TEXT) != 0)
+ setvbuf((FILE *)ptr, NULL, _IONBF, 0);
# elif defined(OPENSSL_SYS_MSDOS)
int fd = fileno((FILE *)ptr);
/* Set correct text/binary mode */