Skip to content

Commit 567ad44

Browse files
authored
Fix UB in fcntl.c (#24140)
Fixes: #24098
1 parent 5b5497f commit 567ad44

File tree

1 file changed

+10
-4
lines changed
  • system/lib/libc/musl/src/fcntl

1 file changed

+10
-4
lines changed

system/lib/libc/musl/src/fcntl/fcntl.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,28 @@
33
#include <stdarg.h>
44
#include <errno.h>
55
#include "syscall.h"
6+
#include <emscripten/console.h>
67

7-
#ifdef __EMSCRIPTEN__
8-
__attribute__((no_sanitize("address")))
9-
#endif
108
int fcntl(int fd, int cmd, ...)
119
{
12-
unsigned long arg;
10+
#ifdef __EMSCRIPTEN__
1311
// XXX Emscripten: According to the va_arg man page it is undefined behaviour to
1412
// read arguments that are not passed. This can lead to a false positive
1513
// in SAFE_HEAP, so avoid it.
14+
unsigned long arg = 0;
1615
if (cmd != F_GETFL && cmd != F_GETFD && cmd != F_GETOWN) {
1716
va_list ap;
1817
va_start(ap, cmd);
1918
arg = va_arg(ap, unsigned long);
2019
va_end(ap);
2120
}
21+
#else
22+
unsigned long arg;
23+
va_list ap;
24+
va_start(ap, cmd);
25+
arg = va_arg(ap, unsigned long);
26+
va_end(ap);
27+
#endif
2228
if (cmd == F_SETFL) arg |= O_LARGEFILE;
2329
if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, (void *)arg);
2430
if (cmd == F_GETOWN) {

0 commit comments

Comments
 (0)