Skip to content

Commit

Permalink
fix bug in (and test) futimesat
Browse files Browse the repository at this point in the history
  • Loading branch information
droundy committed Mar 19, 2017
1 parent bc70597 commit b8d1904
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bigbro-linux.c
Expand Up @@ -369,7 +369,7 @@ static int save_syscall_access(pid_t child, rw_status *h) {
int retval = wait_for_return_value(child, h);
debugprintf("%d: %s(%d, '%s') -> %d\n", child, name,
dirfd, arg, retval);
if (retval >= 0) read_file_at(child, dirfd, arg, h);
if (retval >= 0) write_file_at(child, dirfd, arg, h);
free(arg);
} else {
int retval = wait_for_return_value(child, h);
Expand Down
34 changes: 34 additions & 0 deletions tests/futimesat.c
@@ -0,0 +1,34 @@
#define _POSIX_C_SOURCE 200809L
#define _GNU_SOURCE

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>

// NOTE: futimesat is obsolete (in favor of utimesat), but we should
// still support any programs that might use it.

int main() {
int subd = openat(AT_FDCWD, "tmp/subdir1", O_RDONLY | O_DIRECTORY);
struct timeval *ts = NULL;

// the following should all fail, but should also not cause a crash
// that would prevent the following utimensat from being traced.
futimesat(subd, "foo_symlink_typo", ts);
// The following is a way to silence a warning on using a null
// pointer here. We are intentionally giving a bad value to ensure
// it doesn't screw up bigbro.
char *mynull = ((char *)5) - 5;
futimesat(subd, mynull, ts);
futimesat(subd, "", ts);

int retval = futimesat(subd, "foo_symlink", ts);
if (retval < 0) {
perror("trouble");
}
printf("retval was %d\n", retval);
return 0;
}
14 changes: 14 additions & 0 deletions tests/futimesat.py
@@ -0,0 +1,14 @@
import re

import tests.helper as th

def passes(out, err):
return all(
[th.reads(err, '/tests/futimesat.test'),
th.writes(err, '/tmp/foo'),
th.count_writes(err, 1),
th.count_readdir(err, 0),
])

needs_symlinks = False
skip_windows = True

0 comments on commit b8d1904

Please sign in to comment.