- badwords: replace stray synonyms with 'null-terminator'.
- tests/FILEFORMAT.md: tidy up feature descriptions.
- printf: replace stray `%i` masks with `%d` for consistency.
- pytest: add comments for empty excepts to try silencing GitHub CodeQL
warnings.
- tool1394, unit1675: merge nested `if`s.
- dnscache: fix typo in comment.
- fix whitespace, indent and newlines.
Closes #21921
Do not allow new code that grows buffers without using dynbuf.
-Use of C functions that rely on a terminating zero must only be used on data
-that really do have a null-terminating zero.
+Use of C functions that rely on a null-terminator must only be used on data
+that really do have a null-terminator (`\0` byte).
## Dangerous "data styles"
-Make extra precautions and verify that memory buffers that need a terminating
-zero always have exactly that. Buffers *without* a null-terminator must not be
-used as input to string functions.
+Make extra precautions and verify that memory buffers that need
+null-terminator always have exactly that. Buffers *without* a null-terminator
+must not be used as input to string functions.
# Commit messages
CURLMcode mresult;
struct GlobalInfo *g;
- printf("%s w %p revents %i\n", __PRETTY_FUNCTION__, (void *)w, revents);
+ printf("%s w %p revents %d\n", __PRETTY_FUNCTION__, (void *)w, revents);
g = (struct GlobalInfo *)w->data;
int action = ((revents & EV_READ) ? CURL_POLL_IN : 0) |
((revents & EV_WRITE) ? CURL_POLL_OUT : 0);
- printf("%s w %p revents %i\n", __PRETTY_FUNCTION__, (void *)w, revents);
+ printf("%s w %p revents %d\n", __PRETTY_FUNCTION__, (void *)w, revents);
g = (struct GlobalInfo *)w->data;
mresult = curl_multi_socket_action(g->multi, w->fd, action,
struct SockInfo *fdp = (struct SockInfo *)sockp;
const char *whatstr[] = { "none", "IN", "OUT", "INOUT", "REMOVE" };
- printf("%s e %p s %i what %i cbp %p sockp %p\n",
+ printf("%s e %p s %d what %d cbp %p sockp %p\n",
__PRETTY_FUNCTION__, e, s, what, cbp, sockp);
fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]);
This is the internal module for creating and handling "dynamic buffers". This
means buffers that can be appended to, dynamically and grow to adapt.
-There is always a terminating zero put at the end of the dynamic buffer.
+There is always a null-terminator put at the end of the dynamic buffer.
The `struct dynbuf` is used to hold data for each instance of a dynamic
buffer. The members of that struct **MUST NOT** be accessed or modified
size_t curlx_dyn_len(const struct dynbuf *s);
```
-Returns the length of the buffer in bytes. Does not include the terminating
-zero byte.
+Returns the length of the buffer in bytes. Does not include the
+null-terminator byte.
## `curlx_dyn_setlen`
**curl_mvsnprintf()** write to the character string **buffer**.
The functions **curl_msnprintf()** and **curl_mvsnprintf()** write at most
-*maxlength* bytes (including the terminating null byte ('0')) to
+*maxlength* bytes (including the null-terminator byte ('0')) to
*buffer*.
The functions **curl_mvprintf()**, **curl_mvfprintf()**,
The *const char ** argument is expected to be a pointer to an array of
character type (pointer to a string). Characters from the array are written up
-to (but not including) a terminating null byte. If a precision is specified,
+to (but not including) a null-terminator byte. If a precision is specified,
no more than the number specified are written. If a precision is given, no
null byte need be present; if the precision is not specified, or is greater
-than the size of the array, the array must contain a terminating null byte.
+than the size of the array, the array must contain a null-terminator byte.
## p
CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
libcurl-errors(3).
-Note that curl_easy_setopt(3) does immediately parse the given string so when
-given a bad DoH URL, libcurl might not detect the problem until it later tries
-to resolve a name with it.
+Note that curl_easy_setopt(3) does not immediately parse the given string so
+when given a bad DoH URL, libcurl might not detect the problem until it later
+tries to resolve a name with it.
- `brotli`
- `c-ares` - c-ares is used for (all) name resolves
- `CharConv`
-- `codeset-utf8`. If the running codeset is UTF-8 capable.
+- `codeset-utf8` - if the running codeset is UTF-8 capable.
- `cookies`
- `crypto`
- `cygwin`
- `IPv6`
- `Kerberos`
- `Largefile`
-- `large-time` (time_t is larger than 32-bit)
-- `large-size` (size_t is larger than 32-bit)
+- `large-time` - time_t is larger than 32-bit
+- `large-size` - size_t is larger than 32-bit
- `libssh2`
- `libssh`
-- `badlibssh` (libssh configuration incompatible with the test suite)
+- `badlibssh` - libssh configuration incompatible with the test suite
- `libz`
-- `local-http`. The HTTP server runs on 127.0.0.1
+- `local-http` - the HTTP server runs on 127.0.0.1
- `manual`
- `mbedtls`
- `Mime`
};
typedef int
- (*curl_sshkeycallback) (CURL *easy, /* easy handle */
- const struct curl_khkey *knownkey, /* known */
- const struct curl_khkey *foundkey, /* found */
- enum curl_khmatch, /* libcurl's view on the keys */
- void *clientp); /* custom pointer passed with */
- /* CURLOPT_SSH_KEYDATA */
+ (*curl_sshkeycallback)(CURL *easy, /* easy handle */
+ const struct curl_khkey *knownkey, /* known */
+ const struct curl_khkey *foundkey, /* found */
+ enum curl_khmatch, /* libcurl's view on the keys */
+ void *clientp); /* custom pointer passed with */
+ /* CURLOPT_SSH_KEYDATA */
typedef int
- (*curl_sshhostkeycallback) (void *clientp,/* custom pointer passed */
- /* with CURLOPT_SSH_HOSTKEYDATA */
+ (*curl_sshhostkeycallback)(void *clientp,/* custom pointer passed */
+ /* with CURLOPT_SSH_HOSTKEYDATA */
int keytype, /* CURLKHTYPE */
const char *key, /* hostkey to check */
size_t keylen); /* length of the key */
client_dest_ip = ipquad.remote_ip;
}
- result = curlx_dyn_addf(&ctx->data_out, "PROXY %s %s %s %i %i\r\n",
+ result = curlx_dyn_addf(&ctx->data_out, "PROXY %s %s %s %d %d\r\n",
is_ipv6 ? "TCP6" : "TCP4",
client_source_ip, client_dest_ip,
ipquad.local_port, ipquad.remote_port);
* We now have the numerical IP address in the 'myhost' buffer
*/
host = myhost;
- infof(data, "Local Interface %s is ip %s using address family %i",
+ infof(data, "Local Interface %s is ip %s using address family %d",
iface, host, af);
done = 1;
break;
int h_af = h->addr->ai_family;
/* convert the resolved address, sizeof myhost >= INET_ADDRSTRLEN */
Curl_printable_address(h->addr, myhost, sizeof(myhost));
- infof(data, "Name '%s' family %i resolved to '%s' family %i",
+ infof(data, "Name '%s' family %d resolved to '%s' family %d",
host, af, myhost, h_af);
Curl_dns_entry_unlink(data, &h); /* this will NULL, potential free h */
if(af != h_af) {
if(num_addrs > 1) {
struct Curl_addrinfo **nodes;
- CURL_TRC_DNS(data, "Shuffling %i addresses", num_addrs);
+ CURL_TRC_DNS(data, "Shuffling %d addresses", num_addrs);
nodes = curlx_malloc(num_addrs * sizeof(*nodes));
if(nodes) {
Curl_hash_delete(&dnscache->entries, entry_id, entry_len + 1);
}
- /* put this new host in the cache, an overridy for ALL dns queries */
+ /* put this new host in the cache, an override for ALL dns queries */
dns = dnscache_add_addr(data, dnscache, CURL_DNSQ_ALL,
&head, curlx_str(&source),
curlx_strlen(&source), port, permanent);
(void)curl_easy_setopt(doh, CURLOPT_SSL_OPTIONS,
((long)data->set.ssl.primary.ssl_options &
- ~CURLSSLOPT_AUTO_CLIENT_CERT));
+ ~CURLSSLOPT_AUTO_CLIENT_CERT));
doh->state.internal = TRUE;
doh->master_mid = data->mid; /* master transfer of this one */
return pgrs_timer_names[(size_t)timer];
return "?";
}
-
#endif /* CURLVERBOSE */
+
/*
* Curl_pgrsTimeWas(). Store the timestamp time at the given label.
*/
/*
* Curl_rand_hex() fills the 'rnd' buffer with a given 'num' size with random
- * hexadecimal digits PLUS a null-terminating byte. It must be an odd number
+ * hexadecimal digits PLUS a null-terminator byte. It must be an odd number
* size.
*/
/*
* Curl_rand_alnum() fills the 'rnd' buffer with a given 'num' size with random
- * alphanumerical chars PLUS a null-terminating byte.
+ * alphanumerical chars PLUS a null-terminator byte.
*/
static const char alnum[] =
/*
* Curl_rand_hex() fills the 'rnd' buffer with a given 'num' size with random
- * hexadecimal digits PLUS a null-terminating byte. It must be an odd number
+ * hexadecimal digits PLUS a null-terminator byte. It must be an odd number
* size.
*/
CURLcode Curl_rand_hex(struct Curl_easy *data, unsigned char *rnd, size_t num);
/*
* Curl_rand_alnum() fills the 'rnd' buffer with a given 'num' size with random
- * alphanumerical chars PLUS a null-terminating byte.
+ * alphanumerical chars PLUS a null-terminator byte.
*/
CURLcode Curl_rand_alnum(struct Curl_easy *data, unsigned char *rnd,
size_t num);
break;
default:
- failf(data, "tftp_tx: internal error, event: %i", (int)event);
+ failf(data, "tftp_tx: internal error, event: %d", (int)event);
break;
}
*
* @unittest 1675
*/
-
UNITTEST int ipv4_normalize(struct dynbuf *host);
UNITTEST int ipv4_normalize(struct dynbuf *host)
{
CURLUcode ures;
u->fragment_present = TRUE;
if(fraglen > 1) {
- /* skip the leading '#' in the copy but include the terminating null */
+ /* skip the leading '#' in the copy but include the null-terminator */
if(flags & CURLU_URLENCODE) {
struct dynbuf enc;
curlx_dyn_init(&enc, CURL_MAX_INPUT_LENGTH);
failf(data, "Found host key type RSA1 which is not supported");
return CURLE_SSH;
default:
- failf(data, "Unknown host key type: %i",
+ failf(data, "Unknown host key type: %d",
(store->typemask & LIBSSH2_KNOWNHOST_KEY_MASK));
return CURLE_SSH;
}
status = SecTrustSetOCSPResponse(trust, ocspdata);
CFRelease(ocspdata);
if(status != noErr) {
- failf(data, "Apple SecTrust: failed to set OCSP response: %i",
+ failf(data, "Apple SecTrust: failed to set OCSP response: %d",
(int)status);
result = CURLE_PEER_FAILED_VERIFICATION;
goto out;
status = SecTrustEvaluate(trust, &sec_result);
if(status != noErr) {
- failf(data, "Apple SecTrust verification failed: error %i", (int)status);
+ failf(data, "Apple SecTrust verification failed: error %d", (int)status);
result = CURLE_PEER_FAILED_VERIFICATION;
}
else if((sec_result == kSecTrustResultUnspecified) ||
if((cnlen <= 0) || !cn)
result = CURLE_OUT_OF_MEMORY;
else if((size_t)cnlen != strlen((char *)cn)) {
- /* there was a terminating zero before the end of string, this
+ /* there was a null-terminator before the end of string, this
cannot match and we return failure! */
failf(data, "SSL: illegal cert name field");
result = CURLE_PEER_FAILED_VERIFICATION;
CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [conditional-uninitialized])
CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [language-extension-token])
fi
+
dnl Only clang 3.1 or later
if test "$compiler_num" -ge "301"; then
CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [format-non-iso])
;;
esac
fi
+
dnl Only clang 3.3 or later
if test "$compiler_num" -ge "303"; then
tmp_CFLAGS="$tmp_CFLAGS -Wno-documentation-unknown-command"
tmp_CFLAGS="$tmp_CFLAGS -Wno-varargs"
fi
fi
+
dnl clang 7 or later
if test "$compiler_num" -ge "700"; then
CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [assign-enum])
CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [extra-semi-stmt])
fi
+
dnl clang 10 or later
if test "$compiler_num" -ge "1000"; then
tmp_CFLAGS="$tmp_CFLAGS -Wimplicit-fallthrough" # we have silencing markup for clang 10.0 and above only
CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [xor-used-as-pow])
fi
+
dnl clang 13 or later
if test "$compiler_num" -ge "1300"; then
CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [cast-function-type])
CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [reserved-identifier]) # Keep it before -Wno-reserved-macro-identifier
tmp_CFLAGS="$tmp_CFLAGS -Wno-reserved-macro-identifier" # Sometimes such external macros need to be set
fi
+
dnl clang 16 or later
if test "$compiler_num" -ge "1600"; then
tmp_CFLAGS="$tmp_CFLAGS -Wno-unsafe-buffer-usage"
fi
+
dnl clang 17 or later
if test "$compiler_num" -ge "1700"; then
CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [cast-function-type-strict]) # with Apple clang it requires 16.0 or above
fi
+
dnl clang 19 or later
if test "$compiler_num" -ge "1901"; then
tmp_CFLAGS="$tmp_CFLAGS -Wno-format-signedness"
fi
+
dnl clang 20 or later
if test "$compiler_num" -ge "2001"; then
CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [array-compare])
fi
+
dnl clang 21 or later
if test "$compiler_num" -ge "2101"; then
CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [c++-hidden-decl])
null terminated:null-terminated
NULL-terminated=null-terminated
zero terminated:null-terminated
+zero-terminated:null-terminated
nul terminator:null-terminator
null terminator:null-terminator
zero terminator:null-terminator
conn.recv(1) # wait for ClientHello
conn.close()
except Exception:
+ # ignore expected socket error
pass
t = threading.Thread(target=accept_and_close)
'rss': mem.rss,
})
except psutil.NoSuchProcess:
+ # process may exit between sampling ticks: ignore this
pass
def finish(self):
try:
self._proc.wait(timeout=1)
except subprocess.TimeoutExpired:
+ # timeout means tcpdump is still running
pass
except Exception:
log.exception('Tcpdump')
async for message in websocket:
await websocket.send(message)
except ConnectionClosedError:
+ # websocket connection closed by client
pass
*success = 0;
}
else {
- curl_mfprintf(stderr, "%s got an unexpected message from curl: %i\n",
+ curl_mfprintf(stderr, "%s got an unexpected message from curl: %d\n",
t530_tag(), message->msg);
result = 1;
*success = 0;
CURLMcode mresult = curl_multi_socket_action(multi, s, evBitmask,
&numhandles);
if(mresult != CURLM_OK) {
- curl_mfprintf(stderr, "%s curl error on %s (%i) %s\n",
+ curl_mfprintf(stderr, "%s curl error on %s (%d) %s\n",
t530_tag(), info, mresult, curl_multi_strerror(mresult));
}
return mresult;
*success = 0;
}
else {
- curl_mfprintf(stderr, "Got an unexpected message from curl: %i\n",
+ curl_mfprintf(stderr, "Got an unexpected message from curl: %d\n",
message->msg);
result = 1;
*success = 0;
CURLMcode mresult = curl_multi_socket_action(multi, s, evBitmask,
&numhandles);
if(mresult != CURLM_OK) {
- curl_mfprintf(stderr, "curl error on %s (%i) %s\n",
+ curl_mfprintf(stderr, "curl error on %s (%d) %s\n",
info, mresult, curl_multi_strerror(mresult));
}
}
*success = 0;
}
else {
- curl_mfprintf(stderr, "%s got an unexpected message from curl: %i\n",
+ curl_mfprintf(stderr, "%s got an unexpected message from curl: %d\n",
t758_tag(), message->msg);
result = 1;
*success = 0;
CURLMcode mresult = curl_multi_socket_action(multi, s, evBitmask,
&numhandles);
if(mresult != CURLM_OK) {
- curl_mfprintf(stderr, "%s curl error on %s (%i) %s\n",
+ curl_mfprintf(stderr, "%s curl error on %s (%d) %s\n",
t758_tag(), info, mresult, curl_multi_strerror(mresult));
}
return mresult;
* in nbytes or it fails with a condition that cannot be handled with a simple
* retry of the read call.
*/
-
static ssize_t fullread(int filedes, void *buffer, size_t nbytes)
{
int error;
* indicated in nbytes or it fails with a condition that cannot be handled
* with a simple retry of the write call.
*/
-
static ssize_t fullwrite(int filedes, const void *buffer, size_t nbytes)
{
int error;
* read or FALSE when an unrecoverable error has been detected. Failure of this
* function is an indication that the sockfilt process should terminate.
*/
-
static bool read_stdin(void *buffer, size_t nbytes)
{
ssize_t nread = fullread(fileno(stdin), buffer, nbytes);
* written or FALSE when an unrecoverable error has been detected. Failure of
* this function is an indication that the sockfilt process should terminate.
*/
-
static bool write_stdout(const void *buffer, size_t nbytes)
{
ssize_t nwrite;
fail("assertion failure");
}
}
- else {
- if(certname) {
- curl_mprintf("expected certname NULL but got '%s' "
- "for -E param '%s'\n", certname, p->param);
- fail("assertion failure");
- }
+ else if(certname) {
+ curl_mprintf("expected certname NULL but got '%s' "
+ "for -E param '%s'\n", certname, p->param);
+ fail("assertion failure");
}
if(p->passwd) {
if(passphrase) {
fail("assertion failure");
}
}
- else {
- if(passphrase) {
- curl_mprintf("expected passphrase NULL but got '%s' "
- "for -E param '%s'\n", passphrase, p->param);
- fail("assertion failure");
- }
+ else if(passphrase) {
+ curl_mprintf("expected passphrase NULL but got '%s' "
+ "for -E param '%s'\n", passphrase, p->param);
+ fail("assertion failure");
}
if(certname)
curlx_free(certname);
fail_unless(victim.canary3 == 41,
"three-byte buffer overwrite has happened");
}
- else {
- if(d == DOH_OK) {
- fail_unless(olen <= sizeof(victim.dohbuffer),
- "wrote outside bounds");
- fail_unless(olen > strlen(name), "unrealistic low size");
- }
+ else if(d == DOH_OK) {
+ fail_unless(olen <= sizeof(victim.dohbuffer),
+ "wrote outside bounds");
+ fail_unless(olen > strlen(name), "unrealistic low size");
}
}
} while(0);
{
UNITTEST_BEGIN_SIMPLE
- /* Test ipv4_normalize */
+ /* Test ipv4_normalize */
{
struct dynbuf host;
int fails = 0;
fails++;
}
}
- else {
- if(rc == HOST_IPV4) {
- curl_mfprintf(stderr, "ipv4_normalize('%s') succeeded unexpectedly:"
- " got '%s'\n",
- tests[i].in, curlx_dyn_ptr(&host));
- fails++;
- }
+ else if(rc == HOST_IPV4) {
+ curl_mfprintf(stderr, "ipv4_normalize('%s') succeeded unexpectedly:"
+ " got '%s'\n",
+ tests[i].in, curlx_dyn_ptr(&host));
+ fails++;
}
}
curlx_dyn_free(&host);
}
}
}
- else {
- if(!uc) {
- curl_mfprintf(stderr, "ipv6_parse('%s') succeeded unexpectedly\n",
- tests[i].in);
- fails++;
- }
+ else if(!uc) {
+ curl_mfprintf(stderr, "ipv6_parse('%s') succeeded unexpectedly\n",
+ tests[i].in);
+ fails++;
}
curlx_free(u.host);
curlx_free(u.zoneid);