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 "tool_setup.h"
26#include "tool_cfgable.h"
27#include "tool_doswin.h"
28#include "tool_urlglob.h"
29#include "tool_vms.h"
31static CURLcode globerror(struct URLGlob *glob, const char *err,
32 size_t pos, CURLcode error)
33{
34 glob->error = err;
35 glob->pos = pos;
36 return error;
37}
39static CURLcode glob_fixed(struct URLGlob *glob, char *fixed, size_t len)
40{
41 struct URLPattern *pat = &glob->pattern[glob->pnum];
42 pat->type = GLOB_SET;
43 pat->globindex = -1;
44 pat->c.set.size = 0;
45 pat->c.set.idx = 0;
46 pat->c.set.elem = curlx_malloc(sizeof(char *));
48 if(!pat->c.set.elem)
49 return globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY);
51 pat->c.set.elem[0] = curlx_memdup0(fixed, len);
52 if(!pat->c.set.elem[0]) {
53 curlx_safefree(pat->c.set.elem);
54 return globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY);
55 }
57 pat->c.set.palloc = 1;
58 pat->c.set.size = 1;
59 pat->name = NULL; /* unnamed */
60 return CURLE_OK;
61}
63/* multiply
64 *
65 * Multiplies and checks for overflow.
66 */
67static int multiply(curl_off_t *amount, curl_off_t with)
68{
69 curl_off_t sum;
70 DEBUGASSERT(*amount >= 0);
71 DEBUGASSERT(with >= 0);
72 if((with <= 0) || (*amount <= 0)) {
73 sum = 0;
74 }
75 else {
76#if (defined(__GNUC__) && \
77 ((__GNUC__ > 5) || ((__GNUC__ == 5) && (__GNUC_MINOR__ >= 1)))) || \
78 (defined(__clang__) && __clang_major__ >= 8)
79 if(__builtin_mul_overflow(*amount, with, &sum))
80 return 1;
81#else
82 sum = *amount * with;
83 if(sum / with != *amount)
84 return 1; /* did not fit, bail out */
85#endif
86 }
87 *amount = sum;
88 return 0;
89}
91static CURLcode glob_set(struct URLGlob *glob, const char **patternp,
92 size_t *posp, curl_off_t *amount,
93 int globindex, const struct Curl_str *name)
94{
95 /* processes a set expression with the point behind the opening '{'
96 ','-separated elements are collected until the next closing '}'
97 */
98 struct URLPattern *pat;
99 bool done = FALSE;
100 const char *pattern = *patternp;
101 const char *opattern = pattern;
102 CURLcode result = CURLE_OK;
103 size_t size = 0;
104 char **elem = NULL;
105 size_t palloc = 0; /* start with this */
106 DEBUGASSERT(name);
108 while(!done) {
109 switch(*pattern) {
110 case '\0': /* URL ended while set was still open */
111 result = globerror(glob, "unmatched brace", *posp, CURLE_URL_MALFORMAT);
112 goto error;
114 case '{':
115 case '[': /* no nested expressions at this time */
116 result = globerror(glob, "nested brace", *posp, CURLE_URL_MALFORMAT);
117 goto error;
119 case '}': /* set element completed */
120 if(opattern == pattern) {
121 result = globerror(glob, "empty string within braces", *posp,
122 CURLE_URL_MALFORMAT);
123 goto error;
124 }
126 /* add 1 to size since it is to be incremented below */
127 if(multiply(amount, size + 1)) {
128 result = globerror(glob, "range overflow", 0, CURLE_URL_MALFORMAT);
129 goto error;
130 }
131 done = TRUE;
132 FALLTHROUGH();
133 case ',':
134 if(size >= 100000) {
135 result = globerror(glob, "range overflow", 0, CURLE_URL_MALFORMAT);
136 goto error;
137 }
139 if(!palloc) {
140 palloc = 5; /* a reasonable default */
141 elem = curlx_malloc(palloc * sizeof(char *));
142 }
143 else if(size >= palloc) {
144 char **arr = curlx_realloc(elem, palloc * 2 * sizeof(char *));
145 if(!arr) {
146 result = globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY);
147 goto error;
148 }
149 elem = arr;
150 palloc *= 2;
151 }
153 if(!elem) {
154 result = globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY);
155 goto error;
156 }
158 elem[size] = curlx_strdup(curlx_dyn_ptr(&glob->buf) ?
159 curlx_dyn_ptr(&glob->buf) : "");
160 if(!elem[size]) {
161 result = globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY);
162 goto error;
163 }
164 ++size;
165 curlx_dyn_reset(&glob->buf);
167 ++pattern;
168 if(!done)
169 ++(*posp);
170 break;
172 case ']': /* illegal closing bracket */
173 result = globerror(glob, "unexpected close bracket", *posp,
174 CURLE_URL_MALFORMAT);
175 goto error;
177 case '\\': /* escaped character, skip '\' */
178 if(pattern[1]) {
179 ++pattern;
180 ++(*posp);
181 }
182 FALLTHROUGH();
183 default:
184 /* copy character to set element */
185 if(curlx_dyn_addn(&glob->buf, pattern++, 1)) {
186 result = CURLE_OUT_OF_MEMORY;
187 goto error;
188 }
189 ++(*posp);
190 }
191 }
193 *patternp = pattern; /* return with the new position */
195 pat = &glob->pattern[glob->pnum];
196 pat->type = GLOB_SET;
197 pat->globindex = globindex;
198 pat->c.set.elem = elem;
199 pat->c.set.size = size;
200 pat->c.set.idx = 0;
201 pat->c.set.palloc = palloc;
202 if(curlx_strlen(name)) {
203 pat->name = curlx_memdup0(curlx_str(name), curlx_strlen(name));
204 if(!pat->name) {
205 result = CURLE_OUT_OF_MEMORY;
206 goto error;
207 }
208 }
209 else
210 pat->name = NULL; /* no name */
212 return CURLE_OK;
213error:
214 {
215 size_t i;
216 for(i = 0; i < size; i++)
217 curlx_safefree(elem[i]);
218 }
219 curlx_free(elem);
220 return result;
221}
223static CURLcode glob_range(struct URLGlob *glob, const char **patternp,
224 size_t *posp, curl_off_t *amount,
225 int globindex, const struct Curl_str *name)
226{
227 /* processes a range expression with the point behind the opening '['
228 - char range: e.g. "a-z]", "B-Q]"
229 - num range: e.g. "0-9]", "17-2000]"
230 - num range with leading zeros: e.g. "001-999]"
231 expression is checked for well-formedness and collected until the next ']'
232 */
233 struct URLPattern *pat;
234 const char *pattern = *patternp;
235 const char *c;
237 DEBUGASSERT(name);
238 pat = &glob->pattern[glob->pnum];
239 pat->globindex = globindex;
240 pat->name = NULL; /* no name (so far) */
242 if(ISALPHA(*pattern)) {
243 /* character range detected */
244 bool pmatch = FALSE;
245 char min_c = 0;
246 char max_c = 0;
247 char end_c = 0;
248 unsigned char step = 1;
250 pat->type = GLOB_ASCII;
252 if((pattern[1] == '-') && pattern[2] && pattern[3]) {
253 min_c = pattern[0];
254 max_c = pattern[2];
255 end_c = pattern[3];
256 pmatch = TRUE;
258 if(end_c == ':') {
259 curl_off_t num;
260 const char *p = &pattern[4];
261 if(curlx_str_number(&p, &num, 256) || curlx_str_single(&p, ']'))
262 step = 0;
263 else
264 step = (unsigned char)num;
265 pattern = p;
266 }
267 else if(end_c != ']')
268 /* then this is wrong */
269 pmatch = FALSE;
270 else
271 /* end_c == ']' */
272 pattern += 4;
273 }
275 *posp += (pattern - *patternp);
277 if(!pmatch || !step ||
278 (min_c == max_c && step != 1) ||
279 (min_c != max_c && (min_c > max_c || step > (unsigned)(max_c - min_c) ||
280 (max_c - min_c) > ('z' - 'a'))))
281 /* the pattern is not well-formed */
282 return globerror(glob, "bad range", *posp, CURLE_URL_MALFORMAT);
284 /* if there was a ":[num]" thing, use that as step or else use 1 */
285 pat->c.ascii.step = step;
286 pat->c.ascii.letter = pat->c.ascii.min = (unsigned char)min_c;
287 pat->c.ascii.max = (unsigned char)max_c;
289 if(multiply(amount, (((pat->c.ascii.max - pat->c.ascii.min) /
290 pat->c.ascii.step) + 1)))
291 return globerror(glob, "range overflow", *posp, CURLE_URL_MALFORMAT);
292 }
293 else if(ISDIGIT(*pattern)) {
294 /* numeric range detected */
295 curl_off_t min_n = 0;
296 curl_off_t max_n = 0;
297 curl_off_t step_n = 0;
298 curl_off_t num;
300 pat->type = GLOB_NUM;
301 pat->c.num.npad = 0;
303 if(*pattern == '0') {
304 /* leading zero specified, count them! */
305 c = pattern;
306 while(ISDIGIT(*c)) {
307 c++;
308 ++pat->c.num.npad; /* padding length is set for all instances of this
309 pattern */
310 }
311 }
313 if(!curlx_str_number(&pattern, &num, CURL_OFF_T_MAX)) {
314 min_n = num;
315 if(!curlx_str_single(&pattern, '-')) {
316 curlx_str_passblanks(&pattern);
317 if(!curlx_str_number(&pattern, &num, CURL_OFF_T_MAX)) {
318 max_n = num;
319 if(!curlx_str_single(&pattern, ']'))
320 step_n = 1;
321 else if(!curlx_str_single(&pattern, ':') &&
322 !curlx_str_number(&pattern, &num, CURL_OFF_T_MAX) &&
323 !curlx_str_single(&pattern, ']')) {
324 step_n = num;
325 }
326 /* else bad syntax */
327 }
328 }
329 }
331 *posp += (pattern - *patternp);
333 if(!step_n ||
334 (min_n == max_n && step_n != 1) ||
335 (min_n != max_n && (min_n > max_n || step_n > (max_n - min_n))))
336 /* the pattern is not well-formed */
337 return globerror(glob, "bad range", *posp, CURLE_URL_MALFORMAT);
339 if((CURL_OFF_T_MAX - step_n) < max_n)
340 return globerror(glob, "range end/step overflow", *posp,
341 CURLE_URL_MALFORMAT);
343 pat->c.num.idx = pat->c.num.min = min_n;
344 pat->c.num.max = max_n;
345 pat->c.num.step = step_n;
347 if(multiply(amount, (((pat->c.num.max - pat->c.num.min) /
348 pat->c.num.step) + 1)))
349 return globerror(glob, "range overflow", *posp, CURLE_URL_MALFORMAT);
350 }
351 else
352 return globerror(glob, "bad range specification", *posp,
353 CURLE_URL_MALFORMAT);
355 if(curlx_strlen(name)) {
356 pat->name = curlx_memdup0(curlx_str(name), curlx_strlen(name));
357 if(!pat->name)
358 return CURLE_OUT_OF_MEMORY;
359 }
360 *patternp = pattern;
361 return CURLE_OK;
362}
364#define MAX_IP6LEN 128
366static CURLcode peek_ipv6(const char *str, size_t *skip, bool *ipv6p)
367{
368 /*
369 * Scan for a potential IPv6 literal.
370 * - Valid globs contain a hyphen and <= 1 colon.
371 * - IPv6 literals contain no hyphens and >= 2 colons.
372 */
373 char hostname[MAX_IP6LEN];
374 CURLU *u;
375 const char *endbr = strchr(str, ']');
376 size_t hlen;
377 CURLUcode rc;
378 CURLcode result = CURLE_OK;
379 *ipv6p = FALSE; /* default to nope */
380 *skip = 0;
381 if(!endbr)
382 return CURLE_OK;
384 hlen = endbr - str + 1;
385 if(hlen >= MAX_IP6LEN)
386 return CURLE_OK;
388 u = curl_url();
389 if(!u)
390 return CURLE_OUT_OF_MEMORY;
392 memcpy(hostname, str, hlen);
393 hostname[hlen] = 0;
395 /* ask to "guess scheme" as then it works without an https:// prefix */
396 rc = curl_url_set(u, CURLUPART_URL, hostname, CURLU_GUESS_SCHEME);
397 curl_url_cleanup(u);
398 if(rc == CURLUE_OUT_OF_MEMORY)
399 return CURLE_OUT_OF_MEMORY;
400 if(!rc) {
401 *skip = hlen;
402 *ipv6p = TRUE;
403 }
404 return result;
405}
407static CURLcode add_glob(struct URLGlob *glob, size_t pos)
408{
409 DEBUGASSERT(glob->pattern[glob->pnum].type);
411 if(++glob->pnum >= glob->palloc) {
412 struct URLPattern *np = NULL;
413 glob->palloc *= 2;
414 if(glob->pnum < 255) { /* avoid ridiculous amounts */
415 np = curlx_realloc(glob->pattern,
416 glob->palloc * sizeof(struct URLPattern));
417 if(!np)
418 return globerror(glob, NULL, pos, CURLE_OUT_OF_MEMORY);
419 }
420 else
421 return globerror(glob, "too many {} sets", pos, CURLE_URL_MALFORMAT);
422 glob->pattern = np;
423 }
424 return CURLE_OK;
425}
427/* returns the named glob pattern (case sensitively) if it exists, otherwise
428 NULL */
429static struct URLPattern *glob_find_name(struct URLGlob *glob,
430 struct Curl_str *name)
431{
432 size_t i;
433 /* find the correct glob entry */
434 for(i = 0; i < glob->pnum; i++) {
435 if(glob->pattern[i].name &&
436 curlx_str_cmp(name, glob->pattern[i].name))
437 return &glob->pattern[i];
438 }
439 return NULL; /* no match */
440}
442#define MAX_GLOBNAME_LEN 64
444static CURLcode glob_parse(struct URLGlob *glob, const char *pattern,
445 size_t pos, curl_off_t *amount)
446{
447 /* processes a literal string component of a URL
448 special characters '{' and '[' branch to set/range processing functions
449 */
450 const char *ipattern = pattern; /* start position */
451 CURLcode result = CURLE_OK;
452 int globindex = 0; /* count "actual" globs */
454 *amount = 1;
456 while(*pattern && !result) {
457 while(*pattern && *pattern != '{') {
458 if(*pattern == '[') {
459 /* skip over IPv6 literals and [] */
460 size_t skip = 0;
461 bool ipv6;
462 result = peek_ipv6(pattern, &skip, &ipv6);
463 if(result)
464 return result;
465 if(!ipv6 && (pattern[1] == ']'))
466 skip = 2;
467 if(skip) {
468 if(curlx_dyn_addn(&glob->buf, pattern, skip))
469 return CURLE_OUT_OF_MEMORY;
470 pattern += skip;
471 continue;
472 }
473 break;
474 }
475 if(*pattern == '}' || *pattern == ']')
476 return globerror(glob, "unmatched close brace/bracket", pos,
477 CURLE_URL_MALFORMAT);
479 /* only allow \ to escape known "special letters" */
480 if(*pattern == '\\' &&
481 (pattern[1] == '{' || pattern[1] == '[' ||
482 pattern[1] == '}' || pattern[1] == ']')) {
484 /* escape character, skip '\' */
485 ++pattern;
486 ++pos;
487 }
488 /* copy character to literal */
489 if(curlx_dyn_addn(&glob->buf, pattern++, 1))
490 return CURLE_OUT_OF_MEMORY;
491 ++pos;
492 }
493 if(curlx_dyn_len(&glob->buf)) {
494 /* we got a literal string, add it as a single-item list */
495 result = glob_fixed(glob, curlx_dyn_ptr(&glob->buf),
496 curlx_dyn_len(&glob->buf));
497 if(!result)
498 result = add_glob(glob, pos);
499 curlx_dyn_reset(&glob->buf);
500 }
501 else {
502 struct Curl_str name;
503 if(!*pattern) /* done */
504 break;
505 else if((*pattern == '{') || (*pattern == '[')) {
506 bool set = (*pattern == '{');
507 const char *start;
508 pattern++;
509 pos++;
510 start = pattern;
511 /* fetch the name, if provided */
512 if(curlx_str_single(&pattern, '<') ||
513 curlx_str_until(&pattern, &name, MAX_GLOBNAME_LEN, '>') ||
514 curlx_str_single(&pattern, '>')) {
515 /* Not a proper name. This is not reporting errors on syntax errors
516 on purpose: it means that if there is an existing use case that
517 uses what looks like a broken named-glob syntax (now introduced)
518 we let that function like before. */
519 curlx_str_init(&name);
520 pattern = start; /* reset any partial patch */
521 }
522 else {
523 /* check that the name is not already used */
524 struct URLPattern *p = glob_find_name(glob, &name);
525 if(p)
526 return globerror(glob, "Duplicate glob name", pattern - ipattern,
527 CURLE_URL_MALFORMAT);
528 pos += (pattern - start);
529 }
530 if(set)
531 result = glob_set(glob, &pattern, &pos, amount, globindex++, &name);
532 else
533 result = glob_range(glob, &pattern, &pos, amount, globindex++,
534 &name);
536 if(!result)
537 result = add_glob(glob, pos);
538 }
539 }
540 }
541 return result;
542}
544bool glob_inuse(struct URLGlob *glob)
545{
546 /* Both parsed patterns and a literal URL make the glob active. */
547 return (glob->palloc || glob->literal) ? TRUE : FALSE;
548}
550bool glob_is_literal(const struct URLGlob *glob)
551{
552 return glob->literal;
553}
555/* a glob error has been confirmed, this outputs details about it to the set
556 error stream */
557void glob_show_error(struct URLGlob *glob, const char *url, FILE *error,
558 CURLcode result)
559{
560 char text[512];
561 const char *t;
562 if(glob->pos) {
563 curl_msnprintf(text, sizeof(text), "%s in position %zu:\n%s\n%*s^",
564 glob->error,
565 glob->pos, url, (int)glob->pos - 1, " ");
566 t = text;
567 }
568 else
569 t = glob->error;
571 /* send error description to the error-stream */
572 curl_mfprintf(error, "curl: (%d) %s\n", (int)result, t);
573}
575CURLcode glob_url(struct URLGlob *glob, const char *url, curl_off_t *urlnum,
576 FILE *error)
577{
578 /*
579 * We can deal with any-size, make a buffer with the same length as the
580 * specified URL!
581 */
582 curl_off_t amount = 0;
583 CURLcode result;
585 memset(glob, 0, sizeof(struct URLGlob));
586 curlx_dyn_init(&glob->buf, MAX_CONFIG_LINE_LENGTH);
587 if(!strpbrk(url, "{}[]")) {
588 /* no glob syntax: use the URL as-is instead of parsing a copy of it */
589 glob->literal = TRUE;
590 *urlnum = 1;
591 return CURLE_OK;
592 }
593 glob->pattern = curlx_malloc(2 * sizeof(struct URLPattern));
594 if(!glob->pattern)
595 return CURLE_OUT_OF_MEMORY;
596 glob->palloc = 2;
598 result = glob_parse(glob, url, 1, &amount);
599 if(result) {
600 if(error && glob->error)
601 glob_show_error(glob, url, error, result);
602 *urlnum = 1;
603 return result;
604 }
605 *urlnum = amount;
606 return CURLE_OK;
607}
609void glob_cleanup(struct URLGlob *glob)
610{
611 size_t i;
613 glob->literal = FALSE;
614 glob->beenhere = 0;
615 if(glob->pattern) {
616 for(i = 0; i < glob->pnum; i++) {
617 DEBUGASSERT(glob->pattern[i].type);
618 if((glob->pattern[i].type == GLOB_SET) &&
619 glob->pattern[i].c.set.elem) {
620 curl_off_t elem;
621 for(elem = 0; elem < glob->pattern[i].c.set.size; elem++)
622 curlx_safefree(glob->pattern[i].c.set.elem[elem]);
623 curlx_safefree(glob->pattern[i].c.set.elem);
624 }
625 curlx_safefree(glob->pattern[i].name);
626 }
627 curlx_safefree(glob->pattern);
628 glob->palloc = 0;
629 curlx_dyn_free(&glob->buf);
630 }
631}
633CURLcode glob_next_url(char **globbed, struct URLGlob *glob)
634{
635 struct URLPattern *pat;
636 size_t i;
638 *globbed = NULL;
639 DEBUGASSERT(!glob->literal);
640 curlx_dyn_reset(&glob->buf);
642 if(!glob->beenhere)
643 glob->beenhere = 1;
644 else {
645 bool carry = TRUE;
647 /* implement a counter over the index ranges of all patterns, starting
648 with the rightmost pattern */
649 for(i = 0; carry && (i < glob->pnum); i++) {
650 carry = FALSE;
651 pat = &glob->pattern[glob->pnum - 1 - i];
652 switch(pat->type) {
653 case GLOB_SET:
654 if(pat->c.set.elem && (++pat->c.set.idx == pat->c.set.size)) {
655 pat->c.set.idx = 0;
656 carry = TRUE;
657 }
658 break;
659 case GLOB_ASCII:
660 pat->c.ascii.letter += pat->c.ascii.step;
661 if(pat->c.ascii.letter > pat->c.ascii.max) {
662 pat->c.ascii.letter = pat->c.ascii.min;
663 carry = TRUE;
664 }
665 break;
666 case GLOB_NUM:
667 pat->c.num.idx += pat->c.num.step;
668 if(pat->c.num.idx > pat->c.num.max) {
669 pat->c.num.idx = pat->c.num.min;
670 carry = TRUE;
671 }
672 break;
673 default:
674 DEBUGASSERT(0);
675 return CURLE_FAILED_INIT;
676 }
677 }
678 if(carry) { /* first pattern ptr has run into overflow, done! */
679 return CURLE_OK;
680 }
681 }
683 for(i = 0; i < glob->pnum; ++i) {
684 pat = &glob->pattern[i];
685 switch(pat->type) {
686 case GLOB_SET:
687 if(pat->c.set.elem &&
688 curlx_dyn_add(&glob->buf, pat->c.set.elem[pat->c.set.idx]))
689 return CURLE_OUT_OF_MEMORY;
690 break;
691 case GLOB_ASCII: {
692 char letter = (char)pat->c.ascii.letter;
693 if(curlx_dyn_addn(&glob->buf, &letter, 1))
694 return CURLE_OUT_OF_MEMORY;
695 break;
696 }
697 case GLOB_NUM:
698 if(curlx_dyn_addf(&glob->buf, "%0*" CURL_FORMAT_CURL_OFF_T,
699 pat->c.num.npad, pat->c.num.idx))
700 return CURLE_OUT_OF_MEMORY;
701 break;
702 default:
703 DEBUGASSERT(0);
704 return CURLE_FAILED_INIT;
705 }
706 }
708 *globbed =
709 curlx_strdup(curlx_dyn_ptr(&glob->buf) ? curlx_dyn_ptr(&glob->buf) : "");
710 if(!*globbed)
711 return CURLE_OUT_OF_MEMORY;
713 return CURLE_OK;
714}
716#define MAX_OUTPUT_GLOB_LENGTH (1024 * 1024)
718CURLcode glob_match_url(char **output, const char *filename,
719 struct URLGlob *glob, struct URLGlob *glob2,
720 SANITIZEcode *sc)
721{
722 struct dynbuf dyn;
723 const char *ifilename = filename;
724 *output = NULL;
725 *sc = SANITIZE_ERR_OK;
727 curlx_dyn_init(&dyn, MAX_OUTPUT_GLOB_LENGTH);
729 while(*filename) {
730 CURLcode result = CURLE_OK;
731 struct URLPattern *pat = NULL;
732 if(glob_inuse(glob) && *filename == '#' && ISDIGIT(filename[1])) {
733 /* a numbered glob reference */
734 const char *ptr = filename++;
735 curl_off_t num;
736 if(!curlx_str_number(&filename, &num, glob->pnum) && num) {
737 size_t i;
738 num--; /* make it zero based */
739 /* find the correct glob entry */
740 for(i = 0; i < glob->pnum; i++) {
741 if(glob->pattern[i].globindex == (int)num) {
742 pat = &glob->pattern[i];
743 break;
744 }
745 }
746 }
747 if(!pat)
748 filename = ptr;
749 }
750 else if(*filename == '#' && (filename[1] == '<')) {
751 /* a named glob reference */
752 struct Curl_str name;
753 const char *ptr = filename;
754 filename += 2; /* pass both leading bytes */
755 if(!curlx_str_until(&filename, &name, MAX_GLOBNAME_LEN, '>') &&
756 !curlx_str_single(&filename, '>')) {
757 /* find the correct glob entry */
758 if(glob_inuse(glob))
759 pat = glob_find_name(glob, &name);
760 if(!pat && glob2 && glob_inuse(glob2))
761 /* scan the second glob list if there is one */
762 pat = glob_find_name(glob2, &name);
763 if(!pat) {
764 /* when the name is given correctly, it needs to be an existing glob
765 name, which makes this an error */
766 curlx_dyn_free(&dyn);
767 return globerror(glob, "no glob exists with this name",
768 filename - ifilename, CURLE_BAD_FUNCTION_ARGUMENT);
769 }
770 }
771 if(!pat)
772 filename = ptr;
773 }
774 if(pat) {
775 switch(pat->type) {
776 case GLOB_SET:
777 if(pat->c.set.elem)
778 result = curlx_dyn_add(&dyn, pat->c.set.elem[pat->c.set.idx]);
779 break;
780 case GLOB_ASCII: {
781 char letter = (char)pat->c.ascii.letter;
782 result = curlx_dyn_addn(&dyn, &letter, 1);
783 break;
784 }
785 case GLOB_NUM:
786 result = curlx_dyn_addf(&dyn, "%0*" CURL_FORMAT_CURL_OFF_T,
787 pat->c.num.npad, pat->c.num.idx);
788 break;
789 default:
790 DEBUGASSERT(0);
791 curlx_dyn_free(&dyn);
792 return CURLE_FAILED_INIT;
793 }
794 }
795 else
796 result = curlx_dyn_addn(&dyn, filename++, 1);
797 if(result)
798 return result;
799 }
801 if(curlx_dyn_addn(&dyn, "", 0))
802 return CURLE_OUT_OF_MEMORY;
804#if defined(_WIN32) || defined(MSDOS)
805 {
806 char *sanitized;
807 *sc = sanitize_file_name(&sanitized, curlx_dyn_ptr(&dyn),
808 SANITIZE_ALLOW_PATH | SANITIZE_ALLOW_RESERVED);
809 curlx_dyn_free(&dyn);
810 if(*sc)
811 return CURLE_BAD_FUNCTION_ARGUMENT;
812 *output = sanitized;
813 return CURLE_OK;
814 }
815#else
816 *output = curlx_dyn_ptr(&dyn);
817 return CURLE_OK;
818#endif /* _WIN32 || MSDOS */
819}
Diagnostics4 git calls · 36 ms
CallStatusSizeTime036 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=30 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=86Open pack map
fetch2007.2 KiB · hit30 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=7385 git.response.cache=HIT git.response.duration_ms=30 git.fetch.wants=ddc65b7b8168f1c14b94fe892dcba8629c7d774e 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=7385 git.pkt.payload.max=7364 git.sideband.band1.bytes=7363 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
- a5e1823fba603014
- Request
- c4d3d5ef…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format