master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "unitcheck.h"
25#include "vdns/doh.h"
27static CURLcode test_unit1655(const char *arg)
28{
29 UNITTEST_BEGIN_SIMPLE
31#ifndef CURL_DISABLE_DOH
32 /*
33 * Prove detection of write overflow using a short buffer and a name
34 * of maximal valid length.
35 *
36 * Prove detection of other invalid input.
37 */
38 do {
39 static const char max[] =
40 /* ..|....1.........2.........3.........4.........5.........6... */
41 /* 3456789012345678901234567890123456789012345678901234567890123 */
42 "this.is.a.maximum-length.hostname." /* 34: 34 */
43 "with-no-label-of-greater-length-than-the-sixty-three-characters."
44 /* 64: 98 */
45 "specified.in.the.RFCs." /* 22: 120 */
46 "and.with.a.QNAME.encoding.whose.length.is.exactly." /* 50: 170 */
47 "the.maximum.length.allowed." /* 27: 197 */
48 "that.is.two-hundred.and.fifty-six." /* 34: 231 */
49 "including.the.last.null." /* 24: 255 */
50 "";
51 static const char toolong[] =
52 /* ..|....1.........2.........3.........4.........5.........6... */
53 /* 3456789012345678901234567890123456789012345678901234567890123 */
54 "here.is.a.hostname.which.is.only.barely.too.long." /* 49: 49 */
55 "to.be.encoded.as.a.QNAME.of.the.maximum.allowed.length."
56 /* 55: 104 */
57 "which.is.256.including.a.final.zero-length.label." /* 49: 153 */
58 "representing.the.root.node.so.that.a.name.with." /* 47: 200 */
59 "a.trailing.dot.may.have.up.to." /* 30: 230 */
60 "255.characters.never.more." /* 26: 256 */
61 "";
62 static const char emptylabel[] =
63 "this.is.an.otherwise-valid.hostname."
64 ".with.an.empty.label.";
65 static const char outsizelabel[] =
66 "this.is.an.otherwise-valid.hostname."
67 "with-a-label-of-greater-length-than-the-sixty-three-characters-"
68 "specified.in.the.RFCs.";
69 size_t i;
71 struct test {
72 const char *name;
73 const DOHcode expected_result;
74 };
76 /* plays the role of struct dnsprobe in urldata.h */
77 struct demo {
78 unsigned char dohbuffer[255 + 16]; /* deliberately short buffer */
79 unsigned char canary1;
80 unsigned char canary2;
81 unsigned char canary3;
82 };
84 const struct test playlist[4] = {
85 { toolong, DOH_DNS_NAME_TOO_LONG }, /* expect early failure */
86 { emptylabel, DOH_DNS_BAD_LABEL }, /* also */
87 { outsizelabel, DOH_DNS_BAD_LABEL }, /* also */
88 { max, DOH_OK } /* expect buffer overwrite */
89 };
91 for(i = 0; i < CURL_ARRAYSIZE(playlist); i++) {
92 const char *name = playlist[i].name;
93 size_t olen = 100000;
94 struct demo victim;
95 DOHcode d;
97 victim.canary1 = 87; /* magic numbers, arbitrarily picked */
98 victim.canary2 = 35;
99 victim.canary3 = 41;
100 d = doh_req_encode(name, CURL_DNS_TYPE_A, victim.dohbuffer,
101 sizeof(struct demo), /* allow room for overflow */
102 &olen);
104 fail_unless(d == playlist[i].expected_result,
105 "result returned was not as expected");
106 if(d == playlist[i].expected_result) {
107 if(name == max) {
108 fail_if(victim.canary1 == 87,
109 "demo one-byte buffer overwrite did not happen");
110 }
111 else {
112 fail_unless(victim.canary1 == 87,
113 "one-byte buffer overwrite has happened");
114 }
115 fail_unless(victim.canary2 == 35,
116 "two-byte buffer overwrite has happened");
117 fail_unless(victim.canary3 == 41,
118 "three-byte buffer overwrite has happened");
119 }
120 else if(d == DOH_OK) {
121 fail_unless(olen <= sizeof(victim.dohbuffer),
122 "wrote outside bounds");
123 fail_unless(olen > strlen(name), "unrealistic low size");
124 }
125 }
126 } while(0);
128 /* run normal cases and try to trigger buffer length related errors */
129 do {
130 DNStype dnstype = CURL_DNS_TYPE_A;
131 unsigned char buffer[128];
132 const size_t buflen = sizeof(buffer);
133 const size_t magic1 = 9765;
134 size_t olen1 = magic1;
135 static const char sunshine1[] = "a.com";
136 static const char dotshine1[] = "a.com.";
137 static const char sunshine2[] = "aa.com";
138 size_t olen2;
139 DOHcode ret2;
140 size_t olen;
142 DOHcode ret = doh_req_encode(sunshine1, dnstype, buffer, buflen, &olen1);
143 fail_unless(ret == DOH_OK, "sunshine case 1 should pass fine");
144 fail_if(olen1 == magic1, "olen has not been assigned properly");
145 fail_unless(olen1 > strlen(sunshine1), "bad out length");
147 /* with a trailing dot, the response should have the same length */
148 olen2 = magic1;
149 ret2 = doh_req_encode(dotshine1, dnstype, buffer, buflen, &olen2);
150 fail_unless(ret2 == DOH_OK, "dotshine case should pass fine");
151 fail_if(olen2 == magic1, "olen has not been assigned properly");
152 fail_unless(olen1 == olen2, "olen should not grow for a trailing dot");
154 /* add one letter, the response should be one longer */
155 olen2 = magic1;
156 ret2 = doh_req_encode(sunshine2, dnstype, buffer, buflen, &olen2);
157 fail_unless(ret2 == DOH_OK, "sunshine case 2 should pass fine");
158 fail_if(olen2 == magic1, "olen has not been assigned properly");
159 fail_unless(olen1 + 1 == olen2, "olen should grow with the hostname");
161 /* pass a short buffer, should fail */
162 ret = doh_req_encode(sunshine1, dnstype, buffer, olen1 - 1, &olen);
163 fail_if(ret == DOH_OK, "short buffer should have been noticed");
165 /* pass a minimum buffer, should succeed */
166 ret = doh_req_encode(sunshine1, dnstype, buffer, olen1, &olen);
167 fail_unless(ret == DOH_OK, "minimal length buffer should be long enough");
168 fail_unless(olen == olen1, "bad buffer length");
169 } while(0);
171#endif /* CURL_DISABLE_DOH */
173 UNITTEST_END_SIMPLE
174}
Diagnostics4 git calls · 25 ms
CallStatusSizeTime025 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2002.5 KiB · hit20 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=20 git.response.bytes=2518 git.response.cache=HIT git.response.duration_ms=20 git.fetch.wants=12ea149c2b1d363952dd99fd42ed6a3cb2bda547 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2518 git.pkt.payload.max=2497 git.sideband.band1.bytes=2496 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e2e68acec3ecfa
- Request
- 2eefd92c…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format