Skip to content

Commit eea3a60

Browse files
committed
gh-124621: Emscripten: Fix regression in use-after-close error handling
Introduced in GH-136822. If the fd is already closed, `SYSCALLS.getStreamFromFD()` throws an error. We need to catch it and discard it. The `__wasi_fd_read_orig()` fallback will use it to set errno.
1 parent 7ae4749 commit eea3a60

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Python/emscripten_syscalls.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,17 @@ EM_JS_MACROS(__externref_t, __maybe_fd_read_async, (
148148
size_t iovcnt,
149149
__wasi_size_t *nread
150150
), {
151-
var stream = SYSCALLS.getStreamFromFD(fd);
152151
if (!WebAssembly.promising) {
153152
return null;
154153
}
154+
var stream;
155+
try {
156+
stream = SYSCALLS.getStreamFromFD(fd);
157+
} catch (e) {
158+
// If the fd was already closed or never existed, getStreamFromFD()
159+
// raises. We'll let fd_read_orig() handle setting errno.
160+
return null;
161+
}
155162
if (!stream.stream_ops.readAsync) {
156163
// Not an async device. Fall back to __wasi_fd_read_orig().
157164
return null;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy