aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenjiro Nakayama <nakayamakenjiro@gmail.com>2026-03-08 16:45:26 +0900
committerKenjiro Nakayama <nakayamakenjiro@gmail.com>2026-03-08 16:45:26 +0900
commite5dcc309e7dcdf7c08a656fe31e76f7304556459 (patch)
treee50364d5b55d35e18a5a0707c1cf2ac9d131b5cd
parentb9277f6c1fa17f21b932e7a5a76eeed16d4c456f (diff)
downloadportable-e5dcc309e7dcdf7c08a656fe31e76f7304556459.tar.gz
portable-e5dcc309e7dcdf7c08a656fe31e76f7304556459.tar.bz2
portable-e5dcc309e7dcdf7c08a656fe31e76f7304556459.zip
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
-rw-r--r--crypto/compat/posix_win.c3
1 files changed, 3 insertions, 0 deletions
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, ...)
89 flags &= ~O_NONBLOCK; 89 flags &= ~O_NONBLOCK;
90 90
91 const int fh = open(path, flags, mode); 91 const int fh = open(path, flags, mode);
92 if (fh < 0) {
93 return fh;
94 }
92 95
93 // Set high bit to mark file descriptor as a file handle 96 // Set high bit to mark file descriptor as a file handle
94 return fh + 0x80000000; 97 return fh + 0x80000000;