Don't canonicalize named file descriptors that reference special objects.

Named file descriptors may reference special objects like pipes,
sockets, inodes, ...  Such objects do not belong to the file-system.
This commit is contained in:
Cédric VINCENT 2014-06-27 09:27:50 +02:00
parent a8791f4e68
commit 564b2e6bdc
3 changed files with 43 additions and 0 deletions

View File

@ -412,6 +412,12 @@ int translate_path(Tracee *tracee, char result[PATH_MAX], int dir_fd,
if (status < 0) if (status < 0)
return status; return status;
/* Named file descriptors may reference special
* objects like pipes, sockets, inodes, ... Such
* objects do not belong to the file-system. */
if (result[0] != '/')
return -ENOTDIR;
/* Remove the leading "root" part of the base /* Remove the leading "root" part of the base
* (required!). */ * (required!). */
status = detranslate_path(tracee, result, NULL); status = detranslate_path(tracee, result, NULL);

View File

@ -70,6 +70,9 @@ check-test-a3e68988.c: test-a3e68988
@which gdb >/dev/null 2>&1 || rm -f $< @which gdb >/dev/null 2>&1 || rm -f $<
$(call check_c,$<,$(PROOT) gdb -return-child-result -ex run -ex quit ./$<) $(call check_c,$<,$(PROOT) gdb -return-child-result -ex run -ex quit ./$<)
check-test-fdf487a0.c: test-fdf487a0
$(call check_c,$<,echo test | $(PROOT) ./$<)
check_c = $(Q)if [ -e $< ]; then \ check_c = $(Q)if [ -e $< ]; then \
$(2) $(silently); $(call check,$(1)) \ $(2) $(silently); $(call check,$(1)) \
else \ else \
@ -144,6 +147,9 @@ test-c5a7a0f0: test-c5a7a0f0.c
test-a3e68988: test-a3e68988.c test-a3e68988: test-a3e68988.c
$(Q)$(CC) $< -o $@ $(silently) || true $(Q)$(CC) $< -o $@ $(silently) || true
test-fdf487a0: test-fdf487a0.c
$(Q)$(CC) $< -o $@ $(silently) || true
###################################################################### ######################################################################
# Beautified output # Beautified output

31
tests/test-fdf487a0.c Normal file
View File

@ -0,0 +1,31 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
int fd;
fd = openat(0, "foo", O_RDONLY);
if (fd >= 0 || errno != ENOTDIR) {
printf("1. %d %d\n", fd, (int) errno);
exit(EXIT_FAILURE);
}
fd = openat(0, "", O_RDONLY);
if (fd >= 0 || errno != ENOENT) {
printf("2. %d %d\n", fd, (int) errno);
exit(EXIT_FAILURE);
}
fd = openat(0, NULL, O_RDONLY);
if (fd >= 0 || errno != EFAULT) {
printf("3. %d %d\n", fd, (int) errno);
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}