View Issue Details

IDProjectCategoryView StatusLast Update
0029034mantisbtapi soappublic2022-04-13 12:10
ReporterfloREN Assigned Tocommunity  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.25.2 
Target Version2.25.3Fixed in Version2.25.3 
Summary0029034: SOAP call mc_project_get_id_from_name fails when there is no matching project in PHP 7.2
Description

Hello,

I accountered a problem on a SOAP API call on MantisBT 2.25.2 when looking for project id by the project name.

This call fails with a "SYSTEM WARNING" when no project is found with this name.

Exact error message : "Error Description: count(): Parameter must be an array or an object that implements Countable"

It's caused by calling count() on $this->current_row while $this->current_row is null in DbQuery->value().

This Warning is new in PHP 7.2. (See https://www.php.net/manual/fr/function.count.php#refsect1-function.count-changelog)

Steps To Reproduce

Here is a script to reproduce (With PHP 7.2 and PHP Soap) :

<?php
$s = new SoapClient( 'https://localhost/mantis/api/soap/mantisconnect.php?wsdl' );
$u = 'user';
$p = 'password';
$s->mc_project_get_id_from_name($u, $p, 'non-existing-project-name');

Which returns :

PHP Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Server] Error Type: SYSTEM WARNING,
Error Description: count(): Parameter must be an array or an object that implements Countable

Additional Information

I patched core/classes/DbQuery to check for nullity of $this->current_row. It may be sufficient.

TagsNo tags attached.
Attached Files
DbQuery.patch (413 bytes)   
@@ -857,7 +857,8 @@ class DbQuery {
 			$this->fetch();
 		}
 		if( is_numeric( $p_index_or_name ) ) {
-			if( count( $this->current_row ) > $p_index_or_name ) {
+			if( $this->current_row != null && count( $this->current_row ) > $p_index_or_name ) {
 				# get the element at that numerical position
 				$t_keys = array_keys( $this->current_row );
 				$t_value = $this->current_row[$t_keys[$p_index_or_name]];
DbQuery.patch (413 bytes)   

Activities

dregad

dregad

2021-09-01 11:42

developer   ~0065806

Thanks for the bug report and the patch.

Is there any chance you could resubmit your proposed fix as a pull request on Github ? It makes the review and merge process easier for us.

floREN

floREN

2021-09-01 11:58

reporter   ~0065807

I just did it : https://github.com/mantisbt/mantisbt/pull/1779

Is it OK for you ?

dregad

dregad

2021-09-01 12:17

developer   ~0065808

Perfect, thanks !

Related Changesets

MantisBT: master-2.25 52b84403

2021-09-01 07:55

fbruneau

Committer: dregad


Details Diff
Fix PHP warning when calling count() on bool value

PHP Warning: Uncaught TypeError: count(): Argument 0000001 ($value) must be
of type Countable|array, bool given in DbQuery.class.php:860

Occurs when calling DbQuery::value() on a query that executes
successfully but does not return any rows.

Fixes 0029034, PR https://github.com/mantisbt/mantisbt/pull/1779

Signed-off-by: Damien Regad <dregad@mantisbt.org>
(cherry picked from commit 00626687cdfc64dad798d61c8036e6199c0efc0b)
Affected Issues
0029034
mod - core/classes/DbQuery.class.php Diff File

MantisBT: master 00626687

2021-09-01 07:55

fbruneau

Committer: dregad


Details Diff
Fix PHP warning when calling count() on bool value

PHP Warning: Uncaught TypeError: count(): Argument 0000001 ($value) must be
of type Countable|array, bool given in DbQuery.class.php:860

Occurs when calling DbQuery::value() on a query that executes
successfully but does not return any rows.

Fixes 0029034, PR https://github.com/mantisbt/mantisbt/pull/1779

Signed-off-by: Damien Regad <dregad@mantisbt.org>
Affected Issues
0029034
mod - core/classes/DbQuery.class.php Diff File