From e5dcc309e7dcdf7c08a656fe31e76f7304556459 Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Sun, 8 Mar 2026 16:45:26 +0900 Subject: Avoid integer overflow in posix_open on Windows If open() fails, return the error value immediately. Adding the high bit to -1 results in a large positive integer, which causes callers like tls_config_load_file() to bypass their error checks. Fix https://github.com/libressl/portable/issues/1239 --- crypto/compat/posix_win.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crypto/compat/posix_win.c b/crypto/compat/posix_win.c index 572e527..00d3d82 100644 --- a/crypto/compat/posix_win.c +++ b/crypto/compat/posix_win.c @@ -89,6 +89,9 @@ posix_open(const char *path, ...) flags &= ~O_NONBLOCK; const int fh = open(path, flags, mode); + if (fh < 0) { + return fh; + } // Set high bit to mark file descriptor as a file handle return fh + 0x80000000; -- cgit v1.2.3-55-g6feb