Bug #50378

sql_free_result does not work with all parameters as specified

Added by Robert Vock almost 9 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2013-07-24
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
6.1
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

The method "sql_free_result" of the DatabaseConnection class throws a fatal error when called with the (boolean) result of exec_INSERTquery.

The direct mail extension uses the following code:

$res = $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_dmail_maillog', $insertFields);
$GLOBALS['TYPO3_DB']->sql_free_result($res);

This results in a fatal error because $res is boolean true and sql_free_result asumes it is an object.

The method description of sql_free_result says that it is ok, to call the method with a boolean:

 * @param boolean|\mysqli_result|object $res MySQLi result object / DBAL object

The fix would be to check if the parameter is an object before calling the free-method.
Another "fix" would be to change the method description, but that would leave bugs in extensions which relied on the ability to call sql_free_result with boolean results.

Note: In TYPO3 4.7 sql_free_result would just call mysql_free_result, which would not throw a fatal error, when called with a boolean parameter, but just return false.

#1

Updated by Ernesto Baschny almost 9 years ago

  • Project changed from 329 to TYPO3 Core
#2

Updated by Ernesto Baschny almost 9 years ago

  • Category set to Database API (Doctrine DBAL)
  • Status changed from New to Needs Feedback

This is not a DBAL issue but a general Core issue. So I moved it to the right tracker.

I wonder how this works in 4.7, because first thing sql_free_result does is a:

if ($this->debug_check_recordset($res)) {

and this should then choke (logging errors to sys_log etc) when called without a resource.

What Fatal error do you get?

#3

Updated by Robert Vock almost 9 years ago

debug_check_recordset returns true, if $res is !== FALSE and does not log anything to sys_log

So if $res is true, debug_check_recordset also returns true. (exec_INSERTquery returns true, if the insert succeeded)

The fatal error is:
Fatal error: Call to a member function free() on a non-object in .../typo3/sysext/core/Classes/Database/DatabaseConnection.php on line 1070

#4

Updated by Gerrit Code Review almost 9 years ago

  • Status changed from Needs Feedback to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/22594

#5

Updated by Markus Klein about 8 years ago

  • Is Regression set to No

I'd say that is actually NOT a core bug at all.
Why calling free() at all after an insert??
No resources are allocated for an insert statement.

It is ok to add a check in Core to assure that we ignore boolean values.

#6

Updated by Gerrit Code Review about 8 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/22594

#7

Updated by Gerrit Code Review about 8 years ago

Patch set 1 for branch TYPO3_6-1 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/29413

#8

Updated by Wouter Wolters about 8 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#9

Updated by Benni Mack almost 4 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF