Artifactspublic-v0

curl

master
ply4 git calls32 ms290 KiB3 cachedprotocol v2
377 lines12 KiBRaw
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/* Escape and unescape URL encoding in strings. The functions return a new
25 * allocated string or NULL if an error occurred. */
26#include "curl_setup.h"
28struct Curl_easy;
30#include "urldata.h"
31#include "escape.h"
32#include "curlx/strparse.h"
33#include "curl_printf.h"
35/* for ABI-compatibility with previous versions */
36char *curl_escape(const char *string, int length)
38 return curl_easy_escape(NULL, string, length);
41/* for ABI-compatibility with previous versions */
42char *curl_unescape(const char *string, int length)
44 return curl_easy_unescape(NULL, string, length, NULL);
47#define NOPE 0xff
48#define _OK_ 0x1f /* octet not needing encoding but not a hexadecimal
49 character */
51static const unsigned char hextable[256] = {
52 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, /* 00 */
53 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, /* 08 */
54 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, /* 10 */
55 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, /* 18 */
56 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, /* 20 */
57 NOPE, NOPE, NOPE, NOPE, NOPE, _OK_, _OK_, NOPE, /* 28 */
58 0, 1, 2, 3, 4, 5, 6, 7, /* 30 */
59 8, 9, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, /* 38 */
60 NOPE, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, _OK_, /* 40 */
61 _OK_, _OK_, _OK_, _OK_, _OK_, _OK_, _OK_, _OK_, /* 48 */
62 _OK_, _OK_, _OK_, _OK_, _OK_, _OK_, _OK_, _OK_, /* 50 */
63 _OK_, _OK_, _OK_, NOPE, NOPE, NOPE, NOPE, _OK_, /* 58 */
64 NOPE, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, _OK_, /* 60 */
65 _OK_, _OK_, _OK_, _OK_, _OK_, _OK_, _OK_, _OK_, /* 68 */
66 _OK_, _OK_, _OK_, _OK_, _OK_, _OK_, _OK_, _OK_, /* 70 */
67 _OK_, _OK_, _OK_, NOPE, NOPE, NOPE, _OK_, NOPE, /* 78 */
68 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, /* 80 - not ASCII */
69 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
70 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
71 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
72 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
73 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
74 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
75 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
76 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
77 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
78 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
79 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
80 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
81 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
82 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE,
83 NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE, NOPE
84};
86static const char hexpairs[][2] = {
87 {'0', '0'}, {'0', '1'}, {'0', '2'}, {'0', '3'},
88 {'0', '4'}, {'0', '5'}, {'0', '6'}, {'0', '7'},
89 {'0', '8'}, {'0', '9'}, {'0', 'A'}, {'0', 'B'},
90 {'0', 'C'}, {'0', 'D'}, {'0', 'E'}, {'0', 'F'},
91 {'1', '0'}, {'1', '1'}, {'1', '2'}, {'1', '3'},
92 {'1', '4'}, {'1', '5'}, {'1', '6'}, {'1', '7'},
93 {'1', '8'}, {'1', '9'}, {'1', 'A'}, {'1', 'B'},
94 {'1', 'C'}, {'1', 'D'}, {'1', 'E'}, {'1', 'F'},
95 {'2', '0'}, {'2', '1'}, {'2', '2'}, {'2', '3'},
96 {'2', '4'}, {'2', '5'}, {'2', '6'}, {'2', '7'},
97 {'2', '8'}, {'2', '9'}, {'2', 'A'}, {'2', 'B'},
98 {'2', 'C'}, {'2', 'D'}, {'2', 'E'}, {'2', 'F'},
99 {'3', '0'}, {'3', '1'}, {'3', '2'}, {'3', '3'},
100 {'3', '4'}, {'3', '5'}, {'3', '6'}, {'3', '7'},
101 {'3', '8'}, {'3', '9'}, {'3', 'A'}, {'3', 'B'},
102 {'3', 'C'}, {'3', 'D'}, {'3', 'E'}, {'3', 'F'},
103 {'4', '0'}, {'4', '1'}, {'4', '2'}, {'4', '3'},
104 {'4', '4'}, {'4', '5'}, {'4', '6'}, {'4', '7'},
105 {'4', '8'}, {'4', '9'}, {'4', 'A'}, {'4', 'B'},
106 {'4', 'C'}, {'4', 'D'}, {'4', 'E'}, {'4', 'F'},
107 {'5', '0'}, {'5', '1'}, {'5', '2'}, {'5', '3'},
108 {'5', '4'}, {'5', '5'}, {'5', '6'}, {'5', '7'},
109 {'5', '8'}, {'5', '9'}, {'5', 'A'}, {'5', 'B'},
110 {'5', 'C'}, {'5', 'D'}, {'5', 'E'}, {'5', 'F'},
111 {'6', '0'}, {'6', '1'}, {'6', '2'}, {'6', '3'},
112 {'6', '4'}, {'6', '5'}, {'6', '6'}, {'6', '7'},
113 {'6', '8'}, {'6', '9'}, {'6', 'A'}, {'6', 'B'},
114 {'6', 'C'}, {'6', 'D'}, {'6', 'E'}, {'6', 'F'},
115 {'7', '0'}, {'7', '1'}, {'7', '2'}, {'7', '3'},
116 {'7', '4'}, {'7', '5'}, {'7', '6'}, {'7', '7'},
117 {'7', '8'}, {'7', '9'}, {'7', 'A'}, {'7', 'B'},
118 {'7', 'C'}, {'7', 'D'}, {'7', 'E'}, {'7', 'F'},
119 {'8', '0'}, {'8', '1'}, {'8', '2'}, {'8', '3'},
120 {'8', '4'}, {'8', '5'}, {'8', '6'}, {'8', '7'},
121 {'8', '8'}, {'8', '9'}, {'8', 'A'}, {'8', 'B'},
122 {'8', 'C'}, {'8', 'D'}, {'8', 'E'}, {'8', 'F'},
123 {'9', '0'}, {'9', '1'}, {'9', '2'}, {'9', '3'},
124 {'9', '4'}, {'9', '5'}, {'9', '6'}, {'9', '7'},
125 {'9', '8'}, {'9', '9'}, {'9', 'A'}, {'9', 'B'},
126 {'9', 'C'}, {'9', 'D'}, {'9', 'E'}, {'9', 'F'},
127 {'A', '0'}, {'A', '1'}, {'A', '2'}, {'A', '3'},
128 {'A', '4'}, {'A', '5'}, {'A', '6'}, {'A', '7'},
129 {'A', '8'}, {'A', '9'}, {'A', 'A'}, {'A', 'B'},
130 {'A', 'C'}, {'A', 'D'}, {'A', 'E'}, {'A', 'F'},
131 {'B', '0'}, {'B', '1'}, {'B', '2'}, {'B', '3'},
132 {'B', '4'}, {'B', '5'}, {'B', '6'}, {'B', '7'},
133 {'B', '8'}, {'B', '9'}, {'B', 'A'}, {'B', 'B'},
134 {'B', 'C'}, {'B', 'D'}, {'B', 'E'}, {'B', 'F'},
135 {'C', '0'}, {'C', '1'}, {'C', '2'}, {'C', '3'},
136 {'C', '4'}, {'C', '5'}, {'C', '6'}, {'C', '7'},
137 {'C', '8'}, {'C', '9'}, {'C', 'A'}, {'C', 'B'},
138 {'C', 'C'}, {'C', 'D'}, {'C', 'E'}, {'C', 'F'},
139 {'D', '0'}, {'D', '1'}, {'D', '2'}, {'D', '3'},
140 {'D', '4'}, {'D', '5'}, {'D', '6'}, {'D', '7'},
141 {'D', '8'}, {'D', '9'}, {'D', 'A'}, {'D', 'B'},
142 {'D', 'C'}, {'D', 'D'}, {'D', 'E'}, {'D', 'F'},
143 {'E', '0'}, {'E', '1'}, {'E', '2'}, {'E', '3'},
144 {'E', '4'}, {'E', '5'}, {'E', '6'}, {'E', '7'},
145 {'E', '8'}, {'E', '9'}, {'E', 'A'}, {'E', 'B'},
146 {'E', 'C'}, {'E', 'D'}, {'E', 'E'}, {'E', 'F'},
147 {'F', '0'}, {'F', '1'}, {'F', '2'}, {'F', '3'},
148 {'F', '4'}, {'F', '5'}, {'F', '6'}, {'F', '7'},
149 {'F', '8'}, {'F', '9'}, {'F', 'A'}, {'F', 'B'},
150 {'F', 'C'}, {'F', 'D'}, {'F', 'E'}, {'F', 'F'}
151};
153/* Escapes for URL the given unescaped string of given length.
154 * 'data' is ignored since 7.82.0.
155 */
156char *curl_easy_escape(CURL *curl, const char *string, int length)
158 size_t len;
159 const char *f = string;
160 size_t nappend = 0;
161 char *target;
162 char *encoded;
163 (void)curl;
165 if(!string || (length < 0))
166 return NULL;
168 len = (length ? (size_t)length : strlen(string));
169 if(!len)
170 return curlx_strdup("");
172 if(len > SIZE_MAX / 16)
173 return NULL;
175 encoded = target = curlx_malloc((len * 3) + 1);
176 if(!target)
177 return NULL;
179 while(len--) {
180 uint8_t in = (uint8_t)*string++;
182 if(!(hextable[in] & 0x80))
183 /* append this */
184 nappend++;
185 else {
186 if(nappend) {
187 memcpy(target, f, nappend);
188 target += nappend;
189 nappend = 0;
190 }
191 f = string;
192 /* encode it */
193 target[0] = '%';
194 memcpy(target + 1, hexpairs[in], 2);
195 target += 3;
196 }
197 }
198 if(nappend) {
199 memcpy(target, f, nappend);
200 target += nappend;
201 }
202 *target = '\0'; /* null-terminate */
204 return encoded;
207/*
208 * Curl_urldecode() URL decodes the given string.
209 *
210 * Returns a pointer to a malloced string in *ostring with length given in
211 * *olen. If length == 0, the length is assumed to be strlen(string).
212 *
213 * ctrl options:
214 * - REJECT_NADA: accept everything
215 * - REJECT_CTRL: rejects control characters (byte codes lower than 32) in
216 * the data
217 * - REJECT_ZERO: rejects decoded zero bytes
218 *
219 * The values for the enum starts at 2, to make the assert detect legacy
220 * invokes that used TRUE/FALSE (0 and 1).
221 */
223CURLcode Curl_urldecode(const char *string, size_t length,
224 char **ostring, size_t *olen,
225 enum urlreject ctrl)
227 size_t alloc;
228 char *ns;
229 uint8_t reject_limit;
231 DEBUGASSERT(string);
232 DEBUGASSERT(ctrl >= REJECT_NADA); /* crash on TRUE/FALSE */
234 alloc = (length ? length : strlen(string));
235 ns = curlx_malloc(alloc + 1);
237 if(!ns)
238 return CURLE_OUT_OF_MEMORY;
240 /* store output string */
241 *ostring = ns;
243 reject_limit = (ctrl == REJECT_CTRL) ? 0x20 :
244 (ctrl == REJECT_ZERO) ? 1 : 0;
246 while(alloc) {
247 uint8_t in;
249 if(*string == '%') {
250 if(alloc > 2) {
251 uint8_t h1 = hextable[(uint8_t)string[1]];
252 uint8_t h2 = hextable[(uint8_t)string[2]];
253 if(!((h1 | h2) & 0xf0)) {
254 in = (uint8_t)((h1 << 4) | h2);
255 string += 3;
256 alloc -= 3;
257 if(in < reject_limit)
258 goto error;
259 *ns++ = (char)in;
260 continue;
261 }
262 }
263 in = '%';
264 string++;
265 alloc--;
266 *ns++ = (char)in;
267 continue;
268 }
269 else {
270 const char *p = memchr(string + 1, '%', alloc - 1);
271 size_t n = p ? (size_t)(p - string) : alloc;
273 if(reject_limit) {
274 if(reject_limit == 1) {
275 if(memchr(string, 0, n))
276 goto error;
277 }
278 else {
279 size_t i;
280 for(i = 0; i < n; i++) {
281 if((uint8_t)string[i] < 0x20)
282 goto error;
283 }
284 }
285 }
287 memcpy(ns, string, n);
288 ns += n;
289 string += n;
290 alloc -= n;
291 }
292 }
293 *ns = 0; /* terminate it */
295 if(olen)
296 /* store output size */
297 *olen = (size_t)(ns - *ostring);
299 return CURLE_OK;
300error:
301 curlx_safefree(*ostring);
302 return CURLE_URL_MALFORMAT;
305/*
306 * Unescapes the given URL escaped string of given length. Returns a
307 * pointer to a malloced string with length given in *olen.
308 * If length == 0, the length is assumed to be strlen(string).
309 * If olen == NULL, no output length is stored.
310 * 'data' is ignored since 7.82.0.
311 */
312char *curl_easy_unescape(CURL *curl, const char *string, int inlength,
313 int *outlength)
315 char *str = NULL;
316 (void)curl;
317 if(string && (inlength >= 0)) {
318 size_t inputlen = (size_t)inlength;
319 size_t outputlen;
320 CURLcode res = Curl_urldecode(string, inputlen, &str, &outputlen,
321 REJECT_NADA);
322 if(res)
323 return NULL;
325 if(outlength) {
326 if(outputlen <= (size_t)INT_MAX)
327 *outlength = curlx_uztosi(outputlen);
328 else
329 /* too large to return in an int, fail! */
330 curlx_safefree(str);
331 }
332 }
333 return str;
336/* For operating systems/environments that use different malloc/free
337 systems for the app and for this library, we provide a free that uses
338 the library's memory system */
339void curl_free(void *p)
341 curlx_free(p);
344/*
345 * Curl_hexencode()
346 *
347 * Converts binary input to lowercase hex-encoded ASCII output.
348 * null-terminated.
349 */
350void Curl_hexencode(const unsigned char *src, size_t len, /* input length */
351 unsigned char *out, size_t olen) /* output buffer size */
353 DEBUGASSERT(src && len && (olen >= 3));
354 if(src && len && (olen >= 3)) {
355 while(len-- && (olen >= 3)) {
356 out[0] = Curl_ldigits[*src >> 4];
357 out[1] = Curl_ldigits[*src & 0x0F];
358 ++src;
359 out += 2;
360 olen -= 2;
361 }
362 *out = 0;
363 }
364 else if(olen)
365 *out = 0;
368/* Curl_hexbyte
369 *
370 * Output a single unsigned char as a two-digit UPPERCASE hex number.
371 */
372void Curl_hexbyte(unsigned char *dest, /* must fit two bytes */
373 unsigned char val)
375 dest[0] = Curl_udigits[val >> 4];
376 dest[1] = Curl_udigits[val & 0x0F];
Diagnostics4 git calls · 32 ms
CallStatusSizeTime032 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
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 · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=26
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
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=86
Open pack map
fetch2003.5 KiB · hit26 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=3560
git.response.cache=HIT
git.response.duration_ms=26
git.fetch.wants=32f94cbb8e2fac92228a9c3add21e49c640e91a6
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=3560
git.pkt.payload.max=3539
git.sideband.band1.bytes=3538
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
a5e1704929696102
Request
00590b07…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format