Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Posix Object backend hides object non-existence #93

Open
tilpner opened this issue Feb 24, 2021 · 0 comments
Open

Posix Object backend hides object non-existence #93

tilpner opened this issue Feb 24, 2021 · 0 comments
Assignees

Comments

@tilpner
Copy link
Contributor

tilpner commented Feb 24, 2021

If an object does not exist, this call to open will return -1, but errno is never checked:

open(), openat(), and creat() return the new file descriptor (a nonnegative integer), or -1 if an error occurred (in which case, errno is set appropriately).
– open(2)

https://github.com/julea-io/julea/blob/be6065355938c0e10886466e933c1c99d262b77f/backend/object/posix.c#L206-L210

It then proceeds to initialise the backend object, and returns false. But the return value is ignored, and the object is then passed to other backend operations, as if initialization succeeded:

https://github.com/julea-io/julea/blob/be6065355938c0e10886466e933c1c99d262b77f/server/loop.c#L139-L141

The invalid file descriptor -1 is then passed to pread here, which writes EBADF to errno. This error never reaches the client though, who receives no indication of an error, and doesn't receive any data. It appears to the client, as if the object existed but was empty.

https://github.com/julea-io/julea/blob/be6065355938c0e10886466e933c1c99d262b77f/backend/object/posix.c#L318-L320

With a server posix backend configured, this can be reproduced simply by trying to copy any non-existing object with julea-cli:

$ bld/julea-cli copy object://host/namespace/bar file:///tmp/foo

# in the gdb session attached to julea-server
(gdb) b backend_read
Function "backend_read" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (backend_read) pending.
(gdb) r
Starting program: /home/tilpner/dev/betree/julea/bld/julea-server 
[New LWP 12178]
[New LWP 12393]
[Switching to LWP 12393]

Thread 3 "pool-julea-serv" hit Breakpoint 1, backend_read (backend_data=0x423d00, 
    backend_object=0x7fffdc003250, buffer=0x7fffe8d8d010, length=1048576, offset=0, 
    bytes_read=0x7fffe9d8ce68) at ../backend/object/posix.c:313
313		j_trace_file_begin(bo->path, J_TRACE_FILE_READ);
(gdb) p bo->fd
$1 = -1
# step until after pread
(gdb) p (void(*)(char*))perror("")
Bad file descriptor
$6 = (void (*)(char *)) 0x0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants