From 12008677de759398067f86ad5ef6296a9c8afec3 Mon Sep 17 00:00:00 2001 From: "vva@eagle.mysql.r18.ru" <> Date: Tue, 20 Jan 2004 00:32:25 +0400 Subject: [PATCH] Fixed bug #2310 "INET_ATON handles short-forms addresses incorrectly" --- mysql-test/r/func_misc.result | 11 ++++++++++- mysql-test/t/func_misc.test | 4 ++++ sql/item_func.cc | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result index d51bea020ed..ec5f76409e7 100644 --- a/mysql-test/r/func_misc.result +++ b/mysql-test/r/func_misc.result @@ -6,10 +6,19 @@ inet_ntoa(inet_aton("255.255.255.255.255.255.255.255")) NULL select inet_aton("255.255.255.255.255"),inet_aton("255.255.1.255"),inet_aton("0.1.255"); inet_aton("255.255.255.255.255") inet_aton("255.255.1.255") inet_aton("0.1.255") -1099511627775 4294902271 511 +1099511627775 4294902271 65791 select inet_ntoa(1099511627775),inet_ntoa(4294902271),inet_ntoa(511); inet_ntoa(1099511627775) inet_ntoa(4294902271) inet_ntoa(511) NULL 255.255.1.255 0.0.1.255 +select hex(inet_aton('127')); +hex(inet_aton('127')) +7F +select hex(inet_aton('127.1')); +hex(inet_aton('127.1')) +7F000001 +select hex(inet_aton('127.1.1')); +hex(inet_aton('127.1.1')) +7F010001 select length(format('nan', 2)) > 0; length(format('nan', 2)) > 0 1 diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test index d15c26279ec..9759127b222 100644 --- a/mysql-test/t/func_misc.test +++ b/mysql-test/t/func_misc.test @@ -8,6 +8,10 @@ select inet_ntoa(inet_aton("255.255.255.255.255.255.255.255")); select inet_aton("255.255.255.255.255"),inet_aton("255.255.1.255"),inet_aton("0.1.255"); select inet_ntoa(1099511627775),inet_ntoa(4294902271),inet_ntoa(511); +select hex(inet_aton('127')); +select hex(inet_aton('127.1')); +select hex(inet_aton('127.1.1')); + # # Test for core dump with nan # diff --git a/sql/item_func.cc b/sql/item_func.cc index 5af64ca0be4..802b6dbb8d6 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2618,6 +2618,7 @@ longlong Item_func_inet_aton::val_int() const char *p,* end; char c = '.'; // we mark c to indicate invalid IP in case length is 0 char buff[36]; + int dot_count= 0; String *s,tmp(buff,sizeof(buff),&my_charset_bin); if (!(s = args[0]->val_str(&tmp))) // If null value @@ -2636,6 +2637,7 @@ longlong Item_func_inet_aton::val_int() } else if (c == '.') { + dot_count++; result= (result << 8) + (ulonglong) byte_result; byte_result = 0; } @@ -2643,7 +2645,14 @@ longlong Item_func_inet_aton::val_int() goto err; // Invalid character } if (c != '.') // IP number can't end on '.' + { + switch (dot_count) + { + case 1: result<<= 8; + case 2: result<<= 8; + } return (result << 8) + (ulonglong) byte_result; + } err: null_value=1;