Avoid passing a null value to PHP functions where another type is expected.

PHP 8.1 deprecates this feature.

Closes pull-request #149 and closes #150
This commit is contained in:
Patrick Monnerat 2022-06-01 17:25:34 +02:00 committed by Deon George
parent 5e9b95f9a8
commit 9488fe2ed7
15 changed files with 49 additions and 37 deletions

View File

@ -41,7 +41,7 @@ if (DEBUG_ENABLED)
$www['page'] = new page($app['server']->getIndex()); $www['page'] = new page($app['server']->getIndex());
# See if we can render the command # See if we can render the command
if (trim($www['cmd'])) { if ($www['cmd'] && trim($www['cmd'])) {
# If this is a READ-WRITE operation, the LDAP server must not be in READ-ONLY mode. # If this is a READ-WRITE operation, the LDAP server must not be in READ-ONLY mode.
if ($app['server']->isReadOnly() && ! in_array(get_request('cmd','REQUEST'),$app['readwrite_cmds'])) if ($app['server']->isReadOnly() && ! in_array(get_request('cmd','REQUEST'),$app['readwrite_cmds']))
error(_('You cannot perform updates while server is in read-only mode'),'error','index.php'); error(_('You cannot perform updates while server is in read-only mode'),'error','index.php');

View File

@ -13,7 +13,7 @@ require './common.php';
require LIBDIR.'export_functions.php'; require LIBDIR.'export_functions.php';
$request = array(); $request = array();
$request['dn'] = get_request('dn','GET'); $request['dn'] = get_request('dn','GET',false,'');
$request['format'] = get_request('format','GET',false,get_line_end_format()); $request['format'] = get_request('format','GET',false,get_line_end_format());
$request['scope'] = get_request('scope','GET',false,'base'); $request['scope'] = get_request('scope','GET',false,'base');
$request['exporter_id'] = get_request('exporter_id','GET',false,'LDIF'); $request['exporter_id'] = get_request('exporter_id','GET',false,'LDIF');

View File

@ -19,8 +19,7 @@ if ($_SESSION[APPCONFIG]->getValue('session', 'reCAPTCHA-enable')) {
if ($pass) { if ($pass) {
$user = array(); $user = array();
$user['login'] = get_request('login'); $user['login'] = get_request('login');
$user['password'] = get_request('login_pass'); $user['password'] = get_request('login_pass', 'POST', false, '');
$user['password'] = html_entity_decode($user['password'], ENT_QUOTES);
if ($user['login'] && !strlen($user['password'])) { if ($user['login'] && !strlen($user['password'])) {
system_message(array( system_message(array(

View File

@ -15,8 +15,8 @@ $www['page'] = new page();
$request = array(); $request = array();
$request['componentid'] = get_request('componentid','REQUEST'); $request['componentid'] = get_request('componentid','REQUEST');
$request['hash'] = get_request('hash','REQUEST'); $request['hash'] = get_request('hash','REQUEST',false,'');
$request['password'] = get_request('check_password','REQUEST'); $request['password'] = get_request('check_password','REQUEST',false,'');
$request['action'] = get_request('action','REQUEST'); $request['action'] = get_request('action','REQUEST');
$request['attribute'] = get_request('attr','REQUEST'); $request['attribute'] = get_request('attr','REQUEST');

View File

@ -150,7 +150,7 @@ switch($entry['view']) {
foreach ($sattrs as $attr) { foreach ($sattrs as $attr) {
if (isAjaxEnabled() || (is_null($entry['value']) || ! trim($entry['value']) || $entry['value']==$attr->getName())) { if (isAjaxEnabled() || (is_null($entry['value']) || ! trim($entry['value']) || $entry['value']==$attr->getName())) {
if ((! is_null($entry['value']) && $entry['value']==$attr->getName()) || ! trim($entry['value'])) if (!is_string($entry['value']) || $entry['value']==$attr->getName() || !trim($entry['value']))
$entry['viewed'] = true; $entry['viewed'] = true;
if (isAjaxEnabled() && $entry['value']) if (isAjaxEnabled() && $entry['value'])
@ -380,7 +380,7 @@ switch($entry['view']) {
$desc = $rule->getName(false); $desc = $rule->getName(false);
if (isAjaxEnabled() || (is_null($entry['value']) || ! trim($entry['value']) || $entry['value']==$rule->getName())) { if (isAjaxEnabled() || (is_null($entry['value']) || ! trim($entry['value']) || $entry['value']==$rule->getName())) {
if ((! is_null($entry['value']) && $entry['value']==$rule->getName()) || ! trim($entry['value'])) if (!is_string($entry['value']) || $entry['value']==$rule->getName() || !trim($entry['value']))
$entry['viewed'] = true; $entry['viewed'] = true;
if (null != $rule->getDescription()) if (null != $rule->getDescription())
@ -468,7 +468,7 @@ switch($entry['view']) {
foreach ($socs as $name => $oclass) { foreach ($socs as $name => $oclass) {
if (isAjaxEnabled() || (is_null($entry['value']) || ! trim($entry['value']) || $entry['value']==$oclass->getName())) { if (isAjaxEnabled() || (is_null($entry['value']) || ! trim($entry['value']) || $entry['value']==$oclass->getName())) {
if ((! is_null($entry['value']) && $entry['value']==$oclass->getName()) || ! trim($entry['value'])) if (!is_string($entry['value']) || $entry['value']==$oclass->getName() || !trim($entry['value']))
$entry['viewed'] = true; $entry['viewed'] = true;
if (isAjaxEnabled() && $entry['value']) if (isAjaxEnabled() && $entry['value'])

View File

@ -258,14 +258,14 @@ class PLAAttribute {
} }
} }
public function getValue($i) { public function getValue($i, $default=null) {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
if (isset($this->values[$i])) if (isset($this->values[$i]))
return $this->values[$i]; return $this->values[$i];
else else
return null; return $default;
} }
public function getOldValue($i) { public function getOldValue($i) {

View File

@ -538,7 +538,7 @@ class PageRender extends Visitor {
final protected function drawHiddenValueAttribute($attribute,$i) { final protected function drawHiddenValueAttribute($attribute,$i) {
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__); if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
$val = $attribute->getValue($i); $val = $attribute->getValue($i, '');
printf('<input type="hidden" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" />', printf('<input type="hidden" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" />',
htmlspecialchars($attribute->getName()),$i,htmlspecialchars($attribute->getName()),$i, htmlspecialchars($attribute->getName()),$i,htmlspecialchars($attribute->getName()),$i,
@ -607,7 +607,7 @@ class PageRender extends Visitor {
protected function drawFormReadOnlyValueAttribute($attribute,$i) { protected function drawFormReadOnlyValueAttribute($attribute,$i) {
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__); if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
$val = $attribute->getValue($i); $val = $attribute->getValue($i, '');
printf('<input type="text" class="roval" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" readonly="readonly" />', printf('<input type="text" class="roval" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" readonly="readonly" />',
htmlspecialchars($attribute->getName()),$i,htmlspecialchars($attribute->getName()),$i,htmlspecialchars($val)); htmlspecialchars($attribute->getName()),$i,htmlspecialchars($attribute->getName()),$i,htmlspecialchars($val));
@ -616,7 +616,7 @@ class PageRender extends Visitor {
protected function drawFormReadWriteValueAttribute($attribute,$i) { protected function drawFormReadWriteValueAttribute($attribute,$i) {
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__); if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
$val = $attribute->getValue($i); $val = $attribute->getValue($i, '');
if ($attribute->getHelper() || $attribute->getVerify()) if ($attribute->getHelper() || $attribute->getVerify())
echo '<table cellspacing="0" cellpadding="0" border="0"><tr><td valign="top">'; echo '<table cellspacing="0" cellpadding="0" border="0"><tr><td valign="top">';
@ -720,7 +720,7 @@ class PageRender extends Visitor {
protected function drawFormReadWriteValueDateAttribute($attribute,$i) { protected function drawFormReadWriteValueDateAttribute($attribute,$i) {
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__); if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
$val = $attribute->getValue($i); $val = $attribute->getValue($i, '');
echo '<span style="white-space: nowrap;">'; echo '<span style="white-space: nowrap;">';
printf('<input type="text" class="value" id="new_values_%s_%s" name="new_values[%s][%s]" value="%s" %s%s %s %s/>&nbsp;', printf('<input type="text" class="value" id="new_values_%s_%s" name="new_values[%s][%s]" value="%s" %s%s %s %s/>&nbsp;',
@ -738,7 +738,7 @@ class PageRender extends Visitor {
protected function drawFormReadWriteValueDnAttribute($attribute,$i) { protected function drawFormReadWriteValueDnAttribute($attribute,$i) {
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__); if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
$val = $attribute->getValue($i); $val = $attribute->getValue($i, '');
if ($attribute->getHelper()) if ($attribute->getHelper())
echo '<table cellspacing="0" cellpadding="0"><tr><td valign="top">'; echo '<table cellspacing="0" cellpadding="0"><tr><td valign="top">';
@ -952,7 +952,7 @@ class PageRender extends Visitor {
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__); if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
$server = $this->getServer(); $server = $this->getServer();
$val = $attribute->getValue($i); $val = $attribute->getValue($i, '');
if (trim($val)) if (trim($val))
$enc_type = get_enc_type($val); $enc_type = get_enc_type($val);
@ -974,7 +974,7 @@ class PageRender extends Visitor {
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__); if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
$server = $this->getServer(); $server = $this->getServer();
$val = $attribute->getValue($i); $val = $attribute->getValue($i, '');
$enc_type = get_enc_type($val); $enc_type = get_enc_type($val);
@ -1102,7 +1102,7 @@ class PageRender extends Visitor {
# This is a single value attribute # This is a single value attribute
} else { } else {
$val = $attribute->getValue($i) ? $attribute->getValue($i) : $attribute->getDefault(); $val = $attribute->getValue($i) ? $attribute->getValue($i) : (is_null($attribute->getDefault())? '': $attribute->getDefault());
if ($attribute->getHelper()) if ($attribute->getHelper())
echo '<table cellspacing="0" cellpadding="0"><tr><td valign="top">'; echo '<table cellspacing="0" cellpadding="0"><tr><td valign="top">';

View File

@ -136,7 +136,7 @@ class Query extends xmlTemplate {
$bases = get_request('base','REQUEST',false,null); $bases = get_request('base','REQUEST',false,null);
$query['filter'] = get_request('filter','REQUEST',false,'objectClass=*'); $query['filter'] = get_request('filter','REQUEST',false,'objectClass=*');
$query['scope'] = get_request('scope','REQUEST',false,'sub'); $query['scope'] = get_request('scope','REQUEST',false,'sub');
$attrs = get_request('display_attrs','REQUEST'); $attrs = get_request('display_attrs','REQUEST',false,'');
$attrs = preg_replace('/\s+/','',$attrs); $attrs = preg_replace('/\s+/','',$attrs);
if ($attrs) if ($attrs)

View File

@ -56,7 +56,7 @@ class Template extends xmlTemplate {
# Template RDN attributes # Template RDN attributes
private $rdn; private $rdn;
public function __construct($server_id,$name=null,$filename=null,$type=null,$id=null) { public function __construct($server_id,$name='',$filename=null,$type=null,$id=null) {
parent::__construct($server_id,$name,$filename,$type,$id); parent::__construct($server_id,$name,$filename,$type,$id);
# If this is the default template, we might disable leafs by default. # If this is the default template, we might disable leafs by default.
@ -636,10 +636,13 @@ class Template extends xmlTemplate {
public function getDNEncode($url=true) { public function getDNEncode($url=true) {
// @todo Be nice to do all this in 1 location // @todo Be nice to do all this in 1 location
$dn = $this->getDN();
if (is_null($dn))
$dn = '';
if ($url) if ($url)
return urlencode(preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->getDN())); return urlencode(preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$dn));
else else
return preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->getDN()); return preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$dn);
} }
/** /**

View File

@ -2156,7 +2156,7 @@ function fillRec(id,value) {
if ($attribute->isMultiple() && $i > 0) if ($attribute->isMultiple() && $i > 0)
return; return;
$val = $attribute->getValue($i); $val = $attribute->getValue($i, '');
if ($attribute->isVisible()) { if ($attribute->isVisible()) {
echo '<table cellspacing="0" cellpadding="0" width="100%" border="0"><tr><td class="icon" style="width: 25px;">'; echo '<table cellspacing="0" cellpadding="0" width="100%" border="0"><tr><td class="icon" style="width: 25px;">';

View File

@ -437,7 +437,8 @@ abstract class DS {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
if (! trim($this->getLogin(null)) && $_SESSION[APPCONFIG]->getValue('appearance','anonymous_bind_implies_read_only')) $login = $this->getLogin(null);
if (!($login && trim($login)) && $_SESSION[APPCONFIG]->getValue('appearance','anonymous_bind_implies_read_only'))
return true; return true;
else else
return $this->getValue('server','read_only'); return $this->getValue('server','read_only');

View File

@ -2318,7 +2318,7 @@ class ldap extends DS {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);
$type = ($sattr = $this->getSchemaAttribute($attr_name)) ? $sattr->getType() : null; $type = ($sattr = $this->getSchemaAttribute($attr_name)) ? $sattr->getType() : '';
if (! strcasecmp('boolean',$type) || if (! strcasecmp('boolean',$type) ||
! strcasecmp('isCriticalSystemObject',$attr_name) || ! strcasecmp('isCriticalSystemObject',$attr_name) ||
@ -2383,8 +2383,8 @@ class ldap extends DS {
/* Strangely, some attributeTypes may not show up in the server /* Strangely, some attributeTypes may not show up in the server
* schema. This behavior has been observed in MS Active Directory.*/ * schema. This behavior has been observed in MS Active Directory.*/
$type = null; $type = '';
$syntax = null; $syntax = '';
} else { } else {
$type = $sattr->getType(); $type = $sattr->getType();

View File

@ -1270,6 +1270,9 @@ function is_mail_string($str) {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs);
if (is_null($str))
return false;
$mail_regex = "/^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$/"; $mail_regex = "/^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$/";
if (preg_match($mail_regex,$str)) if (preg_match($mail_regex,$str))
@ -1288,6 +1291,9 @@ function is_url_string($str) {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs);
if (is_null($str))
return false;
$url_regex = '/^(ftp|https?):\/\/+[\w\.\-\/\?\=\&]*\w+/'; $url_regex = '/^(ftp|https?):\/\/+[\w\.\-\/\?\=\&]*\w+/';
if (preg_match($url_regex,$str)) if (preg_match($url_regex,$str))
@ -2649,6 +2655,9 @@ function pla_explode_dn($dn,$with_attributes=0) {
global $CACHE; global $CACHE;
if (is_null($dn))
$dn = '';
if (isset($CACHE['explode'][$dn][$with_attributes])) { if (isset($CACHE['explode'][$dn][$with_attributes])) {
if (DEBUG_ENABLED) if (DEBUG_ENABLED)
debug_log('Return CACHED result (%s) for (%s)',1,0,__FILE__,__LINE__,__METHOD__, debug_log('Return CACHED result (%s) for (%s)',1,0,__FILE__,__LINE__,__METHOD__,

View File

@ -18,11 +18,11 @@
*/ */
abstract class SchemaItem { abstract class SchemaItem {
# The schema item's name. # The schema item's name.
protected $name = null; protected $name = '';
# The OID of this schema item. # The OID of this schema item.
private $oid = null; private $oid = null;
# The description of this schema item. # The description of this schema item.
protected $description = null; protected $description = '';
# Boolean value indicating whether this objectClass is obsolete # Boolean value indicating whether this objectClass is obsolete
private $is_obsolete = false; private $is_obsolete = false;
@ -703,7 +703,7 @@ class ObjectClass_ObjectClassAttribute {
*/ */
class AttributeType extends SchemaItem { class AttributeType extends SchemaItem {
# The attribute from which this attribute inherits (if any) # The attribute from which this attribute inherits (if any)
private $sup_attribute = null; private $sup_attribute = '';
# The equality rule used # The equality rule used
private $equality = null; private $equality = null;
# The ordering of the attributeType # The ordering of the attributeType
@ -711,8 +711,8 @@ class AttributeType extends SchemaItem {
# Boolean: supports substring matching? # Boolean: supports substring matching?
private $sub_str = null; private $sub_str = null;
# The full syntax string, ie 1.2.3.4{16} # The full syntax string, ie 1.2.3.4{16}
private $syntax = null; private $syntax = '';
private $syntax_oid = null; private $syntax_oid = '';
# boolean: is single valued only? # boolean: is single valued only?
private $is_single_value = false; private $is_single_value = false;
# boolean: is collective? # boolean: is collective?
@ -726,7 +726,7 @@ class AttributeType extends SchemaItem {
# The max number of characters this attribute can be # The max number of characters this attribute can be
private $max_length = null; private $max_length = null;
# A string description of the syntax type (taken from the LDAPSyntaxes) # A string description of the syntax type (taken from the LDAPSyntaxes)
private $type = null; private $type = '';
# An array of objectClasses which use this attributeType (must be set by caller) # An array of objectClasses which use this attributeType (must be set by caller)
private $used_in_object_classes = array(); private $used_in_object_classes = array();
# A list of object class names that require this attribute type. # A list of object class names that require this attribute type.
@ -1327,7 +1327,7 @@ class Syntax extends SchemaItem {
*/ */
class MatchingRule extends SchemaItem { class MatchingRule extends SchemaItem {
# This rule's syntax OID # This rule's syntax OID
private $syntax = null; private $syntax = '';
# An array of attribute names who use this MatchingRule # An array of attribute names who use this MatchingRule
private $used_by_attrs = array(); private $used_by_attrs = array();

View File

@ -230,7 +230,7 @@ abstract class xmlTemplates {
return clone $template; return clone $template;
# If we get here, the template ID didnt exist, so return a blank template, which be interpreted as the default template # If we get here, the template ID didnt exist, so return a blank template, which be interpreted as the default template
$object = new $class['name']($this->server_id,null,null,'default'); $object = new $class['name']($this->server_id,'',null,'default');
return $object; return $object;
} }
@ -272,7 +272,7 @@ abstract class xmlTemplate {
# The TEMPLATE attributes as per the template definition, or the DN entry # The TEMPLATE attributes as per the template definition, or the DN entry
protected $attributes = array(); protected $attributes = array();
public function __construct($server_id,$name=null,$filename=null,$type=null,$id=null) { public function __construct($server_id,$name='',$filename=null,$type=null,$id=null) {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);