Merge #15556 - Fix Long2IP issue with PHP7.1

Pull-request: #15556
Fixes: #14906

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2019-11-05 22:38:37 +01:00
commit 59d6fbec82
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
5 changed files with 92 additions and 10 deletions

View File

@ -9,6 +9,7 @@
namespace PhpMyAdmin\Plugins\Transformations\Abs;
use PhpMyAdmin\Plugins\TransformationsPlugin;
use PhpMyAdmin\Util;
/**
* Provides common methods for all of the long to IPv4 transformations plugins.
@ -41,14 +42,13 @@ abstract class LongToIPv4TransformationsPlugin extends TransformationsPlugin
*/
public function applyTransformation($buffer, array $options = array(), $meta = '')
{
if ($buffer < 0 || $buffer > 4294967295) {
if (! Util::isInteger($buffer) || $buffer < 0 || $buffer > 4294967295) {
return htmlspecialchars($buffer);
}
return long2ip($buffer);
return long2ip((int) $buffer);
}
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
/**

View File

@ -45,15 +45,18 @@ class Text_Plain_Binarytoip extends TransformationsPlugin
*/
public function applyTransformation($buffer, array $options = array(), $meta = '')
{
$length = strlen($buffer);
if ($length == 4 || $length == 16) {
$val = @inet_ntop(pack('A' . $length, $buffer));
if ($val !== false) {
return $val;
}
if (0 !== strpos($buffer, '0x')) {
return $buffer;
}
return $buffer;
$ipHex = substr($buffer, 2);
$ipBin = hex2bin($ipHex);
if (false === $ipBin) {
return $buffer;
}
return @inet_ntop($ipBin);
}

View File

@ -4741,4 +4741,16 @@ class Util
return self::linkOrButton($url, $title . $orderImg, $orderLinkParams);
}
/**
* Check that input is an int or an int in a string
*
* @param mixed $input
*
* @return bool
*/
public static function isInteger($input)
{
return (ctype_digit((string) $input));
}
}

View File

@ -944,6 +944,26 @@ class TransformationPluginsTest extends PmaTestCase
),
'suffixMA_suffix'
),
array(
new Text_Plain_Longtoipv4(),
array(168496141),
'10.11.12.13'
),
array(
new Text_Plain_Longtoipv4(),
array('168496141'),
'10.11.12.13'
),
array(
new Text_Plain_Longtoipv4(),
array('my ip'),
'my ip'
),
array(
new Text_Plain_Longtoipv4(),
array('<my ip>'),
'&lt;my ip&gt;'
)
);
if (function_exists('imagecreatetruecolor')) {

View File

@ -2128,4 +2128,51 @@ class UtilTest extends PmaTestCase
],
];
}
/**
* Test for Util::isInteger
*
* @param bool $expected Expected result for a given input
* @param mixed $input Input data to check
*
* @return void
*
* @dataProvider providerIsInteger
*/
public function testIsInteger($expected, $input)
{
$isInteger = Util::isInteger($input);
$this->assertEquals($expected, $isInteger);
}
/**
* Data provider for Util::isInteger test
*
* @return array
*/
public function providerIsInteger()
{
return [
[
true,
1000,
],
[
true,
'1000',
],
[
false,
1000.1,
],
[
false,
'1000.1',
],
[
false,
'input',
],
];
}
}