Bug #78856 UNHEX INET6_ATON INET6_NTOA should emit warning when input is malformed
Submitted: 16 Oct 2015 8:42 Modified: 23 Oct 2015 15:31
Reporter: Guilhem Bichot Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Errors Severity:S3 (Non-critical)
Version:5.6.28,5.7.10 OS:Any
Assigned to: CPU Architecture:Any

[16 Oct 2015 8:42] Guilhem Bichot
Description:
+select unhex("z");
+unhex("z")
+NULL
+select inet6_aton("foo");
+inet6_aton("foo")
+NULL

Imagine someone stores a UUID (with unhex) or IPv6 address (with inet6_aton) into a binary(16) column, like this:

create table t(ip binary(16));
insert into t values(inet6_aton("foo"));

the column is declared nullable, bad input data isn't noticed (no error, no warning, just an inserted NULL). This doesn't help the user to validate his data.

So those two functions should additionally emit a warning 
(WARN_DATA_TRUNCATED? ER_WARN_DATA_OUT_OF_RANGE?
ER_WRONG_VALUE_FOR_TYPE?).
As usual, strict mode will automatically upgrade this warning to error if the bad data is used in a data-modifying statement.

How to repeat:
see above
[16 Oct 2015 8:46] Guilhem Bichot
inet6_ntoa should warn too:

select inet6_ntoa("foo");
select inet6_ntoa(x'11');
just return NULL today.
[23 Oct 2015 15:31] Paul DuBois
Noted in 5.7.10, 5.8.0 changelogs.

These functions now produce warnings for invalid input, or errors in
strict SQL mode: UNHEX(), INET_NTOA(), INET_ATON(), INET6_NTOA(),
INET6_ATON().
[2 Nov 2015 14:24] Paul DuBois
Revised changelog entry:

These functions now produce warnings for invalid input: UNHEX(),
INET_NTOA(), INET_ATON(), INET6_NTOA(), INET6_ATON().

(errors occur in strict mode according to the usual rules, e.g.,
for data-modifying statements.)