diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-07-11 04:42:21 -0400 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-07-11 10:42:21 +0200 |
commit | ad1f3fe6a816ddd7c2e80f4639825e88d93b5a98 (patch) | |
tree | a91f5615184170b98bd6365e81074b224db1fc9a /src/shared/dns-domain.c | |
parent | e3e42fc2b52dbd284a56457269ca920d6ab46295 (diff) | |
download | systemd-ad1f3fe6a816ddd7c2e80f4639825e88d93b5a98.tar.gz |
resolved: allow resolution of names which libidn2 considers invalid (#6315)
https://tools.ietf.org/html/rfc5891#section-4.2.3.1 says that
> The Unicode string MUST NOT contain "--" (two consecutive hyphens) in the third
> and fourth character positions and MUST NOT start or end with a "-" (hyphen).
This means that libidn2 refuses to encode such names.
Let's just resolve them without trying to use IDN.
Diffstat (limited to 'src/shared/dns-domain.c')
-rw-r--r-- | src/shared/dns-domain.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c index 40aec3a1ea..12c4d65dd3 100644 --- a/src/shared/dns-domain.c +++ b/src/shared/dns-domain.c @@ -1282,10 +1282,13 @@ int dns_name_apply_idna(const char *name, char **ret) { IDN2_NFC_INPUT | IDN2_NONTRANSITIONAL); if (r == IDN2_OK) return 1; /* *ret has been written */ - else if (IN_SET(r, IDN2_TOO_BIG_DOMAIN, IDN2_TOO_BIG_LABEL)) + log_debug("idn2_lookup_u8(\"%s\") failed: %s", name, idn2_strerror(r)); + if (r == IDN2_2HYPHEN) + /* The name has two hypens — forbidden by IDNA2008 in some cases */ + return 0; + if (IN_SET(r, IDN2_TOO_BIG_DOMAIN, IDN2_TOO_BIG_LABEL)) return -ENOSPC; - else - return -EINVAL; + return -EINVAL; #elif defined(HAVE_LIBIDN) _cleanup_free_ char *buf = NULL; size_t n = 0, allocated = 0; @@ -1322,7 +1325,7 @@ int dns_name_apply_idna(const char *name, char **ret) { else buf[n++] = '.'; - n +=r; + n += r; } if (n > DNS_HOSTNAME_MAX) @@ -1335,7 +1338,7 @@ int dns_name_apply_idna(const char *name, char **ret) { *ret = buf; buf = NULL; - return (int) n; + return 1; #else return 0; #endif |