StrToHostAddr6 in sockets unit parses invalid IPv6 addresses
Original Reporter info from Mantis: nduffy @solas_agus_dolas
-
Reporter name: Noel Duffy
Original Reporter info from Mantis: nduffy @solas_agus_dolas
- Reporter name: Noel Duffy
Description:
StrToHostAddr6 does not validate input IPv6 addresses. It splits the input string on colons, then takes each substring, prefixes '$', and passes the result to Val. If Val successfully converts the string, StrToHostAddr6 accepts it.
As an example, the string "fe80ca2f1::906e:9d2f:a520:4172" will be successfully parsed, even though it's not a valid IPv6 address because there are more than 4 characters in the first segment.
Steps to reproduce:
This small program demonstrates the problem:
program ip6bug;
uses
SysUtils, sockets;
procedure parse_print_ip6(addr: String);
var
ip6: in6_addr;
idx: Cardinal;
begin
ip6 := StrToHostAddr6(addr);
write('"' + addr+'" ' + '-> ');
for idx := 0 to 15 do
write(IntToHex(byte(ip6.s6_addr8[idx]),2)+'-');
writeln();
end;
const
addr = 'fe80ca2f1::906e:9d2f:a520:4172';
begin
parse_print_ip6(addr);
end.
This program uses StrToHostAddr6 to parse an input string, then it writes out the bytes in in6_addr record returned. It produces this output:
"fe80ca2f1::906e:9d2f:a520:4172" -> A2-F1-00-00-00-00-00-00-90-6E-9D-2F-A5-20-41-72-