@@ -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 */
391390bool 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