--- libsandbox/wrappers.c.orig 2006-07-11 21:42:48.000000000 +0200 +++ libsandbox/wrappers.c 2006-07-11 21:51:50.000000000 +0200 @@ -153,6 +153,16 @@ FILE *_name(const char *pathname, const char *mode) \ { \ FILE *result = NULL; \ + int my_errno = errno; \ + struct stat st; \ +\ + if (mode!=NULL && mode[0]=='r') { \ + /* If we're trying to read, fail normally if file does not stat */\ + if (-1 == stat(pathname, &st)) { \ + return NULL; \ + } \ + } \ + errno = my_errno; \ \ if FUNCTION_SANDBOX_SAFE_OPEN_CHAR("fopen", pathname, mode) { \ check_dlsym(_name); \ @@ -326,12 +336,20 @@ va_list ap; \ int mode = 0; \ int result = -1; \ + int my_errno = errno; \ + struct stat st; \ \ if (flags & O_CREAT) { \ va_start(ap, flags); \ mode = va_arg(ap, int); \ va_end(ap); \ + } else { \ + /* If we're not trying to create, fail normally if file does not stat */\ + if (-1 == stat(pathname, &st)) { \ + return -1; \ + } \ } \ + errno = my_errno; \ \ if FUNCTION_SANDBOX_SAFE_OPEN_INT("open", pathname, flags) { \ check_dlsym(_name); \ @@ -491,6 +509,16 @@ FILE *_name(const char *pathname, const char *mode) \ { \ FILE *result = NULL; \ + int my_errno = errno; \ + struct stat64 st; \ +\ + if (mode!=NULL && mode[0]=='r') { \ + /* If we're trying to read, fail normally if file does not stat */\ + if (-1 == stat64(pathname, &st)) { \ + return NULL; \ + } \ + } \ + errno = my_errno; \ \ if FUNCTION_SANDBOX_SAFE_OPEN_CHAR("fopen64", pathname, mode) { \ check_dlsym(_name); \ @@ -511,12 +539,20 @@ va_list ap; \ int mode = 0; \ int result = -1; \ + int my_errno = errno; \ + struct stat64 st; \ \ if (flags & O_CREAT) { \ va_start(ap, flags); \ mode = va_arg(ap, int); \ va_end(ap); \ + } else { \ + /* If we're not trying to create, fail normally if file does not stat */\ + if (-1 == stat64(pathname, &st)) { \ + return -1; \ + } \ } \ + errno = my_errno; \ \ if FUNCTION_SANDBOX_SAFE_OPEN_INT("open64", pathname, flags) { \ check_dlsym(_name); \