root: make readlink return -EINVAL for non-symlinks#378
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
f013ce3 to
1228e80
Compare
In commit 1391acd ("tests: capi: test ptr==NULL and bufsize<=0 cases") we switched to making the starting point of the trucated tests dynamic, which led me to missing the actual_size==1 case (where the capacity and actual_size are 0 after halving actual_size, resulting in zero-length strings instead of one-character strings for the tests). There were also a few other bugs here (such as our Vec::set_len usage) and the whole "test multiple buffer sizes" logic was incredibly implicit and hairy. The solution is just to make all of this more explicit. Fixes: 1391acd ("tests: capi: test ptr==NULL and bufsize<=0 cases") Signed-off-by: Aleksa Sarai <aleksa@amutable.com>
Previously these were only tested within the Root::create tests, which only tested that most basic usecase worked. We should really test error cases and cases where readlink should succeed where resolving should fail (i.e., dangling and looped symlinks). Signed-off-by: Aleksa Sarai <aleksa@amutable.com>
readlink() will return -EINVAL for non-symlinks, but the race-free readlinkat(fd, "") approach returns -ENOENT if fd is not a symlink. This mismatch can very easily cause confusion (in fact, I found this bug while trying to use Root::readlink elsewhere). As -ENOENT cannot be returned from readlinkat(fd, "") for any other reason, map it to -EINVAL to match the API to what users would expect. It's a bit strange the kernel does this, but oh well... Fixes: e5d212d ("root: add readlink method") Signed-off-by: Aleksa Sarai <aleksa@amutable.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
readlink() will return -EINVAL for non-symlinks, but the race-free
readlinkat(fd, "") approach returns -ENOENT if fd is not a symlink. This
mismatch can very easily cause confusion (in fact, I found this bug
while trying to use Root::readlink elsewhere).
As -ENOENT cannot be returned from readlinkat(fd, "") for any other
reason, map it to -EINVAL to match the API to what users would expect.
It's a bit strange the kernel does this, but oh well...
Fixes: e5d212d ("root: add readlink method")
Signed-off-by: Aleksa Sarai aleksa@amutable.com