Skip to content

Commit 0ae6f4d

Browse files
m-schmoockcdecker
authored andcommitted
wireaddr: allow for UpperCase DNS names
This further relaxes the DNS hostname checks to allow for uppercase input. Changelog-None
1 parent f0dd701 commit 0ae6f4d

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

common/test/run-ip_port_parsing.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ int main(int argc, char *argv[])
128128
assert(is_dnsaddr("is-valid.3hostname123.com"));
129129
assert(is_dnsaddr("just-a-hostname-with-dashes"));
130130
assert(is_dnsaddr("lightningd_dest.underscore.allowed.in.hostname.part.com"));
131+
assert(is_dnsaddr("UpperCase.valiD.COM"));
131132
assert(is_dnsaddr("punycode.xn--bcher-kva.valid.com"));
132-
assert(!is_dnsaddr("UPPERCASE.invalid.com"));
133+
assert(!is_dnsaddr("nonpunycode.bücher.invalid.com"));
133134
assert(!is_dnsaddr("-.invalid.com"));
134135
assert(!is_dnsaddr("invalid.-example.com"));
135136
assert(!is_dnsaddr("invalid.example-.com"));

common/wireaddr.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,20 @@ bool is_wildcardaddr(const char *arg)
378378
/* The rules to check for DNS FQDNs, see `man 7 hostname`
379379
*
380380
* - not longer than 255
381-
* - segments are separated with . dot
382-
* - segments do not start or end with - hyphen
383-
* - segments must be longer than zero
384-
* - allow lowercase a-z and digits 0-9 and - hyphen
385-
* - additionall we allow for an '_' underscore in the hostname part.
381+
* - labels are separated with . dot
382+
* - labels do not start or end with - hyphen
383+
* - labels must be longer than zero
384+
* - allow ASCII letters a-z, A-Z, digits 0-9 and - hyphen
385+
* - additionally we allow for an '_' underscore in the first hostname label
386+
* - other characters must be punycoded rfc3492
386387
*
387-
* See issue #5657
388-
* https://github.com/ElementsProject/lightning/issues/5657
389-
* https://en.wikipedia.org/wiki/Hostname
388+
* See `man 7 hostname` and https://www.rfc-editor.org/rfc/rfc1035
390389
*/
391390
bool is_dnsaddr(const char *arg)
392391
{
393392
size_t i, arglen;
394393
int lastdot;
395-
int numdot;
394+
int numlabels;
396395

397396
if (is_ipaddr(arg) || is_toraddr(arg) || is_wildcardaddr(arg))
398397
return false;
@@ -402,10 +401,10 @@ bool is_dnsaddr(const char *arg)
402401
if (arglen > 255)
403402
return false;
404403
lastdot = -1;
405-
numdot = 0;
404+
numlabels = 0;
406405
for (i = 0; i < arglen; i++) {
407406
if (arg[i] == '.') {
408-
numdot++;
407+
numlabels++;
409408
/* segment must be longer than zero */
410409
if (i - lastdot == 1)
411410
return false;
@@ -420,12 +419,14 @@ bool is_dnsaddr(const char *arg)
420419
return false;
421420
if (arg[i] >= 'a' && arg[i] <= 'z')
422421
continue;
422+
if (arg[i] >= 'A' && arg[i] <= 'Z')
423+
continue;
423424
if (arg[i] >= '0' && arg[i] <= '9')
424425
continue;
425426
if (arg[i] == '-')
426427
continue;
427428
/* allow for _ underscores in the first hostname part */
428-
if (arg[i] == '_' && numdot == 0)
429+
if (arg[i] == '_' && numlabels == 0)
429430
continue;
430431
return false;
431432
}

0 commit comments

Comments
 (0)