-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix bug #74866 #2612
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
Fix bug #74866 #2612
Conversation
weltling
left a comment
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.
IMO the usage of DL_LOAD without the previous stat is a better approach. There are cases, where the shared obj doesn't have to be available under the exact path in CWD.
What I was wondering yesterday checking the previous patch, is that there was a code duplication also going into php_ini.c. Probably it could be avoided by grouping the code into reusable functions for better maintanance. Fe I'd see at least these pieces that can be grouped
- build ext basename from ext name
- check whether the given filename looks like ext name
- build the extension path
- load an arbitrary shared lib
OFC the grouping could be done, after the right fix is in place, too.
Thanks.
| return FAILURE; /* Not full path given or extension_dir is not set */ | ||
| } | ||
|
|
||
| /* load dynamic symbol */ |
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.
Better not to duplicate code, but get it into a function.
| err1 = estrdup(err); | ||
| GET_DL_ERROR(); /* free the buffer storing the error */ | ||
| #endif | ||
|
|
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.
After thinking about it, might it make sense to still check whether filename looks like an extension name? Fe like strcmp against PHP_SHLIB_EXT_PREFIX and PHP_SHLIB_SUFFIX. Reason - if it's already an ext filename, it won't produce a weird output like php_php_bz2.dll.dll or bz2.so.so and an error can be signaled immediately. Again, could be still packed into a simple function to use on teh Zend side as well.
|
Oh, looks like I was commenting on an outdated version. |
|
@weltling I just pushed a new version using a new php_attempt_dl_load() function, avoiding duplicates. Can you test this version ? It should fix the issue for PHP extensions. I prefer not to analyze the input arg, trying to determine if it is a filename or an extension name. Issuing an extensive error message, listing every path we tried to load, and the corresponding error messages is clear enough, IMO. I agree it may lead to weird error messages like : 'Unable to load dynamic library 'php_bz2.dll' (tried : c:\php\ext\php_bz2.dll -> No such file or directory, c:\php\ext\php_php_bz2.dll.dll -> No such file or directory)' but the message is easy to understand from the user's POV. |
|
@flaupretre what about the Zend ext part? Seems it has same issue. Otherwise can test right now. Thanks |
ext/standard/dl.c
Outdated
|
|
||
| static void *php_attempt_dl_load(char *path, char **errp) | ||
| { | ||
| char *handle; |
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.
void *handle;
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.
Fixed. Thanks.
| (*errp) = estrdup(err); | ||
| GET_DL_ERROR(); /* free the buffer storing the error */ | ||
| #endif | ||
| } |
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.
return NULL;
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.
Fixed. Thanks.
|
Yeah, this approach could work. The Zend ext part isn't touched yet though. When it's done, i can make a test build for the reporter to test. Need to check same on Linux at least. Thanks. |
|
About the error message - as for me, it simply look weird. If a name looking like Thanks. |
|
I agree it looks weird but analyzing the name would make the logic much more complex. Remember that we'll end up displaying weird names ONLY when nothing can be loaded. And, with the time, as people will use extension names more and more often, weird messages will slowly disappear... |
|
Yeah, OFC handling the err message is not necessary for the bug fix. I'll check with RMs yet, so at least they're aware about this nuance. Ok, so waiting for the Zend part yet, will test and produce a build then. Thanks. |
|
@weltling Just pushed the fix for PHP and Zend extensions. Removed every stat() call, using DL_LOAD() only everywhere. A small detail : test for bug #71273 (tests/basic/bug71273.phpt) failed during appveyor tests. This must be linked to the error message having been modified but I don't see why the pattern does not match. It works on Linux. Unfortunately, as I cannot test the new version on Windows, I cannot see the command output. The command it execs is : "php -n -d html_errors=on -d extension_dir=a/é/w -d extension=php_kartoffelbrei.dll -v 2>&1" If you can check that this test now fails on Windows, run the command, and send me the output, it would help a lot. Thanks. |
main/php_ini.c
Outdated
| } | ||
| /* }}} */ | ||
|
|
||
| static void *attempt_dl_load(char *path, char **errp) |
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.
Why not just export the other one through dl.h?
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 wanted to avoid calling ext/standard from 'main'. As I didn't know if those parts could communicate with eaach other, I did two identical static functions. If a function in ext/standard can be loaded from main, I'll do it.
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.
That's fine, ext/standard cannot be disabled. By that - such a usage is legit, and in fact, there are quite a few of other places doing it in main.
main/php_ini.c
Outdated
| #include "win32/php_registry.h" | ||
| #include "win32/param.h" | ||
| #include "win32/winutil.h" | ||
| #define GET_DL_ERROR() php_win_err() |
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.
These macros should be exported through the dl.h as well.
|
@flaupretre great, except a few comments seems it's close to finish now. I'd suggest to export that function like The failing test in the earlier AppVeyor run was most likely due to the missing return NULL, etc. Visual Studio is a strict compiler, such bugs come out quite quick. The latest CI runs are all green. Local build seems ok so far, too. Need to check the Linux part at least yet. Thanks. |
|
@weltling Just pushed a new version. Hope it matches your suggestions. I created a PHPAPI php_load_shlib() function in ext/standard/dl.c and use it for both PHP and Zend extensions. |
|
I probably won't have a Linux host available for testing this week-end. I'll do it monday morning. |
ext/standard/dl.c
Outdated
| zend_module_entry *(*get_module)(void); | ||
| int error_type, slash_suffix; | ||
| char *extension_dir; | ||
| char *extension_dir, *err1, *err2; |
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 define 'err1' or 'err2', use 'err_one', 'err_two' instead!
What do you think of it?
|
@flaupretre I've just tested on Linux, at first glance looks good. I've also linked a Windows snapshot build with this patch. Waiting for yours and reporters tests yet to proceed further. Thanks. |
|
@flaupretre any news on your side? Thanks. |
|
@weltling Didn't have time for that today. Will test on Linux tomorrow.
|
|
I just applied this in master as 0782a7f. @flaupretre additional verification would still be great. /cc @remicollet Thanks. |
|
@weltling @remicollet Just checked on Linux. Loading PHP and Zend extensions, nominal case and error. Everything looks OK. |
|
Thanks! And great holiday yet :) |
Work in progress