? diff ? epoll.patch ? fd.patch ? x ? xx ? none/tests/exec-sigmask ? none/tests/insn_mmx ? none/tests/insn_sse ? none/tests/insn_sse2 ? none/tests/syscall-restart1 ? none/tests/syscall-restart2 ? none/tests/tls ? tests/cputest Index: coregrind/vg_syscalls.c =================================================================== RCS file: /home/kde/valgrind/coregrind/vg_syscalls.c,v retrieving revision 1.84 diff -u -3 -p -r1.84 vg_syscalls.c --- coregrind/vg_syscalls.c 12 Feb 2004 14:34:14 -0000 1.84 +++ coregrind/vg_syscalls.c 14 Feb 2004 15:15:14 -0000 @@ -2142,9 +2142,15 @@ PRE(fcntl) POST(fcntl) { - if (arg2 == VKI_F_DUPFD) - if (VG_(clo_track_fds)) - record_fd_open(tid, res, VG_(resolve_filename)(res)); + if (arg2 == VKI_F_DUPFD) { + if (!fd_allowed(res, "fcntl(DUPFD)", tid)) { + VG_(close)(res); + res = -VKI_EMFILE; + } else { + if (VG_(clo_track_fds)) + record_fd_open(tid, res, VG_(resolve_filename)(res)); + } + } } PRE(fchdir) @@ -2175,9 +2181,15 @@ PRE(fcntl64) POST(fcntl64) { - if (arg2 == VKI_F_DUPFD) - if(VG_(clo_track_fds)) - record_fd_open(tid, res, VG_(resolve_filename)(res)); + if (arg2 == VKI_F_DUPFD) { + if (!fd_allowed(res, "fcntl64(DUPFD)", tid)) { + VG_(close)(res); + res = -VKI_EMFILE; + } else { + if (VG_(clo_track_fds)) + record_fd_open(tid, res, VG_(resolve_filename)(res)); + } + } } PRE(fstat) @@ -3852,7 +3864,7 @@ POST(open) VG_(close)(res); res = -VKI_EMFILE; } else { - if(VG_(clo_track_fds)) + if (VG_(clo_track_fds)) record_fd_open(tid, res, VG_(arena_strdup)(VG_AR_CORE, (Char*)arg1)); } MAYBE_PRINTF("%d\n",res); @@ -3896,7 +3908,7 @@ POST(creat) VG_(close)(res); res = -VKI_EMFILE; } else { - if(VG_(clo_track_fds)) + if (VG_(clo_track_fds)) record_fd_open(tid, res, VG_(arena_strdup)(VG_AR_CORE, (Char*)arg1)); } MAYBE_PRINTF("%d\n",res); @@ -3921,7 +3933,7 @@ POST(pipe) res = -VKI_EMFILE; } else { VG_TRACK( post_mem_write, arg1, 2*sizeof(int) ); - if(VG_(clo_track_fds)) { + if (VG_(clo_track_fds)) { record_fd_open(tid, p[0], NULL); record_fd_open(tid, p[1], NULL); } @@ -4465,21 +4477,31 @@ POST(socketcall) switch (arg1 /* request */) { - case SYS_SOCKETPAIR: - /* XXX TODO: check return fd against VG_(max_fd) */ + case SYS_SOCKETPAIR: { VG_TRACK( post_mem_write, ((UInt*)arg2)[3], 2*sizeof(int) ); - if(VG_(clo_track_fds)) { - record_fd_open(tid, ((UInt*)((UInt*)arg2)[3])[0], NULL); - record_fd_open(tid, ((UInt*)((UInt*)arg2)[3])[1], NULL); + fd1 = ((UInt*)((UInt*)arg2)[3])[0]; + fd2 = ((UInt*)((UInt*)arg2)[3])[1]; + if (!fd_allowed(fd1, "socketcall.socketpair", tid) || + !fd_allowed(fd2, "socketcall.socketpair", tid)) { + VG_(close)(fd1); + VG_(close)(fd2); + res = -VKI_EMFILE; + } else { + VG_TRACK( post_mem_write, ((UInt*)arg2)[3], 2*sizeof(int) ); + if (VG_(clo_track_fds)) { + record_fd_open(tid, fd1, NULL); + record_fd_open(tid, fd2, NULL); + } } break; + } case SYS_SOCKET: if (!fd_allowed(res, "socket", tid)) { VG_(close)(res); res = -VKI_EMFILE; } else { - if(VG_(clo_track_fds)) + if (VG_(clo_track_fds)) record_fd_open(tid, res, NULL); } break; @@ -4505,7 +4527,7 @@ POST(socketcall) if (addr_p != (Addr)NULL) buf_and_len_post_check ( tid, res, addr_p, addrlen_p, "socketcall.accept(addrlen_out)" ); - if(VG_(clo_track_fds)) + if (VG_(clo_track_fds)) record_fd_open(tid, res, NULL); } break; @@ -4901,8 +4923,18 @@ POST(futex) { if (!VG_(is_kerror)(res)) { VG_TRACK( post_mem_write, arg1, sizeof(int) ); - if (arg2 == VKI_FUTEX_FD && VG_(clo_track_fds)) - record_fd_open(tid, res, NULL); +// if (arg2 == VKI_FUTEX_FD && VG_(clo_track_fds)) +// record_fd_open(tid, res, NULL); + if (arg2 == VKI_FUTEX_FD) + if (!fd_allowed(res, "futex", tid)) { + VG_(close)(res); + // XXX: futex() can't return EMFILE? + res = -VKI_EMFILE; + } else { + if (VG_(clo_track_fds)) + record_fd_open(tid, res, VG_(arena_strdup)(VG_AR_CORE, (Char*)arg1)); + } + } } }