forked from curl/curl-www
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CVE-2016-8625.patch
718 lines (679 loc) · 23.4 KB
/
CVE-2016-8625.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
From 1f2e6cdd4b8836cfc6e91ae700cbcc4c2488adcd Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Wed, 12 Oct 2016 09:01:06 +0200
Subject: [PATCH] idn: switch to libidn2 use and IDNA2008 support
CVE-2016-8625
Bug: https://curl.se/docs/adv_20161102K.html
Reported-by: Christian Heimes
---
CMakeLists.txt | 13 ++------
configure.ac | 76 +++++++++++++++++--------------------------
lib/curl_setup.h | 7 ++--
lib/easy.c | 26 ---------------
lib/strerror.c | 81 ++--------------------------------------------
lib/strerror.h | 4 +--
lib/url.c | 99 ++++++++++++--------------------------------------------
lib/version.c | 14 ++++----
8 files changed, 66 insertions(+), 254 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4187d37..ed3f38a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -447,11 +447,11 @@ if(NOT CURL_DISABLE_LDAPS)
check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
check_include_file_concat("ldapssl.h" HAVE_LDAPSSL_H)
endif()
# Check for idn
-check_library_exists_concat("idn" idna_to_ascii_lz HAVE_LIBIDN)
+check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2)
# Check for symbol dlopen (same as HAVE_LIBDL)
check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
option(CURL_ZLIB "Set to ON to enable building curl with zlib support." ON)
@@ -616,11 +616,11 @@ check_include_file_concat("assert.h" HAVE_ASSERT_H)
check_include_file_concat("crypto.h" HAVE_CRYPTO_H)
check_include_file_concat("des.h" HAVE_DES_H)
check_include_file_concat("err.h" HAVE_ERR_H)
check_include_file_concat("errno.h" HAVE_ERRNO_H)
check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
-check_include_file_concat("idn-free.h" HAVE_IDN_FREE_H)
+check_include_file_concat("idn2.h" HAVE_IDN2_H)
check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
check_include_file_concat("io.h" HAVE_IO_H)
check_include_file_concat("krb.h" HAVE_KRB_H)
check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
check_include_file_concat("limits.h" HAVE_LIMITS_H)
@@ -646,11 +646,10 @@ check_include_file_concat("string.h" HAVE_STRING_H)
check_include_file_concat("strings.h" HAVE_STRINGS_H)
check_include_file_concat("stropts.h" HAVE_STROPTS_H)
check_include_file_concat("termio.h" HAVE_TERMIO_H)
check_include_file_concat("termios.h" HAVE_TERMIOS_H)
check_include_file_concat("time.h" HAVE_TIME_H)
-check_include_file_concat("tld.h" HAVE_TLD_H)
check_include_file_concat("unistd.h" HAVE_UNISTD_H)
check_include_file_concat("utime.h" HAVE_UTIME_H)
check_include_file_concat("x509.h" HAVE_X509_H)
check_include_file_concat("process.h" HAVE_PROCESS_H)
@@ -660,13 +659,10 @@ check_include_file_concat("malloc.h" HAVE_MALLOC_H)
check_include_file_concat("memory.h" HAVE_MEMORY_H)
check_include_file_concat("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H)
check_include_file_concat("stdint.h" HAVE_STDINT_H)
check_include_file_concat("sockio.h" HAVE_SOCKIO_H)
check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H)
-check_include_file_concat("idna.h" HAVE_IDNA_H)
-
-
check_type_size(size_t SIZEOF_SIZE_T)
check_type_size(ssize_t SIZEOF_SSIZE_T)
check_type_size("long long" SIZEOF_LONG_LONG)
check_type_size("long" SIZEOF_LONG)
@@ -809,13 +805,10 @@ check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
-check_symbol_exists(idn_free "${CURL_INCLUDES}" HAVE_IDN_FREE)
-check_symbol_exists(idna_strerror "${CURL_INCLUDES}" HAVE_IDNA_STRERROR)
-check_symbol_exists(tld_strerror "${CURL_INCLUDES}" HAVE_TLD_STRERROR)
check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL)
check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
@@ -1076,11 +1069,11 @@ _add_if("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI)
_add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
_add_if("IPv6" ENABLE_IPV6)
_add_if("unix-sockets" USE_UNIX_SOCKETS)
_add_if("libz" HAVE_LIBZ)
_add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
-_add_if("IDN" HAVE_LIBIDN)
+_add_if("IDN" HAVE_LIBIDN2)
_add_if("Largefile" (CURL_SIZEOF_CURL_OFF_T GREATER 4) AND
((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
# TODO SSP1 (WinSSL) check is missing
_add_if("SSPI" USE_WINDOWS_SSPI)
_add_if("GSS-API" HAVE_GSSAPI)
diff --git a/configure.ac b/configure.ac
index 83cfbff..74f2316 100644
--- a/configure.ac
+++ b/configure.ac
@@ -155,11 +155,11 @@ dnl initialize all the info variables
curl_gss_msg="no (--with-gssapi)"
curl_tls_srp_msg="no (--enable-tls-srp)"
curl_res_msg="default (--enable-ares / --enable-threaded-resolver)"
curl_ipv6_msg="no (--enable-ipv6)"
curl_unix_sockets_msg="no (--enable-unix-sockets)"
- curl_idn_msg="no (--with-{libidn,winidn})"
+ curl_idn_msg="no (--with-{libidn2,winidn})"
curl_manual_msg="no (--enable-manual)"
curl_libcurl_msg="enabled (--disable-libcurl-option)"
curl_verbose_msg="enabled (--disable-verbose)"
curl_sspi_msg="no (--enable-sspi)"
curl_ldap_msg="no (--enable-ldap / --with-ldap-lib / --with-lber-lib)"
@@ -2828,36 +2828,36 @@ fi
dnl **********************************************************************
dnl Check for the presence of IDN libraries and headers
dnl **********************************************************************
-AC_MSG_CHECKING([whether to build with libidn])
+AC_MSG_CHECKING([whether to build with libidn2])
OPT_IDN="default"
AC_ARG_WITH(libidn,
-AC_HELP_STRING([--with-libidn=PATH],[Enable libidn usage])
-AC_HELP_STRING([--without-libidn],[Disable libidn usage]),
+AC_HELP_STRING([--with-libidn2=PATH],[Enable libidn2 usage])
+AC_HELP_STRING([--without-libidn2],[Disable libidn2 usage]),
[OPT_IDN=$withval])
case "$OPT_IDN" in
no)
- dnl --without-libidn option used
+ dnl --without-libidn2 option used
want_idn="no"
AC_MSG_RESULT([no])
;;
default)
dnl configure option not specified
want_idn="yes"
want_idn_path="default"
AC_MSG_RESULT([(assumed) yes])
;;
yes)
- dnl --with-libidn option used without path
+ dnl --with-libidn2 option used without path
want_idn="yes"
want_idn_path="default"
AC_MSG_RESULT([yes])
;;
*)
- dnl --with-libidn option used with path
+ dnl --with-libidn2 option used with path
want_idn="yes"
want_idn_path="$withval"
AC_MSG_RESULT([yes ($withval)])
;;
esac
@@ -2870,37 +2870,37 @@ if test "$want_idn" = "yes"; then
PKGCONFIG="no"
#
if test "$want_idn_path" != "default"; then
dnl path has been specified
IDN_PCDIR="$want_idn_path/lib$libsuff/pkgconfig"
- CURL_CHECK_PKGCONFIG(libidn, [$IDN_PCDIR])
+ CURL_CHECK_PKGCONFIG(libidn2, [$IDN_PCDIR])
if test "$PKGCONFIG" != "no"; then
IDN_LIBS=`CURL_EXPORT_PCDIR([$IDN_PCDIR]) dnl
- $PKGCONFIG --libs-only-l libidn 2>/dev/null`
+ $PKGCONFIG --libs-only-l libidn2 2>/dev/null`
IDN_LDFLAGS=`CURL_EXPORT_PCDIR([$IDN_PCDIR]) dnl
- $PKGCONFIG --libs-only-L libidn 2>/dev/null`
+ $PKGCONFIG --libs-only-L libidn2 2>/dev/null`
IDN_CPPFLAGS=`CURL_EXPORT_PCDIR([$IDN_PCDIR]) dnl
- $PKGCONFIG --cflags-only-I libidn 2>/dev/null`
+ $PKGCONFIG --cflags-only-I libidn2 2>/dev/null`
IDN_DIR=`echo $IDN_LDFLAGS | $SED -e 's/-L//'`
else
dnl pkg-config not available or provides no info
- IDN_LIBS="-lidn"
+ IDN_LIBS="-lidn2"
IDN_LDFLAGS="-L$want_idn_path/lib$libsuff"
IDN_CPPFLAGS="-I$want_idn_path/include"
IDN_DIR="$want_idn_path/lib$libsuff"
fi
else
dnl path not specified
- CURL_CHECK_PKGCONFIG(libidn)
+ CURL_CHECK_PKGCONFIG(libidn2)
if test "$PKGCONFIG" != "no"; then
- IDN_LIBS=`$PKGCONFIG --libs-only-l libidn 2>/dev/null`
- IDN_LDFLAGS=`$PKGCONFIG --libs-only-L libidn 2>/dev/null`
- IDN_CPPFLAGS=`$PKGCONFIG --cflags-only-I libidn 2>/dev/null`
+ IDN_LIBS=`$PKGCONFIG --libs-only-l libidn2 2>/dev/null`
+ IDN_LDFLAGS=`$PKGCONFIG --libs-only-L libidn2 2>/dev/null`
+ IDN_CPPFLAGS=`$PKGCONFIG --cflags-only-I libidn2 2>/dev/null`
IDN_DIR=`echo $IDN_LDFLAGS | $SED -e 's/-L//'`
else
dnl pkg-config not available or provides no info
- IDN_LIBS="-lidn"
+ IDN_LIBS="-lidn2"
fi
fi
#
if test "$PKGCONFIG" != "no"; then
AC_MSG_NOTICE([pkg-config: IDN_LIBS: "$IDN_LIBS"])
@@ -2916,51 +2916,33 @@ if test "$want_idn" = "yes"; then
#
CPPFLAGS="$IDN_CPPFLAGS $CPPFLAGS"
LDFLAGS="$IDN_LDFLAGS $LDFLAGS"
LIBS="$IDN_LIBS $LIBS"
#
- AC_MSG_CHECKING([if idna_to_ascii_4i can be linked])
+ AC_MSG_CHECKING([if idn2_lookup_ul can be linked])
AC_LINK_IFELSE([
- AC_LANG_FUNC_LINK_TRY([idna_to_ascii_4i])
+ AC_LANG_FUNC_LINK_TRY([idn2_lookup_ul])
],[
AC_MSG_RESULT([yes])
tst_links_libidn="yes"
],[
AC_MSG_RESULT([no])
tst_links_libidn="no"
])
- if test "$tst_links_libidn" = "no"; then
- AC_MSG_CHECKING([if idna_to_ascii_lz can be linked])
- AC_LINK_IFELSE([
- AC_LANG_FUNC_LINK_TRY([idna_to_ascii_lz])
- ],[
- AC_MSG_RESULT([yes])
- tst_links_libidn="yes"
- ],[
- AC_MSG_RESULT([no])
- tst_links_libidn="no"
- ])
- fi
#
+ AC_CHECK_HEADERS( idn2.h )
+
if test "$tst_links_libidn" = "yes"; then
- AC_DEFINE(HAVE_LIBIDN, 1, [Define to 1 if you have the `idn' library (-lidn).])
+ AC_DEFINE(HAVE_LIBIDN2, 1, [Define to 1 if you have the `idn2' library (-lidn2).])
dnl different versions of libidn have different setups of these:
- AC_CHECK_FUNCS( idn_free idna_strerror tld_strerror )
- AC_CHECK_HEADERS( idn-free.h tld.h )
- if test "x$ac_cv_header_tld_h" = "xyes"; then
- AC_SUBST([IDN_ENABLED], [1])
- curl_idn_msg="enabled"
- if test -n "$IDN_DIR" -a "x$cross_compiling" != "xyes"; then
- LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$IDN_DIR"
- export LD_LIBRARY_PATH
- AC_MSG_NOTICE([Added $IDN_DIR to LD_LIBRARY_PATH])
- fi
- else
- AC_MSG_WARN([Libraries for IDN support too old: IDN disabled])
- CPPFLAGS="$clean_CPPFLAGS"
- LDFLAGS="$clean_LDFLAGS"
- LIBS="$clean_LIBS"
+
+ AC_SUBST([IDN_ENABLED], [1])
+ curl_idn_msg="enabled (libidn2)"
+ if test -n "$IDN_DIR" -a "x$cross_compiling" != "xyes"; then
+ LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$IDN_DIR"
+ export LD_LIBRARY_PATH
+ AC_MSG_NOTICE([Added $IDN_DIR to LD_LIBRARY_PATH])
fi
else
AC_MSG_WARN([Cannot find libraries for IDN support: IDN disabled])
CPPFLAGS="$clean_CPPFLAGS"
LDFLAGS="$clean_LDFLAGS"
diff --git a/lib/curl_setup.h b/lib/curl_setup.h
index 5d82e33..9619a1e 100644
--- a/lib/curl_setup.h
+++ b/lib/curl_setup.h
@@ -597,14 +597,13 @@ int netware_init(void);
#include <sys/bsdskt.h>
#include <sys/timeval.h>
#endif
#endif
-#if defined(HAVE_LIBIDN) && defined(HAVE_TLD_H)
-/* The lib was present and the tld.h header (which is missing in libidn 0.3.X
- but we only work with libidn 0.4.1 or later) */
-#define USE_LIBIDN
+#if defined(HAVE_LIBIDN2) && defined(HAVE_IDN2_H)
+/* The lib and header are present */
+#define USE_LIBIDN2
#endif
#ifndef SIZEOF_TIME_T
/* assume default size of time_t to be 32 bit */
#define SIZEOF_TIME_T 4
diff --git a/lib/easy.c b/lib/easy.c
index 517c39f..cb0ac67 100644
--- a/lib/easy.c
+++ b/lib/easy.c
@@ -142,32 +142,10 @@ static CURLcode win32_init(void)
#endif
return CURLE_OK;
}
-#ifdef USE_LIBIDN
-/*
- * Initialise use of IDNA library.
- * It falls back to ASCII if $CHARSET isn't defined. This doesn't work for
- * idna_to_ascii_lz().
- */
-static void idna_init (void)
-{
-#ifdef WIN32
- char buf[60];
- UINT cp = GetACP();
-
- if(!getenv("CHARSET") && cp > 0) {
- snprintf(buf, sizeof(buf), "CHARSET=cp%u", cp);
- putenv(buf);
- }
-#else
- /* to do? */
-#endif
-}
-#endif /* USE_LIBIDN */
-
/* true globals -- for curl_global_init() and curl_global_cleanup() */
static unsigned int initialized;
static long init_flags;
/*
@@ -260,14 +238,10 @@ static CURLcode global_init(long flags, bool memoryfuncs)
if(netware_init()) {
DEBUGF(fprintf(stderr, "Warning: LONG namespace not available\n"));
}
#endif
-#ifdef USE_LIBIDN
- idna_init();
-#endif
-
if(Curl_resolver_global_init()) {
DEBUGF(fprintf(stderr, "Error: resolver_global_init failed\n"));
return CURLE_FAILED_INIT;
}
diff --git a/lib/strerror.c b/lib/strerror.c
index edb96d2..db50c7d 100644
--- a/lib/strerror.c
+++ b/lib/strerror.c
@@ -33,12 +33,12 @@
# endif
#endif
#include <curl/curl.h>
-#ifdef USE_LIBIDN
-#include <idna.h>
+#ifdef USE_LIBIDN2
+#include <idn2.h>
#endif
#ifdef USE_WINDOWS_SSPI
#include "curl_sspi.h"
#endif
@@ -724,87 +724,10 @@ const char *Curl_strerror(struct connectdata *conn, int err)
SET_ERRNO(old_errno);
return buf;
}
-#ifdef USE_LIBIDN
-/*
- * Return error-string for libidn status as returned from idna_to_ascii_lz().
- */
-const char *Curl_idn_strerror (struct connectdata *conn, int err)
-{
-#ifdef HAVE_IDNA_STRERROR
- (void)conn;
- return idna_strerror((Idna_rc) err);
-#else
- const char *str;
- char *buf;
- size_t max;
-
- DEBUGASSERT(conn);
-
- buf = conn->syserr_buf;
- max = sizeof(conn->syserr_buf)-1;
- *buf = '\0';
-
-#ifndef CURL_DISABLE_VERBOSE_STRINGS
- switch ((Idna_rc)err) {
- case IDNA_SUCCESS:
- str = "No error";
- break;
- case IDNA_STRINGPREP_ERROR:
- str = "Error in string preparation";
- break;
- case IDNA_PUNYCODE_ERROR:
- str = "Error in Punycode operation";
- break;
- case IDNA_CONTAINS_NON_LDH:
- str = "Illegal ASCII characters";
- break;
- case IDNA_CONTAINS_MINUS:
- str = "Contains minus";
- break;
- case IDNA_INVALID_LENGTH:
- str = "Invalid output length";
- break;
- case IDNA_NO_ACE_PREFIX:
- str = "No ACE prefix (\"xn--\")";
- break;
- case IDNA_ROUNDTRIP_VERIFY_ERROR:
- str = "Round trip verify error";
- break;
- case IDNA_CONTAINS_ACE_PREFIX:
- str = "Already have ACE prefix (\"xn--\")";
- break;
- case IDNA_ICONV_ERROR:
- str = "Locale conversion failed";
- break;
- case IDNA_MALLOC_ERROR:
- str = "Allocation failed";
- break;
- case IDNA_DLOPEN_ERROR:
- str = "dlopen() error";
- break;
- default:
- snprintf(buf, max, "error %d", err);
- str = NULL;
- break;
- }
-#else
- if((Idna_rc)err == IDNA_SUCCESS)
- str = "No error";
- else
- str = "Error";
-#endif
- if(str)
- strncpy(buf, str, max);
- buf[max] = '\0';
- return (buf);
-#endif
-}
-#endif /* USE_LIBIDN */
-
#ifdef USE_WINDOWS_SSPI
const char *Curl_sspi_strerror (struct connectdata *conn, int err)
{
#ifndef CURL_DISABLE_VERBOSE_STRINGS
char txtbuf[80];
diff --git a/lib/strerror.h b/lib/strerror.h
index ae8c96b..627273e 100644
--- a/lib/strerror.h
+++ b/lib/strerror.h
@@ -5,11 +5,11 @@
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
@@ -24,11 +24,11 @@
#include "urldata.h"
const char *Curl_strerror (struct connectdata *conn, int err);
-#ifdef USE_LIBIDN
+#ifdef USE_LIBIDN2
const char *Curl_idn_strerror (struct connectdata *conn, int err);
#endif
#ifdef USE_WINDOWS_SSPI
const char *Curl_sspi_strerror (struct connectdata *conn, int err);
diff --git a/lib/url.c b/lib/url.c
index 91b2bf8..2dd3830 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -57,28 +57,19 @@
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
-#ifdef USE_LIBIDN
-#include <idna.h>
-#include <tld.h>
-#include <stringprep.h>
-#ifdef HAVE_IDN_FREE_H
-#include <idn-free.h>
-#else
-/* prototype from idn-free.h, not provided by libidn 0.4.5's make install! */
-void idn_free (void *ptr);
-#endif
-#ifndef HAVE_IDN_FREE
-/* if idn_free() was not found in this version of libidn use free() instead */
-#define idn_free(x) (free)(x)
-#endif
+#ifdef USE_LIBIDN2
+#include <idn2.h>
+
#elif defined(USE_WIN32_IDN)
/* prototype for curl_win32_idn_to_ascii() */
bool curl_win32_idn_to_ascii(const char *in, char **out);
-#endif /* USE_LIBIDN */
+#endif /* USE_LIBIDN2 */
+
+#include <idn2.h>
#include "urldata.h"
#include "netrc.h"
#include "formdata.h"
@@ -3769,62 +3760,19 @@ static bool is_ASCII_name(const char *hostname)
return FALSE;
}
return TRUE;
}
-#ifdef USE_LIBIDN
-/*
- * Check if characters in hostname is allowed in Top Level Domain.
- */
-static bool tld_check_name(struct Curl_easy *data,
- const char *ace_hostname)
-{
- size_t err_pos;
- char *uc_name = NULL;
- int rc;
-#ifndef CURL_DISABLE_VERBOSE_STRINGS
- const char *tld_errmsg = "<no msg>";
-#else
- (void)data;
-#endif
-
- /* Convert (and downcase) ACE-name back into locale's character set */
- rc = idna_to_unicode_lzlz(ace_hostname, &uc_name, 0);
- if(rc != IDNA_SUCCESS)
- return FALSE;
-
- /* Warning: err_pos receives "the decoded character offset rather than the
- byte position in the string." And as of libidn 1.32 that character offset
- is for UTF-8, even if the passed in string is another locale. */
- rc = tld_check_lz(uc_name, &err_pos, NULL);
-#ifndef CURL_DISABLE_VERBOSE_STRINGS
-#ifdef HAVE_TLD_STRERROR
- if(rc != TLD_SUCCESS)
- tld_errmsg = tld_strerror((Tld_rc)rc);
-#endif
- if(rc != TLD_SUCCESS)
- infof(data, "WARNING: TLD check for %s failed; %s\n",
- uc_name, tld_errmsg);
-#endif /* CURL_DISABLE_VERBOSE_STRINGS */
- if(uc_name)
- idn_free(uc_name);
- if(rc != TLD_SUCCESS)
- return FALSE;
-
- return TRUE;
-}
-#endif
-
/*
* Perform any necessary IDN conversion of hostname
*/
-static void fix_hostname(struct Curl_easy *data,
- struct connectdata *conn, struct hostname *host)
+static void fix_hostname(struct connectdata *conn, struct hostname *host)
{
size_t len;
+ struct Curl_easy *data = conn->data;
-#ifndef USE_LIBIDN
+#ifndef USE_LIBIDN2
(void)data;
(void)conn;
#elif defined(CURL_DISABLE_VERBOSE_STRINGS)
(void)conn;
#endif
@@ -3838,29 +3786,22 @@ static void fix_hostname(struct Curl_easy *data,
there's no use for it */
host->name[len-1]=0;
/* Check name for non-ASCII and convert hostname to ACE form if we can */
if(!is_ASCII_name(host->name)) {
-#ifdef USE_LIBIDN
- if(stringprep_check_version(LIBIDN_REQUIRED_VERSION)) {
+#ifdef USE_LIBIDN2
+ if(idn2_check_version(IDN2_VERSION)) {
char *ace_hostname = NULL;
-
- int rc = idna_to_ascii_lz(host->name, &ace_hostname, 0);
- infof(data, "Input domain encoded as `%s'\n",
- stringprep_locale_charset());
- if(rc == IDNA_SUCCESS) {
- /* tld_check_name() displays a warning if the host name contains
- "illegal" characters for this TLD */
- (void)tld_check_name(data, ace_hostname);
-
- host->encalloc = ace_hostname;
+ int rc = idn2_lookup_ul((const char *)host->name, &ace_hostname, 0);
+ if(rc == IDN2_OK) {
+ host->encalloc = (char *)ace_hostname;
/* change the name pointer to point to the encoded hostname */
host->name = host->encalloc;
}
else
infof(data, "Failed to convert %s to ACE; %s\n", host->name,
- Curl_idn_strerror(conn, rc));
+ idn2_strerror(rc));
}
#elif defined(USE_WIN32_IDN)
char *ace_hostname = NULL;
if(curl_win32_idn_to_ascii(host->name, &ace_hostname)) {
@@ -3879,13 +3820,13 @@ static void fix_hostname(struct Curl_easy *data,
/*
* Frees data allocated by fix_hostname()
*/
static void free_fixed_hostname(struct hostname *host)
{
-#if defined(USE_LIBIDN)
+#if defined(USE_LIBIDN2)
if(host->encalloc) {
- idn_free(host->encalloc); /* must be freed with idn_free() since this was
+ idn2_free(host->encalloc); /* must be freed with idn2_free() since this was
allocated by libidn */
host->encalloc = NULL;
}
#elif defined(USE_WIN32_IDN)
free(host->encalloc); /* must be freed withidn_free() since this was
@@ -6044,15 +5985,15 @@ static CURLcode create_conn(struct Curl_easy *data,
goto out;
/*************************************************************
* IDN-fix the hostnames
*************************************************************/
- fix_hostname(data, conn, &conn->host);
+ fix_hostname(conn, &conn->host);
if(conn->bits.conn_to_host)
- fix_hostname(data, conn, &conn->conn_to_host);
+ fix_hostname(conn, &conn->conn_to_host);
if(conn->proxy.name && *conn->proxy.name)
- fix_hostname(data, conn, &conn->proxy);
+ fix_hostname(conn, &conn->proxy);
/*************************************************************
* Check whether the host and the "connect to host" are equal.
* Do this after the hostnames have been IDN-fixed .
*************************************************************/
diff --git a/lib/version.c b/lib/version.c
index 1292445..a434a62 100644
--- a/lib/version.c
+++ b/lib/version.c
@@ -34,12 +34,12 @@
# define CARES_STATICLIB
# endif
# include <ares.h>
#endif
-#ifdef USE_LIBIDN
-#include <stringprep.h>
+#ifdef USE_LIBIDN2
+#include <idn2.h>
#endif
#ifdef USE_LIBPSL
#include <libpsl.h>
#endif
@@ -109,13 +109,13 @@ char *curl_version(void)
/* this function is only present in c-ares, not in the original ares */
len = snprintf(ptr, left, " c-ares/%s", ares_version(NULL));
left -= len;
ptr += len;
#endif
-#ifdef USE_LIBIDN
- if(stringprep_check_version(LIBIDN_REQUIRED_VERSION)) {
- len = snprintf(ptr, left, " libidn/%s", stringprep_check_version(NULL));
+#ifdef USE_LIBIDN2
+ if(idn2_check_version(IDN2_VERSION)) {
+ len = snprintf(ptr, left, " libidn2/%s", idn2_check_version(NULL));
left -= len;
ptr += len;
}
#endif
#ifdef USE_LIBPSL
@@ -363,14 +363,14 @@ curl_version_info_data *curl_version_info(CURLversion stamp)
int aresnum;
version_info.ares = ares_version(&aresnum);
version_info.ares_num = aresnum;
}
#endif
-#ifdef USE_LIBIDN
+#ifdef USE_LIBIDN2
/* This returns a version string if we use the given version or later,
otherwise it returns NULL */
- version_info.libidn = stringprep_check_version(LIBIDN_REQUIRED_VERSION);
+ version_info.libidn = idn2_check_version(IDN2_VERSION);
if(version_info.libidn)
version_info.features |= CURL_VERSION_IDN;
#elif defined(USE_WIN32_IDN)
version_info.features |= CURL_VERSION_IDN;
#endif
--
2.9.3