Skip to content

Commit

Permalink
Handle open(NULL).
Browse files Browse the repository at this point in the history
Fixes #3865
  • Loading branch information
khuey committed Nov 1, 2024
1 parent 03771cd commit 50bbbbd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ set(BASIC_TESTS
numa
x86/old_fork
orphan_process
open_null
openat2
packet_mmap_disable
x86/patch_syscall_restart
Expand Down
2 changes: 1 addition & 1 deletion src/preload/syscallbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2532,7 +2532,7 @@ static long sys_open(struct syscall_info* call) {

assert(syscallno == call->no);

if (!supported_open(pathname, flags)) {
if (!pathname || !supported_open(pathname, flags)) {
return traced_raw_syscall(call);
}

Expand Down
5 changes: 3 additions & 2 deletions src/record_syscall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6861,8 +6861,9 @@ static void rec_process_syscall_arch(RecordTask* t,
Registers r = t->regs();
if (r.syscall_failed()) {
uintptr_t path = syscallno == Arch::open ? r.orig_arg1() : r.arg2();
string pathname = t->read_c_str(remote_ptr<char>(path));
if (is_gcrypt_deny_file(pathname.c_str())) {
bool ok = false;
string pathname = t->read_c_str(remote_ptr<char>(path), &ok);
if (ok && is_gcrypt_deny_file(pathname.c_str())) {
fake_gcrypt_file(t, &r);
t->set_regs(r);
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/open_null.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */
#include "util.h"
#include <unistd.h>

int main(void) {
// Use syscall(2) because the glibc prototype for open(2) might enforce that
// it's nonnull.
int fd = syscall(SYS_open, NULL, O_RDONLY);
test_assert(fd == -1);
atomic_puts("EXIT-SUCCESS");
return 0;
}

0 comments on commit 50bbbbd

Please sign in to comment.