Skip to content

Commit 517cc86

Browse files
authored
Don't abort on unsuported ioctl() (#17470)
``ioctl`` with unsupported ``request`` or ``argp`` argument now fails with errno ``EINVAL`` instead of aborting the process. Fixes: #13810 Closes: #13872
1 parent e4ccb9a commit 517cc86

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

src/library_syscall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ var SyscallsLibrary = {
252252
if (!stream.tty) return -{{{ cDefine('ENOTTY') }}};
253253
return 0;
254254
}
255-
default: abort('bad ioctl syscall ' + op);
255+
default: return -{{{ cDefine('EINVAL') }}}; // not supported
256256
}
257257
#endif // SYSCALLS_REQUIRE_FILESYSTEM
258258
},

system/lib/wasmfs/syscalls.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,13 +1233,8 @@ int __syscall_ioctl(int fd, int request, ...) {
12331233
// TTY operations that we do nothing for anyhow can just be ignored.
12341234
return -0;
12351235
}
1236-
case TIOCGPGRP:
1237-
case TIOCSPGRP: {
1238-
// TODO We should get/set the group number here.
1239-
return -EINVAL;
1240-
}
12411236
default: {
1242-
abort();
1237+
return -EINVAL; // not supported
12431238
}
12441239
}
12451240
}

test/other/test_ioctl.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2022 The Emscripten Authors. All rights reserved.
3+
* Emscripten is available under two separate licenses, the MIT license and the
4+
* University of Illinois/NCSA Open Source License. Both these licenses can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include <assert.h>
9+
#include <errno.h>
10+
#include <stdio.h>
11+
#include <sys/ioctl.h>
12+
#include <unistd.h>
13+
14+
int main() {
15+
// CLOEXEC is not supported
16+
assert(ioctl(STDOUT_FILENO, FIOCLEX, NULL) == -1);
17+
assert(errno = EINVAL);
18+
19+
puts("success");
20+
return 0;
21+
}

test/other/test_ioctl.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
success

test/test_other.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8414,6 +8414,11 @@ def test_autotools_shared_check(self):
84148414
def test_ioctl_window_size(self):
84158415
self.do_other_test('test_ioctl_window_size.cpp')
84168416

8417+
@also_with_wasmfs
8418+
def test_sys_ioctl(self):
8419+
# ioctl requires filesystem
8420+
self.do_other_test('test_ioctl.c', emcc_args=['-sFORCE_FILESYSTEM'])
8421+
84178422
def test_fd_closed(self):
84188423
self.do_other_test('test_fd_closed.cpp')
84198424

0 commit comments

Comments
 (0)