Bug #23253
closedintExplode somehow returns comma-containing string values
0%
Description
An strange uncaugt exception error happens sometime during felogin.
We get the following error backtrace during login (see attached error.png).
Looking at the code, there should never be string values or commas in the meberGroups array.
/**
* Creating where-clause for checking group access to elements in enableFields function
*
* @param string Field with group list
* @param string Table name
* @return string AND sql-clause
* @see enableFields()
*/
function getMultipleGroupsWhereClause($field, $table) {
$memberGroups = t3lib_div::intExplode(',',$GLOBALS['TSFE']->gr_list);
$orChecks=array();
$orChecks[]=$field.'=\'\''; // If the field is empty, then OK
$orChecks[]=$field.' IS NULL'; // If the field is NULL, then OK
$orChecks[]=$field.'=\'0\''; // If the field contsains zero, then OK
foreach($memberGroups as $value) {
$orChecks[] = $GLOBALS['TYPO3_DB']->listQuery($field, $value, $table);
}
return ' AND ('.implode(' OR ',$orChecks).')';
}
(issue imported from #M15211)
Files
Updated by Björn Pedersen over 14 years ago
A better look at the code gave an other idea:
we are passing numeric values to the strpos function, which expect strings.
if the value matches the charcode of ',', we get a false positive.
can be tested with the following in t3lib_DivTest.php:
/**
* @test
*/
public function checkStrposWithIntegers() {
$testarray = array(ord(','),10,20);
$checkarray = array(',',',',',');
$expectedArray = array(false, false,false );
$actualArray = array_map(strpos,$checkarray,$testarray);
$this->assertEquals($expectedArray, $actualArray);
}
Updated by Björn Pedersen over 14 years ago
possible fixes:
1) run the value through stringval in t3lib_db->listquery if it is not a string
2) only pass strings to t3lib_db->listquery
3) check for comma only for strings.
my prefered solution would be 1.
the following testcase runs clean:
public function checkStrposWithIntegers2() {
$testarray = array(ord(','),10,20);
$checkarray = array(',',',',',');
$expectedArray = array(false, false,false );
$testarray2=array_map(strval,$testarray);
$actualArray = array_map(strpos,$checkarray,$testarray2);
$this->assertEquals($expectedArray, $actualArray);
}
Updated by Ernesto Baschny over 14 years ago
Commited v2.diff to trunk (rev. 8259)