Skip to content

fix: use zval_get_long() to read value of FTP context option "overwrite" #11332

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

Closed
wants to merge 2 commits into from

Conversation

JonasQuinten
Copy link
Contributor

The FTP context option "overwrite" is read directly via Z_LVAL_P without performing a type check or conversion. Because of this, the option only works reliably if it's set to an integer or if it's absent (defaulting to false), while setting it explicitly to false or null will likely allow overwriting and setting it to true has a small chance of disabling it.

I tried to implement the behavior as described in the commit that added the option (cb89565):

Allow overwriting of files via ftp:// wrapper.
Requires context option:  $context['ftp']['overwrite'] != 0

@nielsdos
Copy link
Member

Thanks for your interest in fixing this. This definitely looks like a bug. You might want to use zend_is_true(zval*) instead though because it's explicitly meant for getting a true/false boolean from a zval.

@JonasQuinten
Copy link
Contributor Author

I used zval_get_long because of the commit message, but I agree that zend_is_true is preferable. It also better matches the documentation that way.

@nielsdos
Copy link
Member

I think this looks good, and CI agrees, thanks for updating.
Are you able to also add a test?
Also, is there a reason you put this as a draft PR?

@JonasQuinten
Copy link
Contributor Author

Yeah, I'll try to add a test.
And there isn't really a reason for this to be a draft.

@nielsdos
Copy link
Member

@JonasQuinten I'm okay with taking this patch as-is without dedicated test, since it's a very small patch and there is identical code doing it correctly. Do you still like to provide a testcase?

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nielsdos While a test case is preferable, this should be fine merging without one.

@nielsdos nielsdos self-assigned this Jun 27, 2023
@nielsdos nielsdos closed this in 1d369a8 Jun 27, 2023
@nielsdos
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants