Skip to content

Commit 9488fe2

Browse files
monneratleenooks
authored andcommitted
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
1 parent 5e9b95f commit 9488fe2

15 files changed

+49
-37
lines changed

htdocs/cmd.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
$www['page'] = new page($app['server']->getIndex());
4242

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

htdocs/export_form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
require LIBDIR.'export_functions.php';
1414

1515
$request = array();
16-
$request['dn'] = get_request('dn','GET');
16+
$request['dn'] = get_request('dn','GET',false,'');
1717
$request['format'] = get_request('format','GET',false,get_line_end_format());
1818
$request['scope'] = get_request('scope','GET',false,'base');
1919
$request['exporter_id'] = get_request('exporter_id','GET',false,'LDIF');

htdocs/login.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
if ($pass) {
2020
$user = array();
2121
$user['login'] = get_request('login');
22-
$user['password'] = get_request('login_pass');
23-
$user['password'] = html_entity_decode($user['password'], ENT_QUOTES);
22+
$user['password'] = get_request('login_pass', 'POST', false, '');
2423

2524
if ($user['login'] && !strlen($user['password'])) {
2625
system_message(array(

htdocs/password_checker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
$request = array();
1717
$request['componentid'] = get_request('componentid','REQUEST');
18-
$request['hash'] = get_request('hash','REQUEST');
19-
$request['password'] = get_request('check_password','REQUEST');
18+
$request['hash'] = get_request('hash','REQUEST',false,'');
19+
$request['password'] = get_request('check_password','REQUEST',false,'');
2020
$request['action'] = get_request('action','REQUEST');
2121
$request['attribute'] = get_request('attr','REQUEST');
2222

htdocs/schema.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150

151151
foreach ($sattrs as $attr) {
152152
if (isAjaxEnabled() || (is_null($entry['value']) || ! trim($entry['value']) || $entry['value']==$attr->getName())) {
153-
if ((! is_null($entry['value']) && $entry['value']==$attr->getName()) || ! trim($entry['value']))
153+
if (!is_string($entry['value']) || $entry['value']==$attr->getName() || !trim($entry['value']))
154154
$entry['viewed'] = true;
155155

156156
if (isAjaxEnabled() && $entry['value'])
@@ -380,7 +380,7 @@
380380
$desc = $rule->getName(false);
381381

382382
if (isAjaxEnabled() || (is_null($entry['value']) || ! trim($entry['value']) || $entry['value']==$rule->getName())) {
383-
if ((! is_null($entry['value']) && $entry['value']==$rule->getName()) || ! trim($entry['value']))
383+
if (!is_string($entry['value']) || $entry['value']==$rule->getName() || !trim($entry['value']))
384384
$entry['viewed'] = true;
385385

386386
if (null != $rule->getDescription())
@@ -468,7 +468,7 @@
468468

469469
foreach ($socs as $name => $oclass) {
470470
if (isAjaxEnabled() || (is_null($entry['value']) || ! trim($entry['value']) || $entry['value']==$oclass->getName())) {
471-
if ((! is_null($entry['value']) && $entry['value']==$oclass->getName()) || ! trim($entry['value']))
471+
if (!is_string($entry['value']) || $entry['value']==$oclass->getName() || !trim($entry['value']))
472472
$entry['viewed'] = true;
473473

474474
if (isAjaxEnabled() && $entry['value'])

lib/PLAAttribute.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,14 @@ public function delValue($i=-1) {
258258
}
259259
}
260260

261-
public function getValue($i) {
261+
public function getValue($i, $default=null) {
262262
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
263263
debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
264264

265265
if (isset($this->values[$i]))
266266
return $this->values[$i];
267267
else
268-
return null;
268+
return $default;
269269
}
270270

271271
public function getOldValue($i) {

lib/PageRender.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ final public function drawHiddenAttributes() {
538538
final protected function drawHiddenValueAttribute($attribute,$i) {
539539
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
540540

541-
$val = $attribute->getValue($i);
541+
$val = $attribute->getValue($i, '');
542542

543543
printf('<input type="hidden" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" />',
544544
htmlspecialchars($attribute->getName()),$i,htmlspecialchars($attribute->getName()),$i,
@@ -607,7 +607,7 @@ protected function drawFormValueAttribute($attribute,$i) {
607607
protected function drawFormReadOnlyValueAttribute($attribute,$i) {
608608
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
609609

610-
$val = $attribute->getValue($i);
610+
$val = $attribute->getValue($i, '');
611611

612612
printf('<input type="text" class="roval" name="new_values[%s][%s]" id="new_values_%s_%s" value="%s" readonly="readonly" />',
613613
htmlspecialchars($attribute->getName()),$i,htmlspecialchars($attribute->getName()),$i,htmlspecialchars($val));
@@ -616,7 +616,7 @@ protected function drawFormReadOnlyValueAttribute($attribute,$i) {
616616
protected function drawFormReadWriteValueAttribute($attribute,$i) {
617617
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
618618

619-
$val = $attribute->getValue($i);
619+
$val = $attribute->getValue($i, '');
620620

621621
if ($attribute->getHelper() || $attribute->getVerify())
622622
echo '<table cellspacing="0" cellpadding="0" border="0"><tr><td valign="top">';
@@ -720,7 +720,7 @@ protected function drawFormReadWriteValueBinaryAttribute($attribute,$i) {
720720
protected function drawFormReadWriteValueDateAttribute($attribute,$i) {
721721
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
722722

723-
$val = $attribute->getValue($i);
723+
$val = $attribute->getValue($i, '');
724724

725725
echo '<span style="white-space: nowrap;">';
726726
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 @@ protected function drawFormReadWriteValueDateAttribute($attribute,$i) {
738738
protected function drawFormReadWriteValueDnAttribute($attribute,$i) {
739739
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
740740

741-
$val = $attribute->getValue($i);
741+
$val = $attribute->getValue($i, '');
742742

743743
if ($attribute->getHelper())
744744
echo '<table cellspacing="0" cellpadding="0"><tr><td valign="top">';
@@ -952,7 +952,7 @@ protected function drawFormReadOnlyValuePasswordAttribute($attribute,$i) {
952952
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
953953

954954
$server = $this->getServer();
955-
$val = $attribute->getValue($i);
955+
$val = $attribute->getValue($i, '');
956956

957957
if (trim($val))
958958
$enc_type = get_enc_type($val);
@@ -974,7 +974,7 @@ protected function drawFormReadWriteValuePasswordAttribute($attribute,$i) {
974974
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__METHOD__);
975975

976976
$server = $this->getServer();
977-
$val = $attribute->getValue($i);
977+
$val = $attribute->getValue($i, '');
978978

979979
$enc_type = get_enc_type($val);
980980

@@ -1102,7 +1102,7 @@ protected function drawFormReadWriteValueSelectionAttribute($attribute,$i) {
11021102

11031103
# This is a single value attribute
11041104
} else {
1105-
$val = $attribute->getValue($i) ? $attribute->getValue($i) : $attribute->getDefault();
1105+
$val = $attribute->getValue($i) ? $attribute->getValue($i) : (is_null($attribute->getDefault())? '': $attribute->getDefault());
11061106

11071107
if ($attribute->getHelper())
11081108
echo '<table cellspacing="0" cellpadding="0"><tr><td valign="top">';

lib/Query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function accept() {
136136
$bases = get_request('base','REQUEST',false,null);
137137
$query['filter'] = get_request('filter','REQUEST',false,'objectClass=*');
138138
$query['scope'] = get_request('scope','REQUEST',false,'sub');
139-
$attrs = get_request('display_attrs','REQUEST');
139+
$attrs = get_request('display_attrs','REQUEST',false,'');
140140

141141
$attrs = preg_replace('/\s+/','',$attrs);
142142
if ($attrs)

lib/Template.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Template extends xmlTemplate {
5656
# Template RDN attributes
5757
private $rdn;
5858

59-
public function __construct($server_id,$name=null,$filename=null,$type=null,$id=null) {
59+
public function __construct($server_id,$name='',$filename=null,$type=null,$id=null) {
6060
parent::__construct($server_id,$name,$filename,$type,$id);
6161

6262
# If this is the default template, we might disable leafs by default.
@@ -636,10 +636,13 @@ public function getDN() {
636636

637637
public function getDNEncode($url=true) {
638638
// @todo Be nice to do all this in 1 location
639+
$dn = $this->getDN();
640+
if (is_null($dn))
641+
$dn = '';
639642
if ($url)
640-
return urlencode(preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->getDN()));
643+
return urlencode(preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$dn));
641644
else
642-
return preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->getDN());
645+
return preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$dn);
643646
}
644647

645648
/**

lib/TemplateRender.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2156,7 +2156,7 @@ protected function drawValueAttribute($attribute,$i) {
21562156
if ($attribute->isMultiple() && $i > 0)
21572157
return;
21582158

2159-
$val = $attribute->getValue($i);
2159+
$val = $attribute->getValue($i, '');
21602160

21612161
if ($attribute->isVisible()) {
21622162
echo '<table cellspacing="0" cellpadding="0" width="100%" border="0"><tr><td class="icon" style="width: 25px;">';

0 commit comments

Comments
 (0)