visaljs 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/THIRD_PARTY_LICENSES +31 -1
- package/cli.js +962 -68
- package/node/include/js_node.h +11 -1
- package/node/prelude/_http_common.js +29 -0
- package/node/prelude/async_hooks.js +50 -11
- package/node/prelude/child_process.js +31 -4
- package/node/prelude/console.js +311 -143
- package/node/prelude/crypto.js +6 -4
- package/node/prelude/dgram.js +1169 -0
- package/node/prelude/diagnostics_channel.js +3 -1
- package/node/prelude/dns.js +250 -45
- package/node/prelude/dns_promises.js +8 -2
- package/node/prelude/fs_promises.js +9 -1
- package/node/prelude/http.js +395 -86
- package/node/prelude/https.js +13 -4
- package/node/prelude/internal/console_class.js +7 -0
- package/node/prelude/internal/console_global.js +25 -0
- package/node/prelude/internal/crypto/key_encryption.js +217 -0
- package/node/prelude/internal/crypto/keys.js +161 -26
- package/node/prelude/internal/crypto/random.js +24 -0
- package/node/prelude/internal/crypto/util.js +2 -1
- package/node/prelude/internal/crypto_x509.js +161 -0
- package/node/prelude/internal/dns_classes.js +6 -0
- package/node/prelude/internal/dns_resolver.js +371 -0
- package/node/prelude/internal/errors.js +9 -0
- package/node/prelude/internal/events_on.js +82 -37
- package/node/prelude/internal/features.js +8 -4
- package/node/prelude/internal/fs_filehandle.js +10 -4
- package/node/prelude/internal/perf_histogram.js +1 -1
- package/node/prelude/internal/process_more.js +32 -17
- package/node/prelude/internal/process_signals.js +8 -2
- package/node/prelude/internal/punycode.ts +163 -0
- package/node/prelude/internal/readline.js +648 -274
- package/node/prelude/internal/readline_editor.js +1240 -0
- package/node/prelude/internal/string_width.js +43 -0
- package/node/prelude/internal/tls/common.js +145 -33
- package/node/prelude/internal/tls/wrap.js +182 -49
- package/node/prelude/internal/tls/x509.js +4 -1
- package/node/prelude/internal/udp.js +177 -0
- package/node/prelude/net.js +13 -1
- package/node/prelude/os.js +24 -6
- package/node/prelude/perf_hooks.js +37 -2
- package/node/prelude/punycode.js +2 -130
- package/node/prelude/readline.js +113 -4
- package/node/prelude/readline_promises.js +56 -32
- package/node/prelude/tls.js +21 -4
- package/node/prelude/util.js +3 -16
- package/node/src/host_dns.c +623 -0
- package/node/src/host_http.c +12 -0
- package/node/src/host_net.c +46 -0
- package/node/src/host_os.c +1 -6
- package/node/src/host_sys.c +70 -0
- package/node/src/host_udp.c +418 -0
- package/node/third_party/c-ares/LICENSE.md +24 -0
- package/node/third_party/c-ares/config/darwin/ares_config.h +573 -0
- package/node/third_party/c-ares/config/freebsd/ares_config.h +573 -0
- package/node/third_party/c-ares/config/linux/ares_config.h +573 -0
- package/node/third_party/c-ares/config/openbsd/ares_config.h +583 -0
- package/node/third_party/c-ares/include/ares.h +1237 -0
- package/node/third_party/c-ares/include/ares_build.h +202 -0
- package/node/third_party/c-ares/include/ares_dns.h +127 -0
- package/node/third_party/c-ares/include/ares_dns_record.h +1119 -0
- package/node/third_party/c-ares/include/ares_nameser.h +510 -0
- package/node/third_party/c-ares/include/ares_version.h +47 -0
- package/node/third_party/c-ares/src/lib/ares_addrinfo2hostent.c +305 -0
- package/node/third_party/c-ares/src/lib/ares_addrinfo_localhost.c +245 -0
- package/node/third_party/c-ares/src/lib/ares_android.c +496 -0
- package/node/third_party/c-ares/src/lib/ares_android.h +38 -0
- package/node/third_party/c-ares/src/lib/ares_cancel.c +87 -0
- package/node/third_party/c-ares/src/lib/ares_close_sockets.c +137 -0
- package/node/third_party/c-ares/src/lib/ares_conn.c +511 -0
- package/node/third_party/c-ares/src/lib/ares_conn.h +202 -0
- package/node/third_party/c-ares/src/lib/ares_cookie.c +461 -0
- package/node/third_party/c-ares/src/lib/ares_data.c +168 -0
- package/node/third_party/c-ares/src/lib/ares_data.h +92 -0
- package/node/third_party/c-ares/src/lib/ares_destroy.c +159 -0
- package/node/third_party/c-ares/src/lib/ares_free_hostent.c +54 -0
- package/node/third_party/c-ares/src/lib/ares_free_string.c +33 -0
- package/node/third_party/c-ares/src/lib/ares_freeaddrinfo.c +67 -0
- package/node/third_party/c-ares/src/lib/ares_getaddrinfo.c +806 -0
- package/node/third_party/c-ares/src/lib/ares_getenv.c +38 -0
- package/node/third_party/c-ares/src/lib/ares_getenv.h +34 -0
- package/node/third_party/c-ares/src/lib/ares_gethostbyaddr.c +229 -0
- package/node/third_party/c-ares/src/lib/ares_gethostbyname.c +341 -0
- package/node/third_party/c-ares/src/lib/ares_getnameinfo.c +437 -0
- package/node/third_party/c-ares/src/lib/ares_hosts_file.c +960 -0
- package/node/third_party/c-ares/src/lib/ares_inet_net_pton.h +31 -0
- package/node/third_party/c-ares/src/lib/ares_init.c +631 -0
- package/node/third_party/c-ares/src/lib/ares_ipv6.h +115 -0
- package/node/third_party/c-ares/src/lib/ares_library_init.c +190 -0
- package/node/third_party/c-ares/src/lib/ares_metrics.c +261 -0
- package/node/third_party/c-ares/src/lib/ares_options.c +492 -0
- package/node/third_party/c-ares/src/lib/ares_parse_into_addrinfo.c +179 -0
- package/node/third_party/c-ares/src/lib/ares_private.h +648 -0
- package/node/third_party/c-ares/src/lib/ares_process.c +1649 -0
- package/node/third_party/c-ares/src/lib/ares_qcache.c +442 -0
- package/node/third_party/c-ares/src/lib/ares_query.c +151 -0
- package/node/third_party/c-ares/src/lib/ares_search.c +623 -0
- package/node/third_party/c-ares/src/lib/ares_send.c +300 -0
- package/node/third_party/c-ares/src/lib/ares_set_socket_functions.c +590 -0
- package/node/third_party/c-ares/src/lib/ares_setup.h +224 -0
- package/node/third_party/c-ares/src/lib/ares_socket.c +427 -0
- package/node/third_party/c-ares/src/lib/ares_socket.h +163 -0
- package/node/third_party/c-ares/src/lib/ares_sortaddrinfo.c +447 -0
- package/node/third_party/c-ares/src/lib/ares_strerror.c +91 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig.c +642 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_files.c +851 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_mac.c +373 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_win.c +673 -0
- package/node/third_party/c-ares/src/lib/ares_timeout.c +162 -0
- package/node/third_party/c-ares/src/lib/ares_update_servers.c +1376 -0
- package/node/third_party/c-ares/src/lib/ares_version.c +36 -0
- package/node/third_party/c-ares/src/lib/config-dos.h +114 -0
- package/node/third_party/c-ares/src/lib/config-win32.h +396 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_array.c +409 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable.c +451 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable.h +174 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_asvp.c +224 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_dict.c +230 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_strvp.c +210 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_szvp.c +188 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpstr.c +186 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpvp.c +194 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_llist.c +385 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_slist.c +479 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_slist.h +207 -0
- package/node/third_party/c-ares/src/lib/event/ares_event.h +191 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_configchg.c +746 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_epoll.c +192 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_kqueue.c +248 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_poll.c +140 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_select.c +159 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_thread.c +575 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_wake_pipe.c +172 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_win32.c +981 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_win32.h +161 -0
- package/node/third_party/c-ares/src/lib/include/ares_array.h +276 -0
- package/node/third_party/c-ares/src/lib/include/ares_buf.h +732 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_asvp.h +130 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_dict.h +123 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_strvp.h +130 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_szvp.h +118 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_vpstr.h +111 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_vpvp.h +128 -0
- package/node/third_party/c-ares/src/lib/include/ares_llist.h +239 -0
- package/node/third_party/c-ares/src/lib/include/ares_mem.h +41 -0
- package/node/third_party/c-ares/src/lib/include/ares_str.h +261 -0
- package/node/third_party/c-ares/src/lib/inet_net_pton.c +451 -0
- package/node/third_party/c-ares/src/lib/inet_ntop.c +219 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_create_query.c +78 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_expand_name.c +99 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_expand_string.c +107 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_fds.c +80 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_getsock.c +85 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_a_reply.c +107 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_mapping.c +982 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.c +309 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.h +72 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_name.c +736 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_parse.c +1360 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_private.h +273 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_record.c +1701 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_write.c +1229 -0
- package/node/third_party/c-ares/src/lib/str/ares_buf.c +1510 -0
- package/node/third_party/c-ares/src/lib/str/ares_str.c +562 -0
- package/node/third_party/c-ares/src/lib/str/ares_strsplit.c +90 -0
- package/node/third_party/c-ares/src/lib/str/ares_strsplit.h +51 -0
- package/node/third_party/c-ares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
- package/node/third_party/c-ares/src/lib/util/ares_iface_ips.c +640 -0
- package/node/third_party/c-ares/src/lib/util/ares_iface_ips.h +140 -0
- package/node/third_party/c-ares/src/lib/util/ares_math.c +167 -0
- package/node/third_party/c-ares/src/lib/util/ares_math.h +58 -0
- package/node/third_party/c-ares/src/lib/util/ares_rand.c +389 -0
- package/node/third_party/c-ares/src/lib/util/ares_rand.h +36 -0
- package/node/third_party/c-ares/src/lib/util/ares_threads.c +613 -0
- package/node/third_party/c-ares/src/lib/util/ares_threads.h +60 -0
- package/node/third_party/c-ares/src/lib/util/ares_time.h +49 -0
- package/node/third_party/c-ares/src/lib/util/ares_timeval.c +95 -0
- package/node/third_party/c-ares/src/lib/util/ares_uri.c +1627 -0
- package/node/third_party/c-ares/src/lib/util/ares_uri.h +252 -0
- package/node/third_party/c-ares/src/lib/windows_port.c +29 -0
- package/package.json +1 -1
- package/prebuilt/darwin-arm64/cares-a6286c65ca9374a3.a +0 -0
- package/prebuilt/darwin-x64/cares-a6286c65ca9374a3.a +0 -0
- package/prebuilt/linux-arm64/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-arm64-musl/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-x64/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-x64-musl/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
- package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
- package/prebuilt/win32-x64/cares-49c9ec95162b912d.a +0 -0
- package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
- package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
- package/runtime/include/js_builtins.h +5 -0
- package/runtime/include/js_crypto.h +11 -0
- package/runtime/include/js_gc.h +13 -10
- package/runtime/include/js_jobs.h +2 -0
- package/runtime/include/js_object.h +58 -0
- package/runtime/include/jscontext.h +1 -0
- package/runtime/src/crypto_internal.h +1 -0
- package/runtime/src/crypto_subtle.c +66 -7
- package/runtime/src/crypto_tls.c +265 -19
- package/runtime/src/gc.c +73 -92
- package/runtime/src/inspect.c +18 -1
- package/runtime/src/jobs.c +37 -22
- package/runtime/src/object.c +49 -2
- package/runtime/src/os.c +16 -6
- package/runtime/src/os.h +2 -0
- package/runtime/src/process.c +97 -10
|
@@ -0,0 +1,736 @@
|
|
|
1
|
+
/* MIT License
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) 2023 Brad House
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice (including the next
|
|
13
|
+
* paragraph) shall be included in all copies or substantial portions of the
|
|
14
|
+
* Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*
|
|
24
|
+
* SPDX-License-Identifier: MIT
|
|
25
|
+
*/
|
|
26
|
+
#include "ares_private.h"
|
|
27
|
+
|
|
28
|
+
/* RFC 1035 3.1 limits a name to 255 octets. We track presentation length
|
|
29
|
+
* (label octets plus one separator before each label after the first), which is
|
|
30
|
+
* up to ~2 octets looser than the strict wire limit and so never rejects a
|
|
31
|
+
* compliant name. Shared by the read and write paths. */
|
|
32
|
+
#define ARES_MAX_NAME_PRESENTATION_LEN 255
|
|
33
|
+
|
|
34
|
+
/* A name of <= 255 octets holds at most 128 labels, so it can never legitimately
|
|
35
|
+
* require more than that many compression-pointer jumps. Bounding the number of
|
|
36
|
+
* indirections stops a name built purely from pointers (which never adds label
|
|
37
|
+
* bytes, so the length cap never fires) from being walked without limit. */
|
|
38
|
+
#define ARES_MAX_INDIRS 128
|
|
39
|
+
|
|
40
|
+
typedef struct {
|
|
41
|
+
char *name;
|
|
42
|
+
size_t name_len;
|
|
43
|
+
size_t idx;
|
|
44
|
+
} ares_nameoffset_t;
|
|
45
|
+
|
|
46
|
+
static void ares_nameoffset_free(void *arg)
|
|
47
|
+
{
|
|
48
|
+
ares_nameoffset_t *off = arg;
|
|
49
|
+
if (off == NULL) {
|
|
50
|
+
return; /* LCOV_EXCL_LINE: DefensiveCoding */
|
|
51
|
+
}
|
|
52
|
+
ares_free(off->name);
|
|
53
|
+
ares_free(off);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static ares_status_t ares_nameoffset_create(ares_llist_t **list,
|
|
57
|
+
const char *name, size_t idx)
|
|
58
|
+
{
|
|
59
|
+
ares_status_t status;
|
|
60
|
+
ares_nameoffset_t *off = NULL;
|
|
61
|
+
|
|
62
|
+
if (list == NULL || name == NULL || ares_strlen(name) == 0 ||
|
|
63
|
+
ares_strlen(name) > ARES_MAX_NAME_PRESENTATION_LEN) {
|
|
64
|
+
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* Don't record a name as a compression target if it can't be referenced by
|
|
68
|
+
* a pointer. DNS name compression offsets are only 14 bits (RFC 1035
|
|
69
|
+
* 4.1.4), so a name positioned beyond 0x3FFF would have its offset
|
|
70
|
+
* truncated when written, producing a pointer to the wrong location. */
|
|
71
|
+
if (idx > 0x3FFF) {
|
|
72
|
+
return ARES_SUCCESS;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (*list == NULL) {
|
|
76
|
+
*list = ares_llist_create(ares_nameoffset_free);
|
|
77
|
+
}
|
|
78
|
+
if (*list == NULL) {
|
|
79
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
80
|
+
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
off = ares_malloc_zero(sizeof(*off));
|
|
84
|
+
if (off == NULL) {
|
|
85
|
+
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
off->name = ares_strdup(name);
|
|
89
|
+
if (off->name == NULL) {
|
|
90
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
91
|
+
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
off->name_len = ares_strlen(off->name);
|
|
95
|
+
off->idx = idx;
|
|
96
|
+
|
|
97
|
+
if (ares_llist_insert_last(*list, off) == NULL) {
|
|
98
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
99
|
+
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return ARES_SUCCESS;
|
|
103
|
+
|
|
104
|
+
/* LCOV_EXCL_START: OutOfMemory */
|
|
105
|
+
fail:
|
|
106
|
+
ares_nameoffset_free(off);
|
|
107
|
+
return status;
|
|
108
|
+
/* LCOV_EXCL_STOP */
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
static const ares_nameoffset_t *ares_nameoffset_find(ares_llist_t *list,
|
|
112
|
+
const char *name)
|
|
113
|
+
{
|
|
114
|
+
size_t name_len = ares_strlen(name);
|
|
115
|
+
ares_llist_node_t *node;
|
|
116
|
+
const ares_nameoffset_t *longest_match = NULL;
|
|
117
|
+
|
|
118
|
+
if (list == NULL || name == NULL || name_len == 0) {
|
|
119
|
+
return NULL;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
for (node = ares_llist_node_first(list); node != NULL;
|
|
123
|
+
node = ares_llist_node_next(node)) {
|
|
124
|
+
const ares_nameoffset_t *val = ares_llist_node_val(node);
|
|
125
|
+
size_t prefix_len;
|
|
126
|
+
|
|
127
|
+
/* Can't be a match if the stored name is longer */
|
|
128
|
+
if (val->name_len > name_len) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/* Can't be the longest match if our existing longest match is longer */
|
|
133
|
+
if (longest_match != NULL && longest_match->name_len > val->name_len) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
prefix_len = name_len - val->name_len;
|
|
138
|
+
|
|
139
|
+
/* Due to DNS 0x20, lets not inadvertently mangle things, use case-sensitive
|
|
140
|
+
* matching instead of case-insensitive. This may result in slightly
|
|
141
|
+
* larger DNS queries overall. */
|
|
142
|
+
if (!ares_streq(val->name, name + prefix_len)) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* We need to make sure if `val->name` is "example.com" that name is
|
|
147
|
+
* is separated by a label, e.g. "myexample.com" is not ok, however
|
|
148
|
+
* "my.example.com" is, so we look for the preceding "." */
|
|
149
|
+
if (prefix_len != 0 && name[prefix_len - 1] != '.') {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
longest_match = val;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return longest_match;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static void ares_dns_labels_free_cb(void *arg)
|
|
160
|
+
{
|
|
161
|
+
ares_buf_t **buf = arg;
|
|
162
|
+
if (buf == NULL) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
ares_buf_destroy(*buf);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static ares_buf_t *ares_dns_labels_add(ares_array_t *labels)
|
|
170
|
+
{
|
|
171
|
+
ares_buf_t **buf;
|
|
172
|
+
|
|
173
|
+
if (labels == NULL) {
|
|
174
|
+
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (ares_array_insert_last((void **)&buf, labels) != ARES_SUCCESS) {
|
|
178
|
+
return NULL;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
*buf = ares_buf_create();
|
|
182
|
+
if (*buf == NULL) {
|
|
183
|
+
ares_array_remove_last(labels);
|
|
184
|
+
return NULL;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return *buf;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static ares_buf_t *ares_dns_labels_get_last(ares_array_t *labels)
|
|
191
|
+
{
|
|
192
|
+
ares_buf_t **buf = ares_array_last(labels);
|
|
193
|
+
|
|
194
|
+
if (buf == NULL) {
|
|
195
|
+
return NULL;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return *buf;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
static ares_buf_t *ares_dns_labels_get_at(ares_array_t *labels, size_t idx)
|
|
202
|
+
{
|
|
203
|
+
ares_buf_t **buf = ares_array_at(labels, idx);
|
|
204
|
+
|
|
205
|
+
if (buf == NULL) {
|
|
206
|
+
return NULL;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return *buf;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
static void ares_dns_name_labels_del_last(ares_array_t *labels)
|
|
213
|
+
{
|
|
214
|
+
ares_array_remove_last(labels);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
static ares_status_t ares_parse_dns_name_escape(ares_buf_t *namebuf,
|
|
218
|
+
ares_buf_t *label,
|
|
219
|
+
ares_bool_t validate_hostname)
|
|
220
|
+
{
|
|
221
|
+
ares_status_t status;
|
|
222
|
+
unsigned char c;
|
|
223
|
+
|
|
224
|
+
status = ares_buf_fetch_bytes(namebuf, &c, 1);
|
|
225
|
+
if (status != ARES_SUCCESS) {
|
|
226
|
+
return ARES_EBADNAME;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/* If next character is a digit, read 2 more digits */
|
|
230
|
+
if (ares_isdigit(c)) {
|
|
231
|
+
size_t i;
|
|
232
|
+
unsigned int val = 0;
|
|
233
|
+
|
|
234
|
+
val = c - '0';
|
|
235
|
+
|
|
236
|
+
for (i = 0; i < 2; i++) {
|
|
237
|
+
status = ares_buf_fetch_bytes(namebuf, &c, 1);
|
|
238
|
+
if (status != ARES_SUCCESS) {
|
|
239
|
+
return ARES_EBADNAME;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!ares_isdigit(c)) {
|
|
243
|
+
return ARES_EBADNAME;
|
|
244
|
+
}
|
|
245
|
+
val *= 10;
|
|
246
|
+
val += c - '0';
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/* Out of range */
|
|
250
|
+
if (val > 255) {
|
|
251
|
+
return ARES_EBADNAME;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (validate_hostname && !ares_is_hostnamech((unsigned char)val)) {
|
|
255
|
+
return ARES_EBADNAME;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return ares_buf_append_byte(label, (unsigned char)val);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/* We can just output the character */
|
|
262
|
+
if (validate_hostname && !ares_is_hostnamech(c)) {
|
|
263
|
+
return ARES_EBADNAME;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return ares_buf_append_byte(label, c);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
static ares_status_t ares_split_dns_name(ares_array_t *labels,
|
|
270
|
+
ares_bool_t validate_hostname,
|
|
271
|
+
const char *name)
|
|
272
|
+
{
|
|
273
|
+
ares_status_t status;
|
|
274
|
+
ares_buf_t *label = NULL;
|
|
275
|
+
ares_buf_t *namebuf = NULL;
|
|
276
|
+
size_t i;
|
|
277
|
+
size_t total_len = 0;
|
|
278
|
+
unsigned char c;
|
|
279
|
+
|
|
280
|
+
if (name == NULL || labels == NULL) {
|
|
281
|
+
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/* Put name into a buffer for parsing */
|
|
285
|
+
namebuf = ares_buf_create();
|
|
286
|
+
if (namebuf == NULL) {
|
|
287
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
288
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (*name != '\0') {
|
|
292
|
+
status =
|
|
293
|
+
ares_buf_append(namebuf, (const unsigned char *)name, ares_strlen(name));
|
|
294
|
+
if (status != ARES_SUCCESS) {
|
|
295
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/* Start with 1 label */
|
|
300
|
+
label = ares_dns_labels_add(labels);
|
|
301
|
+
if (label == NULL) {
|
|
302
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
303
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
while (ares_buf_fetch_bytes(namebuf, &c, 1) == ARES_SUCCESS) {
|
|
307
|
+
/* New label */
|
|
308
|
+
if (c == '.') {
|
|
309
|
+
label = ares_dns_labels_add(labels);
|
|
310
|
+
if (label == NULL) {
|
|
311
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
312
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
313
|
+
}
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/* Escape */
|
|
318
|
+
if (c == '\\') {
|
|
319
|
+
status = ares_parse_dns_name_escape(namebuf, label, validate_hostname);
|
|
320
|
+
if (status != ARES_SUCCESS) {
|
|
321
|
+
goto done;
|
|
322
|
+
}
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/* Output direct character */
|
|
327
|
+
if (validate_hostname && !ares_is_hostnamech(c)) {
|
|
328
|
+
status = ARES_EBADNAME;
|
|
329
|
+
goto done;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
status = ares_buf_append_byte(label, c);
|
|
333
|
+
if (status != ARES_SUCCESS) {
|
|
334
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/* Remove trailing blank label */
|
|
339
|
+
if (ares_buf_len(ares_dns_labels_get_last(labels)) == 0) {
|
|
340
|
+
ares_dns_name_labels_del_last(labels);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/* If someone passed in "." there could have been 2 blank labels, check for
|
|
344
|
+
* that */
|
|
345
|
+
if (ares_array_len(labels) == 1 &&
|
|
346
|
+
ares_buf_len(ares_dns_labels_get_last(labels)) == 0) {
|
|
347
|
+
ares_dns_name_labels_del_last(labels);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/* Scan to make sure label lengths are valid */
|
|
351
|
+
for (i = 0; i < ares_array_len(labels); i++) {
|
|
352
|
+
const ares_buf_t *buf = ares_dns_labels_get_at(labels, i);
|
|
353
|
+
size_t len = ares_buf_len(buf);
|
|
354
|
+
/* No 0-length labels, and no labels over 63 bytes */
|
|
355
|
+
if (len == 0 || len > 63) {
|
|
356
|
+
status = ARES_EBADNAME;
|
|
357
|
+
goto done;
|
|
358
|
+
}
|
|
359
|
+
total_len += len;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/* Can't exceed maximum (unescaped) length */
|
|
363
|
+
if (ares_array_len(labels) &&
|
|
364
|
+
total_len + ares_array_len(labels) - 1 > ARES_MAX_NAME_PRESENTATION_LEN) {
|
|
365
|
+
status = ARES_EBADNAME;
|
|
366
|
+
goto done;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
status = ARES_SUCCESS;
|
|
370
|
+
|
|
371
|
+
done:
|
|
372
|
+
ares_buf_destroy(namebuf);
|
|
373
|
+
return status;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
ares_status_t ares_dns_name_write(ares_buf_t *buf, ares_llist_t **list,
|
|
377
|
+
ares_bool_t validate_hostname,
|
|
378
|
+
const char *name)
|
|
379
|
+
{
|
|
380
|
+
const ares_nameoffset_t *off = NULL;
|
|
381
|
+
size_t name_len;
|
|
382
|
+
size_t orig_name_len;
|
|
383
|
+
size_t pos = ares_buf_len(buf);
|
|
384
|
+
ares_array_t *labels = NULL;
|
|
385
|
+
char name_copy[512];
|
|
386
|
+
ares_status_t status;
|
|
387
|
+
|
|
388
|
+
if (buf == NULL || name == NULL) {
|
|
389
|
+
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
labels = ares_array_create(sizeof(ares_buf_t *), ares_dns_labels_free_cb);
|
|
393
|
+
if (labels == NULL) {
|
|
394
|
+
return ARES_ENOMEM;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/* NOTE: due to possible escaping, name_copy buffer is > 256 to allow for
|
|
398
|
+
* this */
|
|
399
|
+
name_len = ares_strcpy(name_copy, name, sizeof(name_copy));
|
|
400
|
+
orig_name_len = name_len;
|
|
401
|
+
|
|
402
|
+
/* Find longest match */
|
|
403
|
+
if (list != NULL) {
|
|
404
|
+
off = ares_nameoffset_find(*list, name_copy);
|
|
405
|
+
if (off != NULL && off->name_len != name_len) {
|
|
406
|
+
/* truncate */
|
|
407
|
+
name_len -= (off->name_len + 1);
|
|
408
|
+
name_copy[name_len] = 0;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/* Output labels */
|
|
413
|
+
if (off == NULL || off->name_len != orig_name_len) {
|
|
414
|
+
size_t i;
|
|
415
|
+
|
|
416
|
+
status = ares_split_dns_name(labels, validate_hostname, name_copy);
|
|
417
|
+
if (status != ARES_SUCCESS) {
|
|
418
|
+
goto done;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
for (i = 0; i < ares_array_len(labels); i++) {
|
|
422
|
+
size_t len = 0;
|
|
423
|
+
const ares_buf_t *lbuf = ares_dns_labels_get_at(labels, i);
|
|
424
|
+
const unsigned char *ptr = ares_buf_peek(lbuf, &len);
|
|
425
|
+
|
|
426
|
+
status = ares_buf_append_byte(buf, (unsigned char)(len & 0xFF));
|
|
427
|
+
if (status != ARES_SUCCESS) {
|
|
428
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
status = ares_buf_append(buf, ptr, len);
|
|
432
|
+
if (status != ARES_SUCCESS) {
|
|
433
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/* If we are NOT jumping to another label, output terminator */
|
|
438
|
+
if (off == NULL) {
|
|
439
|
+
status = ares_buf_append_byte(buf, 0);
|
|
440
|
+
if (status != ARES_SUCCESS) {
|
|
441
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/* Output name compression offset jump */
|
|
447
|
+
if (off != NULL) {
|
|
448
|
+
/* off->idx is guaranteed to fit in 14 bits: ares_nameoffset_create()
|
|
449
|
+
* refuses to record offsets beyond 0x3FFF, so the mask below never
|
|
450
|
+
* actually truncates. */
|
|
451
|
+
unsigned short u16 =
|
|
452
|
+
(unsigned short)0xC000 | (unsigned short)(off->idx & 0x3FFF);
|
|
453
|
+
status = ares_buf_append_be16(buf, u16);
|
|
454
|
+
if (status != ARES_SUCCESS) {
|
|
455
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/* Store pointer for future jumps as long as its not an exact match for
|
|
460
|
+
* a prior entry */
|
|
461
|
+
if (list != NULL && (off == NULL || off->name_len != orig_name_len) &&
|
|
462
|
+
name_len > 0) {
|
|
463
|
+
status = ares_nameoffset_create(list, name /* not truncated copy! */, pos);
|
|
464
|
+
if (status != ARES_SUCCESS) {
|
|
465
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
status = ARES_SUCCESS;
|
|
470
|
+
|
|
471
|
+
done:
|
|
472
|
+
ares_array_destroy(labels);
|
|
473
|
+
return status;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/* Reserved characters for names that need to be escaped */
|
|
477
|
+
static ares_bool_t is_reservedch(int ch)
|
|
478
|
+
{
|
|
479
|
+
switch (ch) {
|
|
480
|
+
case '"':
|
|
481
|
+
case '.':
|
|
482
|
+
case ';':
|
|
483
|
+
case '\\':
|
|
484
|
+
case '(':
|
|
485
|
+
case ')':
|
|
486
|
+
case '@':
|
|
487
|
+
case '$':
|
|
488
|
+
return ARES_TRUE;
|
|
489
|
+
default:
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return ARES_FALSE;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
static ares_status_t ares_fetch_dnsname_into_buf(ares_buf_t *buf,
|
|
497
|
+
ares_buf_t *dest, size_t len,
|
|
498
|
+
ares_bool_t is_hostname)
|
|
499
|
+
{
|
|
500
|
+
size_t remaining_len;
|
|
501
|
+
const unsigned char *ptr = ares_buf_peek(buf, &remaining_len);
|
|
502
|
+
ares_status_t status;
|
|
503
|
+
size_t i;
|
|
504
|
+
|
|
505
|
+
if (buf == NULL || len == 0 || remaining_len < len) {
|
|
506
|
+
return ARES_EBADRESP;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
for (i = 0; i < len; i++) {
|
|
510
|
+
unsigned char c = ptr[i];
|
|
511
|
+
|
|
512
|
+
/* Hostnames have a very specific allowed character set. Anything outside
|
|
513
|
+
* of that (non-printable and reserved included) are disallowed */
|
|
514
|
+
if (is_hostname && !ares_is_hostnamech(c)) {
|
|
515
|
+
status = ARES_EBADRESP;
|
|
516
|
+
goto fail;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/* NOTE: dest may be NULL if the user is trying to skip the name. validation
|
|
520
|
+
* still occurs above. */
|
|
521
|
+
if (dest == NULL) {
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/* Non-printable characters need to be output as \DDD */
|
|
526
|
+
if (!ares_isprint(c)) {
|
|
527
|
+
unsigned char escape[4];
|
|
528
|
+
|
|
529
|
+
escape[0] = '\\';
|
|
530
|
+
escape[1] = '0' + (c / 100);
|
|
531
|
+
escape[2] = '0' + ((c % 100) / 10);
|
|
532
|
+
escape[3] = '0' + (c % 10);
|
|
533
|
+
|
|
534
|
+
status = ares_buf_append(dest, escape, sizeof(escape));
|
|
535
|
+
if (status != ARES_SUCCESS) {
|
|
536
|
+
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/* Reserved characters need to be escaped, otherwise normal */
|
|
543
|
+
if (is_reservedch(c)) {
|
|
544
|
+
status = ares_buf_append_byte(dest, '\\');
|
|
545
|
+
if (status != ARES_SUCCESS) {
|
|
546
|
+
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
status = ares_buf_append_byte(dest, c);
|
|
551
|
+
if (status != ARES_SUCCESS) {
|
|
552
|
+
return status; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
return ares_buf_consume(buf, len);
|
|
557
|
+
|
|
558
|
+
fail:
|
|
559
|
+
return status;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
ares_status_t ares_dns_name_parse(ares_buf_t *buf, char **name,
|
|
563
|
+
ares_bool_t is_hostname,
|
|
564
|
+
ares_bool_t allow_compression)
|
|
565
|
+
{
|
|
566
|
+
size_t save_offset = 0;
|
|
567
|
+
unsigned char c;
|
|
568
|
+
ares_status_t status;
|
|
569
|
+
ares_buf_t *namebuf = NULL;
|
|
570
|
+
size_t label_start = ares_buf_get_position(buf);
|
|
571
|
+
size_t name_len = 0;
|
|
572
|
+
size_t indir = 0;
|
|
573
|
+
|
|
574
|
+
if (buf == NULL) {
|
|
575
|
+
return ARES_EFORMERR;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (name != NULL) {
|
|
579
|
+
namebuf = ares_buf_create();
|
|
580
|
+
if (namebuf == NULL) {
|
|
581
|
+
status = ARES_ENOMEM;
|
|
582
|
+
goto fail;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/* The compression scheme allows a domain name in a message to be
|
|
587
|
+
* represented as either:
|
|
588
|
+
*
|
|
589
|
+
* - a sequence of labels ending in a zero octet
|
|
590
|
+
* - a pointer
|
|
591
|
+
* - a sequence of labels ending with a pointer
|
|
592
|
+
*/
|
|
593
|
+
while (1) {
|
|
594
|
+
/* Keep track of the minimum label starting position to prevent forward
|
|
595
|
+
* jumping */
|
|
596
|
+
if (label_start > ares_buf_get_position(buf)) {
|
|
597
|
+
label_start = ares_buf_get_position(buf);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
status = ares_buf_fetch_bytes(buf, &c, 1);
|
|
601
|
+
if (status != ARES_SUCCESS) {
|
|
602
|
+
goto fail;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/* Pointer/Redirect */
|
|
606
|
+
if ((c & 0xc0) == 0xc0) {
|
|
607
|
+
/* The pointer takes the form of a two octet sequence:
|
|
608
|
+
*
|
|
609
|
+
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
|
610
|
+
* | 1 1| OFFSET |
|
|
611
|
+
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
|
612
|
+
*
|
|
613
|
+
* The first two bits are ones. This allows a pointer to be distinguished
|
|
614
|
+
* from a label, since the label must begin with two zero bits because
|
|
615
|
+
* labels are restricted to 63 octets or less. (The 10 and 01
|
|
616
|
+
* combinations are reserved for future use.) The OFFSET field specifies
|
|
617
|
+
* an offset from the start of the message (i.e., the first octet of the
|
|
618
|
+
* ID field in the domain header). A zero offset specifies the first byte
|
|
619
|
+
* of the ID field, etc.
|
|
620
|
+
*/
|
|
621
|
+
size_t offset = (size_t)((c & 0x3F) << 8);
|
|
622
|
+
|
|
623
|
+
/* Some RR types (e.g. SRV) do not permit name compression within their
|
|
624
|
+
* RDATA. Reject a compression pointer when it is not allowed. */
|
|
625
|
+
if (!allow_compression) {
|
|
626
|
+
status = ARES_EBADNAME;
|
|
627
|
+
goto fail;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/* Fetch second byte of the redirect length */
|
|
631
|
+
status = ares_buf_fetch_bytes(buf, &c, 1);
|
|
632
|
+
if (status != ARES_SUCCESS) {
|
|
633
|
+
goto fail;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
offset |= ((size_t)c);
|
|
637
|
+
|
|
638
|
+
/* According to RFC 1035 4.1.4:
|
|
639
|
+
* In this scheme, an entire domain name or a list of labels at
|
|
640
|
+
* the end of a domain name is replaced with a pointer to a prior
|
|
641
|
+
* occurrence of the same name.
|
|
642
|
+
* Note the word "prior", meaning it must go backwards. This was
|
|
643
|
+
* confirmed via the ISC BIND code that it also prevents forward
|
|
644
|
+
* pointers.
|
|
645
|
+
*/
|
|
646
|
+
if (offset >= label_start) {
|
|
647
|
+
status = ARES_EBADNAME;
|
|
648
|
+
goto fail;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/* Bound the number of indirections. A name made purely of pointers never
|
|
652
|
+
* adds label bytes, so the length cap below can't stop it; the
|
|
653
|
+
* strictly-decreasing rule alone still allows thousands of jumps per name.
|
|
654
|
+
* No legitimate <= 255 octet name needs more than 128 labels/jumps. */
|
|
655
|
+
indir++;
|
|
656
|
+
if (indir > ARES_MAX_INDIRS) {
|
|
657
|
+
status = ARES_EBADNAME;
|
|
658
|
+
goto fail;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/* First time we make a jump, save the current position */
|
|
662
|
+
if (save_offset == 0) {
|
|
663
|
+
save_offset = ares_buf_get_position(buf);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
status = ares_buf_set_position(buf, offset);
|
|
667
|
+
if (status != ARES_SUCCESS) {
|
|
668
|
+
status = ARES_EBADNAME;
|
|
669
|
+
goto fail;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
continue;
|
|
673
|
+
} else if ((c & 0xc0) != 0) {
|
|
674
|
+
/* 10 and 01 are reserved */
|
|
675
|
+
status = ARES_EBADNAME;
|
|
676
|
+
goto fail;
|
|
677
|
+
} else if (c == 0) {
|
|
678
|
+
/* termination via zero octet*/
|
|
679
|
+
break;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/* New label */
|
|
683
|
+
|
|
684
|
+
/* RFC 1035 3.1 limits a name to 255 octets. Enforce it during
|
|
685
|
+
* decompression so labels reached through a chain of pointers can't expand a
|
|
686
|
+
* single name without bound. Track the presentation length (label data plus
|
|
687
|
+
* the separator that precedes each label after the first), matching
|
|
688
|
+
* ares_split_dns_name() on the write side. */
|
|
689
|
+
if (name_len) {
|
|
690
|
+
name_len++;
|
|
691
|
+
}
|
|
692
|
+
name_len += c;
|
|
693
|
+
if (name_len > ARES_MAX_NAME_PRESENTATION_LEN) {
|
|
694
|
+
status = ARES_EBADNAME;
|
|
695
|
+
goto fail;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/* Labels are separated by periods */
|
|
699
|
+
if (ares_buf_len(namebuf) != 0 && name != NULL) {
|
|
700
|
+
status = ares_buf_append_byte(namebuf, '.');
|
|
701
|
+
if (status != ARES_SUCCESS) {
|
|
702
|
+
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
status = ares_fetch_dnsname_into_buf(buf, namebuf, c, is_hostname);
|
|
707
|
+
if (status != ARES_SUCCESS) {
|
|
708
|
+
goto fail;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/* Restore offset read after first redirect/pointer as this is where the DNS
|
|
713
|
+
* message continues */
|
|
714
|
+
if (save_offset) {
|
|
715
|
+
ares_buf_set_position(buf, save_offset);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
if (name != NULL) {
|
|
719
|
+
*name = ares_buf_finish_str(namebuf, NULL);
|
|
720
|
+
if (*name == NULL) {
|
|
721
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
722
|
+
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
return ARES_SUCCESS;
|
|
727
|
+
|
|
728
|
+
fail:
|
|
729
|
+
/* We want badname response if we couldn't parse */
|
|
730
|
+
if (status == ARES_EBADRESP) {
|
|
731
|
+
status = ARES_EBADNAME;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
ares_buf_destroy(namebuf);
|
|
735
|
+
return status;
|
|
736
|
+
}
|