-
Notifications
You must be signed in to change notification settings - Fork 8k
Plain stream wrapper: Add assertions to uphold assumptions and remove a dubious API usage #17322
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
Plain stream wrapper: Add assertions to uphold assumptions and remove a dubious API usage #17322
Conversation
def7561
to
30003f5
Compare
30003f5
to
78d365c
Compare
main/streams/plain_wrapper.c
Outdated
if (expand_filepath(filename, realpath) == NULL) { | ||
return NULL; | ||
} | ||
realpath_len = strlen(realpath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might wasteful - it's not used in all paths below. Just keep strlen(realpath)
- this function is not really used so not much point to change it.
main/streams/plain_wrapper.c
Outdated
realpath_len = strlen(filename); | ||
ZEND_ASSERT(realpath_len < sizeof(realpath) && "Assumed real path filename is too long"); | ||
strcpy(realpath, filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an external API so there should be some prevention - you should at least use strncpy if you really need to replace this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can keep the assert but not use only strcpy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strncpy does do padding, which is pointless. Actually, strlcpy here was fine IMO because with the new code we now do two traversals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah good point. Let's close this PR in that case...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just the top one makes sense. I don't really mind. This function is not even used from anywhere in the core - at least I didn't find any usage...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there might still be external usage ofc. as it's public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dropped the first commit
The description of PHP_STRLCPY says that this is a fast version of strlcpy that should be used if we *know* the size of both the source and destination buffers. This is clearly not the case as we use strlen() to compute it. Moreover if the result cannot fit in the destination buffer something seriously strange has happened and we should return a failure state rather than truncating.
78d365c
to
80e6701
Compare
No description provided.