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 "urldata.h"
26#include "curl_trc.h"
28/*
29 * This test hardcodes the knowledge of the buffer size which is internal to
30 * Curl_infof(). If that buffer is changed in size, this tests needs to be
31 * updated to still be valid.
32 */
34static char input[4096];
35static char output[4096];
37/*
38 * This debugf callback dumps the string into the static buffer
39 * for the unit test to inspect. Since we know that we are only dealing with
40 * text we can afford the luxury of skipping the type check here.
41 */
42static int debugf_cb(CURL *handle, curl_infotype type, char *buf, size_t size,
43 void *userptr)
44{
45 (void)handle;
46 (void)type;
47 (void)userptr;
49 memset(output, '\0', sizeof(output));
50 memcpy(output, buf, size);
51 return 0;
52}
54static CURLcode t1652_setup(struct Curl_easy **easy)
55{
56 CURLcode result = CURLE_OK;
58 global_init(CURL_GLOBAL_ALL);
59 *easy = curl_easy_init();
60 if(!*easy) {
61 curl_global_cleanup();
62 return CURLE_OUT_OF_MEMORY;
63 }
64 curl_easy_setopt(*easy, CURLOPT_DEBUGFUNCTION, debugf_cb);
65 curl_easy_setopt(*easy, CURLOPT_VERBOSE, 1L);
66 return result;
67}
69static void t1652_stop(struct Curl_easy *easy)
70{
71 curl_easy_cleanup(easy);
72 curl_global_cleanup();
73}
75static int verify(const char *info, const char *two)
76{
77 /* the 'info' one has a newline appended */
78 const char *nl = strchr(info, '\n');
79 if(!nl)
80 return 1; /* nope */
81 return strncmp(info, two, nl - info);
82}
84static CURLcode test_unit1652(const char *arg)
85{
86 struct Curl_easy *easy;
88 UNITTEST_BEGIN(t1652_setup(&easy))
90#if defined(CURL_HAVE_DIAG) && !defined(__clang__)
91#pragma GCC diagnostic push
92#pragma GCC diagnostic ignored "-Wformat" /* for GCC v5 to v8 */
93#pragma GCC diagnostic ignored "-Wformat-zero-length"
94#if __GNUC__ >= 7
95#pragma GCC diagnostic ignored "-Wformat-overflow"
96#endif
97#endif
99 /* Injecting a simple short string via a format */
100 curl_msnprintf(input, sizeof(input), "Simple Test");
101 Curl_infof(easy, "%s", input);
102 fail_unless(verify(output, input) == 0, "Simple string test");
104 /* Injecting a few different variables with a format */
105 Curl_infof(easy, "%s %d testing %ld", input, 42, 43L);
106 fail_unless(verify(output, "Simple Test 42 testing 43\n") == 0,
107 "Format string");
109 /* Variations of empty strings */
110 Curl_infof(easy, "");
111 fail_unless(strlen(output) == 1, "Empty string");
112 Curl_infof(easy, "%s", (char *)NULL);
113 fail_unless(verify(output, "(nil)") == 0, "Passing NULL as string");
115 /* Note: libcurl's tracebuffer hold 2048 bytes, so the max strlen() we
116 * get out of it is 2047, since we need a \0 at the end.
117 * Curl_infof() in addition adds a \n at the end, making the effective
118 * output 2046 characters.
119 * Any input that long or longer is truncated, ending in '...\n'.
120 */
122 /* A string long enough to not be truncated */
123 memset(input, '\0', sizeof(input));
124 memset(input, 'A', 2045);
125 Curl_infof(easy, "%s", input);
126 curl_mfprintf(stderr, "output len %zu: %s", strlen(output), output);
127 /* output is input + \n */
128 fail_unless(strlen(output) == 2046, "No truncation of infof input");
129 fail_unless(verify(output, input) == 0, "No truncation of infof input");
130 fail_unless(output[sizeof(output) - 1] == '\0',
131 "No truncation of infof input");
133 /* Over the limit without newline for truncation via '...' */
134 memset(input + 2045, 'A', 4);
135 Curl_infof(easy, "%s", input);
136 curl_mfprintf(stderr, "output len %zu: %s", strlen(output), output);
137 fail_unless(strlen(output) == 2047, "Truncation of infof input 1");
138 fail_unless(output[sizeof(output) - 1] == '\0',
139 "Truncation of infof input 1");
141 /* Over the limit with newline for truncation via '...' */
142 memset(input + 2045, 'A', 4);
143 memset(input + 2045 + 4, '\n', 1);
144 Curl_infof(easy, "%s", input);
145 curl_mfprintf(stderr, "output len %zu: %s", strlen(output), output);
146 fail_unless(strlen(output) == 2047, "Truncation of infof input 2");
147 fail_unless(output[sizeof(output) - 1] == '\0',
148 "Truncation of infof input 2");
150 /* Way over the limit for truncation via '...' */
151 memset(input, '\0', sizeof(input));
152 memset(input, 'A', sizeof(input) - 1);
153 Curl_infof(easy, "%s", input);
154 curl_mfprintf(stderr, "output len %zu: %s", strlen(output), output);
155 fail_unless(strlen(output) == 2047, "Truncation of infof input 3");
156 fail_unless(output[sizeof(output) - 1] == '\0',
157 "Truncation of infof input 3");
159#if defined(CURL_HAVE_DIAG) && !defined(__clang__)
160#pragma GCC diagnostic pop
161#endif
163 UNITTEST_END(t1652_stop(easy))
164}
Diagnostics4 git calls · 146 ms
CallStatusSizeTime0146 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 · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 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=3 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
fetch2002.0 KiB141 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=141 git.response.bytes=2069 git.response.cache=MISS git.response.duration_ms=141 git.fetch.wants=312fe8a4b0811fdfecac3939aeb75a1d2a205dde 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=2069 git.pkt.payload.max=2048 git.sideband.band1.bytes=2047 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
- a5e1ffeecc15a9c0
- Request
- d7a75b8b…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format