Switches the errno check from EINVAL to EFAULT #4
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.
Leaving this here for my future evaluation and for the sake of argument, all manual references are from ARM based OS X:
The manual of errno says the following:
So. Both have a right to exist as valid error numbers for the test case. That being said, in multiple locations I've seen reference to the fact that when
syscall
tosys_write
occurs, if a negative number is returned, it should be considered as the error code.If we refer to the manual of write, we can see that EFAULT fits under the test case:
It fits under the test case because "
iov
ordata
" (iov is outside of our scope but data isn't) and NULL is of course outside of the process's allocated address space.If we have a further look at EINVAL: "[EINVAL] The pointer associated with fildes is negative". We can see a somewhat confusing reference to the pointer associated with filedes being negative, perhaps they are referring to something internal, not sure. But it seems wrong to consider NULL a negative address.
Then there is one other mention for another error case which produces EINVAL: "[EINVAL] The value provided for nbyte exceeds INT_MAX." Which to us is irrelevant in the context of this case.
So as a result, there seems to be no viable way for write to be producing this errno as per the test case mentioned by @JonathanDUFOUR in #3.
My possibly incorrect guess as to why @xtrm-en ended up using EINVAL: as per the POSIX IEEE 1003.1 standard (link to a draft as most seem to be paywalled) - pipes (which are being used to test write) have no offset associated with them and as per line 69801 (
EINVAL case for pwrite()
), it is plausible that seeing an invalid buffer the instructions decided to check for an offset.tl;dr: To be honest I struggle to find the reasoning behind the introduction of the EINVAL test case. I have arguments above for EFAULT. I don't have them for EINVAL.