Skip to content

Implement script only include #1111

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 8 commits into from

Conversation

yohgaki
Copy link
Contributor

@yohgaki yohgaki commented Feb 22, 2015

https://wiki.php.net/rfc/script_only_include

I used memcmp() to compare file extension. It's better to use strcasecmp for windows, probably. Use #if ?

I also used E_COMPILE_ERROR for now. If it's OK to use E_ERROR/E_RECVERABLE_ERROR in zend_language_scanner.[cl], I'll change.

I'll treat failing tests later.

@@ -130,6 +130,8 @@ struct _zend_compiler_globals {

HashTable interned_strings;

char *script_extensions[32];
Copy link
Contributor

Choose a reason for hiding this comment

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

this (32) should be a constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. Do you have suggested name? If so, I just use yours.

@smalyshev
Copy link
Contributor

Don't see the move_uploaded_file() part.

@@ -5682,13 +5683,40 @@ PHP_FUNCTION(is_uploaded_file)
}
/* }}} */


static int php_check_filename_extensions(zend_string *filename) { /* {{{ */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This may be implemented as ZEND_API in Zend.

@yohgaki
Copy link
Contributor Author

yohgaki commented Feb 23, 2015

I found what's wrong in ZTS build. It seems I have to relocate script_extensions array to somewhere accessible. CG is not accessible under ZTS build according to gdb.

Where would be the best place to locate script_extensions char array?
EG? or make CG available like non-ZTS build?

if (new_value && new_value->len) {
tmp = str = estrndup(new_value->val, new_value->len);
for(str = new_value->val, i = 0; ; str = NULL) {
token = strtok_r(str, " ", &save_ptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

please use php_strtok_r

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, also seems save_ptr isn't initialized here.

@Igknighted
Copy link

I was bored and read through the RFC and I feel like this feature addresses a problem that doesn't exist if the PHP "developer" did their job right. This RFC is merely adding another already implemented feature.

Maybe I'm mistaken or missing something, there doesn't seem to be any added value to PHP by implementing this.

break;
}
p = Z_STRVAL_P(filename) + Z_STRLEN_P(filename) - len;
if (!memcmp(p, CG(script_extensions)[i], len)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you're using case sensitive match here. Are you sure it won't break on case-insensitive filesystems?

@awalgarg
Copy link

awalgarg commented Mar 7, 2015

Umm.. not sure if this is the right place but won't it be better to change the behavior to the way other programming languages do it as pointed out in the RFC? As in include foo should be used and php would try to include foo.php. It would break backwards compatibility so having an ini option would make sense?

Just my 2 cents.. :)

@smalyshev
Copy link
Contributor

RFC vote seems to be declined, can we close this?

@nikic nikic closed this Apr 2, 2015
@Kubo2
Copy link
Contributor

Kubo2 commented Apr 11, 2015

@yohgaki 'Just note that it is programmer's problem, if he doesn't write security invulnerable code, not a problem of the language.

So 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants