From 7ba9caf227d1282e3f5ff7387bb1dd7e3aa2cb19 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Wed, 28 Apr 2021 16:24:20 +0200 Subject: [PATCH] [document] Show IP also for idn domains. --- src/config/cmdline.c | 1 - src/document/document.c | 25 +++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/config/cmdline.c b/src/config/cmdline.c index 99b6dbd8e..92dfa98da 100644 --- a/src/config/cmdline.c +++ b/src/config/cmdline.c @@ -172,7 +172,6 @@ lookup_cmd(struct option *o, char ***argv, int *argc) if (idname) { int code = idna_to_ascii_lz(idname, &idname2, 0); - /* FIXME: Return NULL if it coughed? --jonas */ if (code == IDNA_SUCCESS) { idname = idname2; allocated = 1; diff --git a/src/document/document.c b/src/document/document.c index e483d9f0d..931ff4af8 100644 --- a/src/document/document.c +++ b/src/document/document.c @@ -10,6 +10,10 @@ #include #include +#ifdef HAVE_IDNA_H +#include +#endif + #include #ifdef HAVE_NETINET_IN_H #include /* OS/2 needs this after sys/types.h */ @@ -99,13 +103,22 @@ get_ip(struct document *document) { #ifdef HAVE_INET_NTOP struct uri *uri = document->uri; - char tmp; + char *host = memacpy(uri->host, uri->hostlen); - if (!uri || !uri->host || !uri->hostlen) return; - tmp = uri->host[uri->hostlen]; - uri->host[uri->hostlen] = 0; - find_host(uri->host, &document->querydns, found_dns, &document->ip, 0); - uri->host[uri->hostlen] = tmp; + if (host) { +#ifdef CONFIG_IDN + char *idname; + int code = idna_to_ascii_lz(host, &idname, 0); + + if (code == IDNA_SUCCESS) { + find_host(idname, &document->querydns, found_dns, &document->ip, 0); + free(idname); + } +#else + find_host(host, &document->querydns, found_dns, &document->ip, 0); +#endif + mem_free(host); + } #endif }