mysqli blank error
Description
The following code:
$string ="<?php error_reporting(E_ALL ^ E_STRICT); ini_set('display_errors', 1); require_once '".SITEPATH ."/model/settings.php'; require_once '".SITEPATH ."/model/table_class.php';require_once '".SITEPATH ."/components/site/page.php';";
$string .="\$pages = new PageClass;\$class_page = \$pages->load((int)".$this->variables['page_id'].");?>";
file_put_contents(SITEPATH."/uploads/test.php", $string);
$result = exec( "php '".SITEPATH."/uploads/test.php' 2>&1");
<?php
Resulted in this output:
thrown in /var/www/vhosts/rhaindustry.com/httpdocs/model/settings.php on line 58
Original the line was $mysqli = new mysqli(SITE_DB_HOST, SITE_DB_USER, SITE_DB_PASS, SITE_DB_NAME);
I changed it to mysqli_report( MYSQLI_REPORT_OFF ); based on suggestions I read, but I still received the same blank error, and now it is giving me the blank error with that line.
But I expected this output instead:
Nothing. The website is working without an errors, it's just when I ran my script to run through the site via exec after upgrading to 8.1 to find any errors, that I found this blank error.
I have never seen a blank error in my life.
PHP Version
PHP 8.1
Operating System
Ubuntu 20.04
Putting aside my terror at the code you've shown us,
The error message indicates line 58 in settings.php. You have not posted settings.php. We can't show you what the problem is unless we can see that... but my guess is that you put your call to mysqli_report in the wrong place: it has to go before the source of the error, not after.
Given that this is a bug tracker, you may want to consider these options for more support.
I thought I was rather direct in my message. I sent you the exact line where the issue was and then reported how the given solution online was to put mysqli_report( MYSQLI_REPORT_OFF ); and that gave the same exact blank error.
You might think that what you have given us is enough to reproduce the error, but unfortunately it's not. The code is not executable on its own. It's also very messy and difficult to read. We don't really understand what result you are seeing or what it has to do with mysqli_report( MYSQLI_REPORT_OFF );. "I have never seen a blank error in my life." is not a valid bug report. We haven't seen it either and unless you can share with us code that can reproduce it successfully, we probably won't.
You might try an online executable to see if it can be reproduced there. e.g. https://phpize.online/
However, we require MCVE that we can copy and run under the specified operating system. It can't be just some code taken out of a class without any context. Are all these requires necessary to reproduce the problem? Why didn't you share these files? Please limit the code to the minimum code that will show that error and then make sure that we can execute it ourselves without seeing your project.
To simplify, this will give a blank error
$string = "<?php error_reporting(E_ALL ^ E_STRICT); ini_set('display_errors', 1); mysqli_report( MYSQLI_REPORT_OFF ); ?>";
file_put_contents(SITEPATH."/uploads/test.php", $string);
$result = exec( "php '".SITEPATH."/uploads/test.php' 2>&1");
To clarify I am not receiving the error when accessing a page directly, it's only when I run exec through the command line that I receive it.
Ok, I am confused. I keep looking at this code and I have no idea what output I am expecting. What is a "blank error"? Can you post a screenshot please?
Well yea, if you don't have an uploads folder on your machine. file_put_contents('test.php'): That should work assuming you have permissions from PHP to create the file in the home directory. Otherwise need to specify a directory and give it permissions for www-data. With that script the result I received when running the exec is "thrown in test.php on line 1"
https://www.php.net/manual/en/function.exec.php
Return Values
The last line from the result of the command.
Duh, so there should be something like echo $result in that code. That makes much more sense...
Before 8.1 there was no blank error when executing that line, I have been executing that code for 10 years to do a bug check of every page. The reason being is when you have a production environment and you have error reporting turned off as it exposes code, you want to run the script to check everything. Hence my bug report of this is happening. You have to admit wtf is a blank warning being caused from calling a mysqli function.
- You should never have error reporting turned off in production. You should have
display_errors = 0in production and you should log the errors instead. - You misidentified the error. It does not come from the code you posted. If you check the full error message you will see that the message is pointing to one of the mysqli functions.
- In PHP 8.1 the default error reporting mode in mysqli changed from silent to exceptions. This is why you haven't seen the error before, you were silencing them all. The error was always there.
- Retrieving just the last line of the output is not going to help you identify problems.
exechas the out-parameter called$output. Use that.
Ok, I just have to stay, have you studied the OWASP top 10, one of the first things is to disable all errors on production because it exposes code. Of course I have a test server with error warnings. But when I do a major update, PHP 8.0 to PHP 8.1 for example, I run the script to parse all the code and find any errors. Hence in the code I sent turning on all errors. In my report of the issue, YES I read that you turn the MYSQLI reporting to off to repress it, my point in the error post is even just using the function of turning it off, when you run it from the exec command it is giving a blank error and it should not be happening. I will reiterate the site is fully functional after the upgrade, you only encounter this when running it from the command line and it should NOT be happening.
have you studied the OWAPS top 10, one of the first things is to disable all errors on production because it exposes code.
The OWASP cheatsheet for PHP supports what I have said. You absolutely should have error reporting enabled in production and it will not expose code to users. IF you have display_errors enabled though, it might expose backtrace and even parameter values.
you only encounter this when running it from the command line and it should NOT be happening.
Not sure what you mean, but we don't see any bug from your description. PHP seems to be working as designed and is throwing the error properly. Whether you want to see that error, just its last line, or nothing at all is up to you. This bug report will remain closed as this seems to be all just a misunderstanding of what exec() returns.
Ugh this is getting ridiculous. Of course the code I sent without the proper write permissions on the server would not be able to write to the file and then it would never get to run the exec and echoing the blank error from the command line. I am a PHP programming veteran of 20 years, I don't make bug report willy nilly. Figure out your permissions, put the code I gave and run it from a PHP script using the exec command.
I am running Ubuntu 20 with all the latest updates, speaking of which, upgrading to PHP 8,0 brought my site to a hault, isset which should never break your code, all the sudden lead to fault errors. I had to update everything to empty, which according to everything I read is the worst thing to do, but it works great for my purposes. Then I did an update 2 weeks ago on PHP 8.0 and all the sudden a few issets I had were now faults and I had to update them to empty. Issets should NEVER result in an error, you are literally asking, can I access this, but if you have an array with a subarray variable, not that is a fault. Like so what if the first array doesn't exist, it shouldn't give a fault and break the code just because you are trying to check for a subarray variable of a variable that does not exist.
Then everything I read, people are saying DO NOT upgrade to PHP 8.0 and definitely do not upgrade to PHP 8.1, it causes too many errors. Luckily I am dealing with closed source code so I can figure out how to deal with it, but the majority of open source code will not work on PHP 8.0 due to these silly changes.
So I have to have an extra server, running on the old version of PHP to run open source software, just because they took things that were warnings to faults. Most of the warnings to faults had nothing to do with security, just willy nilly decisions the developers of PHP made. So now I have to have a seperate old server, which is not fully updated for security issues, just to run the latest open source app, because using the latest PHP and Mysql breaks their code. I'd be like great if the updates really improved security, but they do not.
Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you.
Thank you for your interest in PHP.