Bug #120874 MySQL's INET6_NTOA function is not RFC 5952 complaint
Submitted: 6 Jul 13:30 Modified: 7 Jul 6:36
Reporter: Aaditya Dubey Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.4.x, 9.7.x OS:Any
Assigned to: CPU Architecture:Any

[6 Jul 13:30] Aaditya Dubey
Description:
Section 4.2.2 of RFC5952 says "::" should not be used to shorten one 16-bit 0 field. But the current INET6_NTOA function in MySQL seems to shorten it.

Reference: https://www.rfc-editor.org/info/rfc5952/#section-4.2.2

Code Reference: https://github.com/mysql/mysql-server/blob/845d525d49c8027a4d0cdcc43372c96ba295c857/sql/it...

How to repeat:
Sample current output:

mysql> SELECT INET6_NTOA(UNHEX('00010002000300040005000600070000'));
+-------------------------------------------------------+
| INET6_NTOA(UNHEX('00010002000300040005000600070000')) |
+-------------------------------------------------------+
| 1:2:3:4:5:6:7::                                       |
+-------------------------------------------------------+
1 row in set (0.001 sec)

The last field is a one 16bit 0 field. This has be shortened to "::". Ideally this should be the output:

mysql> SELECT INET6_NTOA(UNHEX('00010002000300040005000600070000'));
+-------------------------------------------------------+
| INET6_NTOA(UNHEX('00010002000300040005000600070000')) |
+-------------------------------------------------------+
| 1:2:3:4:5:6:7:0                                       |
+-------------------------------------------------------+
1 row in set (0.00 sec)

Suggested fix:
The patch attached to this ticket fixes the issue, but it's included to demonstrate the problem. More thought is required to determine how MySQL plans to address this and what the consequences are of keeping this function compliant.
[6 Jul 13:31] Aaditya Dubey
Suggested fix

Attachment: patch_inetfunc.cc.patch (text/x-patch), 533 bytes.

[7 Jul 6:36] Chaithra Marsur Gopala Reddy
Hi Aaditya Dubey,

Thank you for the test case. Verified as described.
[7 Jul 6:42] Chaithra Marsur Gopala Reddy
Thank you very much for your patch contribution, we appreciate it!

In order for us to continue the process of reviewing your contribution to MySQL, please send us a signed copy of the Oracle Contributor Agreement (OCA) as outlined in https://oca.opensource.oracle.com

Signing an OCA needs to be done only once and it's valid for all other Oracle governed Open Source projects as well.

Getting a signed/approved OCA on file will help us facilitate your contribution - this one, and others in the future.  

Please let us know, if you have any questions.

Thank you for your interest in MySQL.