mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
wireaddr: allow for UpperCase DNS names
This further relaxes the DNS hostname checks to allow for uppercase input. Changelog-None
This commit is contained in:
parent
f0dd701bc5
commit
0ae6f4d6fb
@ -128,8 +128,9 @@ int main(int argc, char *argv[])
|
|||||||
assert(is_dnsaddr("is-valid.3hostname123.com"));
|
assert(is_dnsaddr("is-valid.3hostname123.com"));
|
||||||
assert(is_dnsaddr("just-a-hostname-with-dashes"));
|
assert(is_dnsaddr("just-a-hostname-with-dashes"));
|
||||||
assert(is_dnsaddr("lightningd_dest.underscore.allowed.in.hostname.part.com"));
|
assert(is_dnsaddr("lightningd_dest.underscore.allowed.in.hostname.part.com"));
|
||||||
|
assert(is_dnsaddr("UpperCase.valiD.COM"));
|
||||||
assert(is_dnsaddr("punycode.xn--bcher-kva.valid.com"));
|
assert(is_dnsaddr("punycode.xn--bcher-kva.valid.com"));
|
||||||
assert(!is_dnsaddr("UPPERCASE.invalid.com"));
|
assert(!is_dnsaddr("nonpunycode.bücher.invalid.com"));
|
||||||
assert(!is_dnsaddr("-.invalid.com"));
|
assert(!is_dnsaddr("-.invalid.com"));
|
||||||
assert(!is_dnsaddr("invalid.-example.com"));
|
assert(!is_dnsaddr("invalid.-example.com"));
|
||||||
assert(!is_dnsaddr("invalid.example-.com"));
|
assert(!is_dnsaddr("invalid.example-.com"));
|
||||||
|
@ -378,21 +378,20 @@ bool is_wildcardaddr(const char *arg)
|
|||||||
/* The rules to check for DNS FQDNs, see `man 7 hostname`
|
/* The rules to check for DNS FQDNs, see `man 7 hostname`
|
||||||
*
|
*
|
||||||
* - not longer than 255
|
* - not longer than 255
|
||||||
* - segments are separated with . dot
|
* - labels are separated with . dot
|
||||||
* - segments do not start or end with - hyphen
|
* - labels do not start or end with - hyphen
|
||||||
* - segments must be longer than zero
|
* - labels must be longer than zero
|
||||||
* - allow lowercase a-z and digits 0-9 and - hyphen
|
* - allow ASCII letters a-z, A-Z, digits 0-9 and - hyphen
|
||||||
* - additionall we allow for an '_' underscore in the hostname part.
|
* - additionally we allow for an '_' underscore in the first hostname label
|
||||||
|
* - other characters must be punycoded rfc3492
|
||||||
*
|
*
|
||||||
* See issue #5657
|
* See `man 7 hostname` and https://www.rfc-editor.org/rfc/rfc1035
|
||||||
* https://github.com/ElementsProject/lightning/issues/5657
|
|
||||||
* https://en.wikipedia.org/wiki/Hostname
|
|
||||||
*/
|
*/
|
||||||
bool is_dnsaddr(const char *arg)
|
bool is_dnsaddr(const char *arg)
|
||||||
{
|
{
|
||||||
size_t i, arglen;
|
size_t i, arglen;
|
||||||
int lastdot;
|
int lastdot;
|
||||||
int numdot;
|
int numlabels;
|
||||||
|
|
||||||
if (is_ipaddr(arg) || is_toraddr(arg) || is_wildcardaddr(arg))
|
if (is_ipaddr(arg) || is_toraddr(arg) || is_wildcardaddr(arg))
|
||||||
return false;
|
return false;
|
||||||
@ -402,10 +401,10 @@ bool is_dnsaddr(const char *arg)
|
|||||||
if (arglen > 255)
|
if (arglen > 255)
|
||||||
return false;
|
return false;
|
||||||
lastdot = -1;
|
lastdot = -1;
|
||||||
numdot = 0;
|
numlabels = 0;
|
||||||
for (i = 0; i < arglen; i++) {
|
for (i = 0; i < arglen; i++) {
|
||||||
if (arg[i] == '.') {
|
if (arg[i] == '.') {
|
||||||
numdot++;
|
numlabels++;
|
||||||
/* segment must be longer than zero */
|
/* segment must be longer than zero */
|
||||||
if (i - lastdot == 1)
|
if (i - lastdot == 1)
|
||||||
return false;
|
return false;
|
||||||
@ -420,12 +419,14 @@ bool is_dnsaddr(const char *arg)
|
|||||||
return false;
|
return false;
|
||||||
if (arg[i] >= 'a' && arg[i] <= 'z')
|
if (arg[i] >= 'a' && arg[i] <= 'z')
|
||||||
continue;
|
continue;
|
||||||
|
if (arg[i] >= 'A' && arg[i] <= 'Z')
|
||||||
|
continue;
|
||||||
if (arg[i] >= '0' && arg[i] <= '9')
|
if (arg[i] >= '0' && arg[i] <= '9')
|
||||||
continue;
|
continue;
|
||||||
if (arg[i] == '-')
|
if (arg[i] == '-')
|
||||||
continue;
|
continue;
|
||||||
/* allow for _ underscores in the first hostname part */
|
/* allow for _ underscores in the first hostname part */
|
||||||
if (arg[i] == '_' && numdot == 0)
|
if (arg[i] == '_' && numlabels == 0)
|
||||||
continue;
|
continue;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user