Skip to content

Commit 4a71779

Browse files
committed
[ticket/security-203] Do not add null values to versions info
Also stopped using reference for validate_versions() method argument. SECURTIY-203
1 parent 5966323 commit 4a71779

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

version_helper.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public function get_versions($force_update = false, $force_cache = false)
315315
$info['stable'] = (empty($info['stable'])) ? array() : $info['stable'];
316316
$info['unstable'] = (empty($info['unstable'])) ? $info['stable'] : $info['unstable'];
317317

318-
$this->validate_versions($info);
318+
$info = $this->validate_versions($info);
319319

320320
$this->cache->put($cache_file, $info, 86400); // 24 hours
321321
}
@@ -328,8 +328,10 @@ public function get_versions($force_update = false, $force_cache = false)
328328
*
329329
* @param array $versions_info Decoded json data array. Will be modified
330330
* and cleaned by this method
331+
*
332+
* @return array Versions info array
331333
*/
332-
public function validate_versions(&$versions_info)
334+
public function validate_versions($versions_info)
333335
{
334336
$array_diff = array_diff_key($versions_info, array($this->version_schema));
335337

@@ -362,7 +364,7 @@ public function validate_versions(&$versions_info)
362364
$version_data = array();
363365
foreach ($this->version_schema[$stability_type] as $key => $value)
364366
{
365-
if (isset($old_version_data[$key]) || $old_version_data[$key] === null)
367+
if (isset($old_version_data[$key]))
366368
{
367369
$version_data[$key] = $old_version_data[$key];
368370
}
@@ -388,16 +390,13 @@ public function validate_versions(&$versions_info)
388390
if (!empty($value) && !preg_match('#^' . get_preg_expression('url') . '$#iu', $value) &&
389391
!preg_match('#^' . get_preg_expression('www_url') . '$#iu', $value))
390392
{
391-
$value = '';
392393
throw new \RuntimeException($this->user->lang('VERSIONCHECK_INVALID_URL'));
393394
}
394395
break;
395396

396397
case 'version':
397-
$value = $value ?: '';
398-
if (!preg_match(get_preg_expression('semantic_version'), $value))
398+
if (!empty($value) && !preg_match(get_preg_expression('semantic_version'), $value))
399399
{
400-
$value = '';
401400
throw new \RuntimeException($this->user->lang('VERSIONCHECK_INVALID_VERSION'));
402401
}
403402
break;
@@ -409,5 +408,7 @@ public function validate_versions(&$versions_info)
409408
}
410409
}
411410
}
411+
412+
return $versions_info;
412413
}
413414
}

0 commit comments

Comments
 (0)