File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -126,11 +126,14 @@ int main(int argc, char *argv[])
126126 assert (is_dnsaddr ("123example.com" ));
127127 assert (is_dnsaddr ("example123.com" ));
128128 assert (is_dnsaddr ("is-valid.3hostname123.com" ));
129+ assert (is_dnsaddr ("just-a-hostname-with-dashes" ));
130+ assert (is_dnsaddr ("lightningd_dest.underscore.allowed.in.hostname.part.com" ));
129131 assert (!is_dnsaddr ("UPPERCASE.invalid.com" ));
130132 assert (!is_dnsaddr ("-.invalid.com" ));
131133 assert (!is_dnsaddr ("invalid.-example.com" ));
132134 assert (!is_dnsaddr ("invalid.example-.com" ));
133135 assert (!is_dnsaddr ("invalid..example.com" ));
136+ assert (!is_dnsaddr ("underscore.not.allowed.in.domain_name.com" ));
134137
135138 /* Grossly invalid. */
136139 assert (!separate_address_and_port (tmpctx , "[" , & ip , & port ));
Original file line number Diff line number Diff line change @@ -375,18 +375,24 @@ bool is_wildcardaddr(const char *arg)
375375 return streq (arg , "" );
376376}
377377
378- /* Rules:
378+ /* The rules to check for DNS FQDNs, see `man 7 hostname`
379379 *
380380 * - not longer than 255
381381 * - segments are separated with . dot
382382 * - segments do not start or end with - hyphen
383- * - segments must be longer thant zero
384- * - lowercase a-z and digits 0-9 and - 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.
386+ *
387+ * See issue #5657
388+ * https://github.com/ElementsProject/lightning/issues/5657
389+ * https://en.wikipedia.org/wiki/Hostname
385390 */
386391bool is_dnsaddr (const char * arg )
387392{
388393 size_t i , arglen ;
389394 int lastdot ;
395+ int numdot ;
390396
391397 if (is_ipaddr (arg ) || is_toraddr (arg ) || is_wildcardaddr (arg ))
392398 return false;
@@ -396,8 +402,10 @@ bool is_dnsaddr(const char *arg)
396402 if (arglen > 255 )
397403 return false;
398404 lastdot = -1 ;
405+ numdot = 0 ;
399406 for (i = 0 ; i < arglen ; i ++ ) {
400407 if (arg [i ] == '.' ) {
408+ numdot ++ ;
401409 /* segment must be longer than zero */
402410 if (i - lastdot == 1 )
403411 return false;
@@ -416,6 +424,9 @@ bool is_dnsaddr(const char *arg)
416424 continue ;
417425 if (arg [i ] == '-' )
418426 continue ;
427+ /* allow for _ underscores in the first hostname part */
428+ if (arg [i ] == '_' && numdot == 0 )
429+ continue ;
419430 return false;
420431 }
421432 return true;
You can’t perform that action at this time.
0 commit comments