From 170714f03311c1fb59ca43b2ff02a4bf41d315dd Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Sun, 3 Nov 2019 18:21:02 +0100 Subject: [PATCH 1/5] Fix Long2IP issue with PHP7.1 Since PHP7.1, as long2ip expects an int, due to the strict_mode, PHP throws an error. Signed-off-by: Hugues Peccatte --- .../Abs/LongToIPv4TransformationsPlugin.php | 6 +++--- libraries/classes/Util.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libraries/classes/Plugins/Transformations/Abs/LongToIPv4TransformationsPlugin.php b/libraries/classes/Plugins/Transformations/Abs/LongToIPv4TransformationsPlugin.php index 8498d1b7b4..217c46b005 100644 --- a/libraries/classes/Plugins/Transformations/Abs/LongToIPv4TransformationsPlugin.php +++ b/libraries/classes/Plugins/Transformations/Abs/LongToIPv4TransformationsPlugin.php @@ -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 ~~~~~~~~~~~~~~~~~~~~ */ /** diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index 6461c61812..41f27c9362 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -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)); + } } From e4dd3f08ceff880abff07902b580d6ad8772bc82 Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Sun, 3 Nov 2019 18:33:50 +0100 Subject: [PATCH 2/5] Update unit tests Signed-off-by: Hugues Peccatte --- .../TransformationPluginsTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/classes/Plugins/Transformations/TransformationPluginsTest.php b/test/classes/Plugins/Transformations/TransformationPluginsTest.php index 609c908d20..6962980a0b 100644 --- a/test/classes/Plugins/Transformations/TransformationPluginsTest.php +++ b/test/classes/Plugins/Transformations/TransformationPluginsTest.php @@ -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>' + ) ); if (function_exists('imagecreatetruecolor')) { From 164c15854d02359db008a24a6c74a64f376956dc Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Sun, 3 Nov 2019 20:13:31 +0100 Subject: [PATCH 3/5] Add unit tests for Util::isInteger Signed-off-by: Hugues Peccatte --- test/classes/UtilTest.php | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/classes/UtilTest.php b/test/classes/UtilTest.php index 8b4ed63e7e..047f2b1753 100644 --- a/test/classes/UtilTest.php +++ b/test/classes/UtilTest.php @@ -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', + ], + ]; + } } From f4e786d9a93b76a72480d4e52b839d34d803616d Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Sun, 3 Nov 2019 20:47:42 +0100 Subject: [PATCH 4/5] IP transformed to binary were not understood anymore Signed-off-by: Hugues Peccatte --- .../Output/Text_Plain_Binarytoip.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libraries/classes/Plugins/Transformations/Output/Text_Plain_Binarytoip.php b/libraries/classes/Plugins/Transformations/Output/Text_Plain_Binarytoip.php index 80e7348840..5422d24536 100644 --- a/libraries/classes/Plugins/Transformations/Output/Text_Plain_Binarytoip.php +++ b/libraries/classes/Plugins/Transformations/Output/Text_Plain_Binarytoip.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin\Plugins\Transformations\Output; use PhpMyAdmin\Plugins\TransformationsPlugin; +use function hex2bin; /** * Handles the binary to IPv4/IPv6 transformation for text plain @@ -45,15 +46,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); } From 8d18c801ebea67cb59e5b05011df13f51f38e166 Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Tue, 5 Nov 2019 10:14:39 +0100 Subject: [PATCH 5/5] Fix PHP compatibility issue Signed-off-by: Hugues Peccatte --- .../Plugins/Transformations/Output/Text_Plain_Binarytoip.php | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/classes/Plugins/Transformations/Output/Text_Plain_Binarytoip.php b/libraries/classes/Plugins/Transformations/Output/Text_Plain_Binarytoip.php index 5422d24536..54e344e3fa 100644 --- a/libraries/classes/Plugins/Transformations/Output/Text_Plain_Binarytoip.php +++ b/libraries/classes/Plugins/Transformations/Output/Text_Plain_Binarytoip.php @@ -9,7 +9,6 @@ namespace PhpMyAdmin\Plugins\Transformations\Output; use PhpMyAdmin\Plugins\TransformationsPlugin; -use function hex2bin; /** * Handles the binary to IPv4/IPv6 transformation for text plain