Commit 42517c886a for openssl.org

commit 42517c886a25f9f2a9cd659f5987d78fde77be20
Author: Igor Ustinov <igus@openssl.foundation>
Date:   Fri Aug 14 15:24:08 2026 +0200

    Bugfix in the file BIO - avoiding false negatives based on previous errno.

    Base on the idea of @Rydier.

    Fixes #32179

    Reviewed-by: Richard Levitte <levitte@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
    Merge-date: Wed Aug 19 11:03:35 2026
    Merged-from: https://github.com/openssl/openssl/pull/32382

diff --git a/crypto/bio/bss_file.c b/crypto/bio/bss_file.c
index 7aed585342..e01cd3ba99 100644
--- a/crypto/bio/bss_file.c
+++ b/crypto/bio/bss_file.c
@@ -182,6 +182,9 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
     FILE **fpp;
     char p[4];
     int st;
+#if defined(OPENSSL_SYS_WINDOWS)
+    int oldErr;
+#endif

     switch (cmd) {
     case BIO_C_FILE_SEEK:
@@ -198,6 +201,10 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
          * so we map the 0:non-0 return value here to 0:1 with a
          * double negation
          */
+#if defined(OPENSSL_SYS_WINDOWS)
+        oldErr = errno;
+        errno = 0;
+#endif
         if (b->flags & BIO_FLAGS_UPLINK_INTERNAL)
             ret = !!(long)UP_feof(fp);
         else
@@ -211,6 +218,8 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
          */
         if (ret == 0 && errno == EINVAL)
             ret = -EINVAL;
+        else if (errno == 0)
+            errno = oldErr;
 #endif
         break;
     case BIO_C_FILE_TELL: