checksrc: detect more kinds of NULL comparisons we avoid

Co-authored-by: Jay Satiro
Closes #8180
This commit is contained in:
Daniel Stenberg 2021-12-25 21:41:14 +01:00
parent acaa79f961
commit 21248e052d
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
36 changed files with 87 additions and 87 deletions

View File

@ -154,7 +154,7 @@ static void get_sdp_filename(const char *url, char *sdp_filename,
{ {
const char *s = strrchr(url, '/'); const char *s = strrchr(url, '/');
strcpy(sdp_filename, "video.sdp"); strcpy(sdp_filename, "video.sdp");
if(s != NULL) { if(s) {
s++; s++;
if(s[0] != '\0') { if(s[0] != '\0') {
snprintf(sdp_filename, namelen, "%s.sdp", s); snprintf(sdp_filename, namelen, "%s.sdp", s);
@ -171,8 +171,8 @@ static void get_media_control_attribute(const char *sdp_filename,
char *s = malloc(max_len); char *s = malloc(max_len);
FILE *sdp_fp = fopen(sdp_filename, "rb"); FILE *sdp_fp = fopen(sdp_filename, "rb");
control[0] = '\0'; control[0] = '\0';
if(sdp_fp != NULL) { if(sdp_fp) {
while(fgets(s, max_len - 2, sdp_fp) != NULL) { while(fgets(s, max_len - 2, sdp_fp)) {
sscanf(s, " a = control: %32s", control); sscanf(s, " a = control: %32s", control);
} }
fclose(sdp_fp); fclose(sdp_fp);
@ -239,7 +239,7 @@ int main(int argc, char * const argv[])
/* initialize this curl session */ /* initialize this curl session */
curl = curl_easy_init(); curl = curl_easy_init();
if(curl != NULL) { if(curl) {
my_curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); my_curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
my_curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L); my_curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
my_curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout); my_curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout);

View File

@ -218,7 +218,7 @@ int SyncTime_CURL_Fetch(CURL *curl, char *URL_Str, char *OutFileName,
curl_easy_setopt(curl, CURLOPT_URL, URL_Str); curl_easy_setopt(curl, CURLOPT_URL, URL_Str);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if(outfile != NULL) if(outfile)
fclose(outfile); fclose(outfile);
return res; /* (CURLE_OK) */ return res; /* (CURLE_OK) */
} }

View File

@ -502,7 +502,7 @@ sub scanfile {
} }
# check for '== NULL' in if/while conditions but not if the thing on # check for '== NULL' in if/while conditions but not if the thing on
# the left of it is a function call # the left of it is a function call
if($nostr =~ /^(.*)(if|while)(\(.*[^)]) == NULL/) { if($nostr =~ /^(.*)(if|while)(\(.*?)([!=]= NULL|NULL [!=]=)/) {
checkwarn("EQUALSNULL", $line, checkwarn("EQUALSNULL", $line,
length($1) + length($2) + length($3), length($1) + length($2) + length($3),
$file, $l, "we prefer !variable instead of \"== NULL\" comparisons"); $file, $l, "we prefer !variable instead of \"== NULL\" comparisons");

View File

@ -1164,7 +1164,7 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
bool fromfile = TRUE; bool fromfile = TRUE;
char *line = NULL; char *line = NULL;
if(NULL == inc) { if(!inc) {
/* we didn't get a struct, create one */ /* we didn't get a struct, create one */
c = calloc(1, sizeof(struct CookieInfo)); c = calloc(1, sizeof(struct CookieInfo));
if(!c) if(!c)

View File

@ -822,7 +822,7 @@ static CURLcode dupset(struct Curl_easy *dst, struct Curl_easy *src)
struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data) struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
{ {
struct Curl_easy *outcurl = calloc(1, sizeof(struct Curl_easy)); struct Curl_easy *outcurl = calloc(1, sizeof(struct Curl_easy));
if(NULL == outcurl) if(!outcurl)
goto fail; goto fail;
/* /*

View File

@ -1004,7 +1004,7 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data,
} }
/* parse the port */ /* parse the port */
if(ip_end != NULL) { if(ip_end) {
port_start = strchr(ip_end, ':'); port_start = strchr(ip_end, ':');
if(port_start) { if(port_start) {
port_min = curlx_ultous(strtoul(port_start + 1, NULL, 10)); port_min = curlx_ultous(strtoul(port_start + 1, NULL, 10));
@ -4190,7 +4190,7 @@ CURLcode ftp_parse_url_path(struct Curl_easy *data)
} }
/* parse the URL path into separate path components */ /* parse the URL path into separate path components */
while((slashPos = strchr(curPos, '/')) != NULL) { while((slashPos = strchr(curPos, '/'))) {
size_t compLen = slashPos - curPos; size_t compLen = slashPos - curPos;
/* path starts with a slash: add that as a directory */ /* path starts with a slash: add that as a directory */
@ -4357,7 +4357,7 @@ static CURLcode ftp_setup_connection(struct Curl_easy *data,
struct FTP *ftp; struct FTP *ftp;
data->req.p.ftp = ftp = calloc(sizeof(struct FTP), 1); data->req.p.ftp = ftp = calloc(sizeof(struct FTP), 1);
if(NULL == ftp) if(!ftp)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
ftp->path = &data->state.up.path[1]; /* don't include the initial slash */ ftp->path = &data->state.up.path[1]; /* don't include the initial slash */

View File

@ -89,7 +89,7 @@ static int hostmatch(char *hostname, char *pattern)
match. */ match. */
wildcard_enabled = 1; wildcard_enabled = 1;
pattern_label_end = strchr(pattern, '.'); pattern_label_end = strchr(pattern, '.');
if(!pattern_label_end || strchr(pattern_label_end + 1, '.') == NULL || if(!pattern_label_end || !strchr(pattern_label_end + 1, '.') ||
pattern_wildcard > pattern_label_end || pattern_wildcard > pattern_label_end ||
strncasecompare(pattern, "xn--", 4)) { strncasecompare(pattern, "xn--", 4)) {
wildcard_enabled = 0; wildcard_enabled = 0;

View File

@ -3311,7 +3311,7 @@ checkhttpprefix(struct Curl_easy *data,
#ifdef CURL_DOES_CONVERSIONS #ifdef CURL_DOES_CONVERSIONS
/* convert from the network encoding using a scratch area */ /* convert from the network encoding using a scratch area */
char *scratch = strdup(s); char *scratch = strdup(s);
if(NULL == scratch) { if(!scratch) {
failf(data, "Failed to allocate memory for conversion!"); failf(data, "Failed to allocate memory for conversion!");
return FALSE; /* can't return CURLE_OUT_OF_MEMORY so return FALSE */ return FALSE; /* can't return CURLE_OUT_OF_MEMORY so return FALSE */
} }
@ -3351,7 +3351,7 @@ checkrtspprefix(struct Curl_easy *data,
#ifdef CURL_DOES_CONVERSIONS #ifdef CURL_DOES_CONVERSIONS
/* convert from the network encoding using a scratch area */ /* convert from the network encoding using a scratch area */
char *scratch = strdup(s); char *scratch = strdup(s);
if(NULL == scratch) { if(!scratch) {
failf(data, "Failed to allocate memory for conversion!"); failf(data, "Failed to allocate memory for conversion!");
return FALSE; /* can't return CURLE_OUT_OF_MEMORY so return FALSE */ return FALSE; /* can't return CURLE_OUT_OF_MEMORY so return FALSE */
} }

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -114,7 +114,7 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
if(getifaddrs(&head) >= 0) { if(getifaddrs(&head) >= 0) {
for(iface = head; iface != NULL; iface = iface->ifa_next) { for(iface = head; iface != NULL; iface = iface->ifa_next) {
if(iface->ifa_addr != NULL) { if(iface->ifa_addr) {
if(iface->ifa_addr->sa_family == af) { if(iface->ifa_addr->sa_family == af) {
if(strcasecompare(iface->ifa_name, interf)) { if(strcasecompare(iface->ifa_name, interf)) {
void *addr; void *addr;

View File

@ -1,6 +1,6 @@
/* This is from the BIND 4.9.4 release, modified to compile by itself */ /* This is from the BIND 4.9.4 release, modified to compile by itself */
/* Copyright (c) 1996 - 2020 by Internet Software Consortium. /* Copyright (c) 1996 - 2021 by Internet Software Consortium.
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -174,7 +174,7 @@ inet_pton6(const char *src, unsigned char *dst)
pch = strchr((xdigits = xdigits_l), ch); pch = strchr((xdigits = xdigits_l), ch);
if(!pch) if(!pch)
pch = strchr((xdigits = xdigits_u), ch); pch = strchr((xdigits = xdigits_u), ch);
if(pch != NULL) { if(pch) {
val <<= 4; val <<= 4;
val |= (pch - xdigits); val |= (pch - xdigits);
if(++saw_xdigit > 4) if(++saw_xdigit > 4)
@ -211,7 +211,7 @@ inet_pton6(const char *src, unsigned char *dst)
*tp++ = (unsigned char) ((val >> 8) & 0xff); *tp++ = (unsigned char) ((val >> 8) & 0xff);
*tp++ = (unsigned char) (val & 0xff); *tp++ = (unsigned char) (val & 0xff);
} }
if(colonp != NULL) { if(colonp) {
/* /*
* Since some memmove()'s erroneously fail to handle * Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand. * overlapping regions, we'll do the shift by hand.

View File

@ -880,7 +880,7 @@ Curl_sec_login(struct Curl_easy *data, struct connectdata *conn)
void void
Curl_sec_end(struct connectdata *conn) Curl_sec_end(struct connectdata *conn)
{ {
if(conn->mech != NULL && conn->mech->end) if(conn->mech && conn->mech->end)
conn->mech->end(conn->app_data); conn->mech->end(conn->app_data);
free(conn->app_data); free(conn->app_data);
conn->app_data = NULL; conn->app_data = NULL;

View File

@ -595,7 +595,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done)
attr_len = strlen(attr); attr_len = strlen(attr);
vals = ldap_get_values_len(server, entryIterator, attribute); vals = ldap_get_values_len(server, entryIterator, attribute);
if(vals != NULL) { if(vals) {
for(i = 0; (vals[i] != NULL); i++) { for(i = 0; (vals[i] != NULL); i++) {
result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\t", 1); result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\t", 1);
if(result) { if(result) {

View File

@ -189,7 +189,7 @@ static void MD4_Update(MD4_CTX *ctx, const void *data, unsigned long size)
{ {
if(!ctx->data) { if(!ctx->data) {
ctx->data = malloc(size); ctx->data = malloc(size);
if(ctx->data != NULL) { if(ctx->data) {
memcpy(ctx->data, data, size); memcpy(ctx->data, data, size);
ctx->size = size; ctx->size = size;
} }
@ -198,7 +198,7 @@ static void MD4_Update(MD4_CTX *ctx, const void *data, unsigned long size)
static void MD4_Final(unsigned char *result, MD4_CTX *ctx) static void MD4_Final(unsigned char *result, MD4_CTX *ctx)
{ {
if(ctx->data != NULL) { if(ctx->data) {
#if !defined(HAS_MBEDTLS_RESULT_CODE_BASED_FUNCTIONS) #if !defined(HAS_MBEDTLS_RESULT_CODE_BASED_FUNCTIONS)
mbedtls_md4(ctx->data, ctx->size, result); mbedtls_md4(ctx->data, ctx->size, result);
#else #else

View File

@ -858,7 +858,7 @@ static int dprintf_formatf(
{ {
void *ptr; void *ptr;
ptr = (void *) p->data.ptr; ptr = (void *) p->data.ptr;
if(ptr != NULL) { if(ptr) {
/* If the pointer is not NULL, write it as a %#x spec. */ /* If the pointer is not NULL, write it as a %#x spec. */
base = 16; base = 16;
digits = (p->flags & FLAGS_UPPER)? upper_digits : lower_digits; digits = (p->flags & FLAGS_UPPER)? upper_digits : lower_digits;

View File

@ -107,7 +107,7 @@ struct Curl_tree *Curl_splayinsert(struct curltime i,
if(!node) if(!node)
return t; return t;
if(t != NULL) { if(t) {
t = Curl_splay(i, t); t = Curl_splay(i, t);
if(compare(i, t->key) == 0) { if(compare(i, t->key) == 0) {
/* There already exists a node in the tree with the very same key. Build /* There already exists a node in the tree with the very same key. Build

View File

@ -845,7 +845,7 @@ CURLcode Curl_disconnect(struct Curl_easy *data,
return CURLE_OK; return CURLE_OK;
} }
if(conn->dns_entry != NULL) { if(conn->dns_entry) {
Curl_resolv_unlock(data, conn->dns_entry); Curl_resolv_unlock(data, conn->dns_entry);
conn->dns_entry = NULL; conn->dns_entry = NULL;
} }
@ -2592,7 +2592,7 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data,
if(data->set.str[STRING_PROXY]) { if(data->set.str[STRING_PROXY]) {
proxy = strdup(data->set.str[STRING_PROXY]); proxy = strdup(data->set.str[STRING_PROXY]);
/* if global proxy is set, this is it */ /* if global proxy is set, this is it */
if(NULL == proxy) { if(!proxy) {
failf(data, "memory shortage"); failf(data, "memory shortage");
result = CURLE_OUT_OF_MEMORY; result = CURLE_OUT_OF_MEMORY;
goto out; goto out;
@ -2602,7 +2602,7 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data,
if(data->set.str[STRING_PRE_PROXY]) { if(data->set.str[STRING_PRE_PROXY]) {
socksproxy = strdup(data->set.str[STRING_PRE_PROXY]); socksproxy = strdup(data->set.str[STRING_PRE_PROXY]);
/* if global socks proxy is set, this is it */ /* if global socks proxy is set, this is it */
if(NULL == socksproxy) { if(!socksproxy) {
failf(data, "memory shortage"); failf(data, "memory shortage");
result = CURLE_OUT_OF_MEMORY; result = CURLE_OUT_OF_MEMORY;
goto out; goto out;

View File

@ -230,7 +230,7 @@ static CURLcode auth_digest_get_qop_values(const char *options, int *value)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
token = strtok_r(tmp, ",", &tok_buf); token = strtok_r(tmp, ",", &tok_buf);
while(token != NULL) { while(token) {
if(strcasecompare(token, DIGEST_QOP_VALUE_STRING_AUTH)) if(strcasecompare(token, DIGEST_QOP_VALUE_STRING_AUTH))
*value |= DIGEST_QOP_VALUE_AUTH; *value |= DIGEST_QOP_VALUE_AUTH;
else if(strcasecompare(token, DIGEST_QOP_VALUE_STRING_AUTH_INT)) else if(strcasecompare(token, DIGEST_QOP_VALUE_STRING_AUTH_INT))
@ -556,7 +556,7 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
token = strtok_r(tmp, ",", &tok_buf); token = strtok_r(tmp, ",", &tok_buf);
while(token != NULL) { while(token) {
if(strcasecompare(token, DIGEST_QOP_VALUE_STRING_AUTH)) { if(strcasecompare(token, DIGEST_QOP_VALUE_STRING_AUTH)) {
foundAuth = TRUE; foundAuth = TRUE;
} }

View File

@ -761,10 +761,10 @@ static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data,
CURLcode result = CURLE_SSL_PINNEDPUBKEYNOTMATCH; CURLcode result = CURLE_SSL_PINNEDPUBKEYNOTMATCH;
/* if a path wasn't specified, don't pin */ /* if a path wasn't specified, don't pin */
if(NULL == pinnedpubkey) if(!pinnedpubkey)
return CURLE_OK; return CURLE_OK;
if(NULL == cert) if(!cert)
return result; return result;
do { do {
@ -782,7 +782,7 @@ static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data,
break; /* failed */ break; /* failed */
buff1 = malloc(len1); buff1 = malloc(len1);
if(NULL == buff1) if(!buff1)
break; /* failed */ break; /* failed */
len2 = len1; len2 = len1;
@ -797,7 +797,7 @@ static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data,
result = Curl_pin_peer_pubkey(data, pinnedpubkey, buff1, len1); result = Curl_pin_peer_pubkey(data, pinnedpubkey, buff1, len1);
} while(0); } while(0);
if(NULL != key) if(key)
gnutls_pubkey_deinit(key); gnutls_pubkey_deinit(key);
Curl_safefree(buff1); Curl_safefree(buff1);

View File

@ -784,7 +784,7 @@ static char *nss_get_password(PK11SlotInfo *slot, PRBool retry, void *arg)
{ {
(void)slot; /* unused */ (void)slot; /* unused */
if(retry || NULL == arg) if(retry || !arg)
return NULL; return NULL;
else else
return (char *)PORT_Strdup((char *)arg); return (char *)PORT_Strdup((char *)arg);
@ -1170,7 +1170,7 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
struct SECKEYPrivateKeyStr *key; struct SECKEYPrivateKeyStr *key;
PK11SlotInfo *slot = nss_find_slot_by_name(pem_slotname); PK11SlotInfo *slot = nss_find_slot_by_name(pem_slotname);
if(NULL == slot) { if(!slot) {
failf(data, "NSS: PK11 slot not found: %s", pem_slotname); failf(data, "NSS: PK11 slot not found: %s", pem_slotname);
return SECFailure; return SECFailure;
} }
@ -1184,7 +1184,7 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
cert = PK11_FindCertFromDERCertItem(slot, &cert_der, proto_win); cert = PK11_FindCertFromDERCertItem(slot, &cert_der, proto_win);
SECITEM_FreeItem(&cert_der, PR_FALSE); SECITEM_FreeItem(&cert_der, PR_FALSE);
if(NULL == cert) { if(!cert) {
failf(data, "NSS: client certificate from file not found"); failf(data, "NSS: client certificate from file not found");
PK11_FreeSlot(slot); PK11_FreeSlot(slot);
return SECFailure; return SECFailure;
@ -1192,7 +1192,7 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
key = PK11_FindPrivateKeyFromCert(slot, cert, NULL); key = PK11_FindPrivateKeyFromCert(slot, cert, NULL);
PK11_FreeSlot(slot); PK11_FreeSlot(slot);
if(NULL == key) { if(!key) {
failf(data, "NSS: private key from file not found"); failf(data, "NSS: private key from file not found");
CERT_DestroyCertificate(cert); CERT_DestroyCertificate(cert);
return SECFailure; return SECFailure;
@ -1209,9 +1209,9 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
/* use the default NSS hook */ /* use the default NSS hook */
if(SECSuccess != NSS_GetClientAuthData((void *)nickname, sock, caNames, if(SECSuccess != NSS_GetClientAuthData((void *)nickname, sock, caNames,
pRetCert, pRetKey) pRetCert, pRetKey)
|| NULL == *pRetCert) { || !*pRetCert) {
if(NULL == nickname) if(!nickname)
failf(data, "NSS: client certificate not found (nickname not " failf(data, "NSS: client certificate not found (nickname not "
"specified)"); "specified)");
else else
@ -1222,7 +1222,7 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
/* get certificate nickname if any */ /* get certificate nickname if any */
nickname = (*pRetCert)->nickname; nickname = (*pRetCert)->nickname;
if(NULL == nickname) if(!nickname)
nickname = "[unknown]"; nickname = "[unknown]";
if(!strncmp(nickname, pem_slotname, sizeof(pem_slotname) - 1U)) { if(!strncmp(nickname, pem_slotname, sizeof(pem_slotname) - 1U)) {
@ -1231,7 +1231,7 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
return SECFailure; return SECFailure;
} }
if(NULL == *pRetKey) { if(!*pRetKey) {
failf(data, "NSS: private key not found for certificate: %s", nickname); failf(data, "NSS: private key not found for certificate: %s", nickname);
return SECFailure; return SECFailure;
} }
@ -1346,7 +1346,7 @@ static CURLcode nss_init_core(struct Curl_easy *data, const char *cert_dir)
PRErrorCode err; PRErrorCode err;
const char *err_name; const char *err_name;
if(nss_context != NULL) if(nss_context)
return CURLE_OK; return CURLE_OK;
memset((void *) &initparams, '\0', sizeof(initparams)); memset((void *) &initparams, '\0', sizeof(initparams));
@ -1362,7 +1362,7 @@ static CURLcode nss_init_core(struct Curl_easy *data, const char *cert_dir)
NSS_INIT_READONLY | NSS_INIT_PK11RELOAD); NSS_INIT_READONLY | NSS_INIT_PK11RELOAD);
free(certpath); free(certpath);
if(nss_context != NULL) if(nss_context)
return CURLE_OK; return CURLE_OK;
err = PR_GetError(); err = PR_GetError();
@ -1374,7 +1374,7 @@ static CURLcode nss_init_core(struct Curl_easy *data, const char *cert_dir)
nss_context = NSS_InitContext("", "", "", "", &initparams, NSS_INIT_READONLY nss_context = NSS_InitContext("", "", "", "", &initparams, NSS_INIT_READONLY
| NSS_INIT_NOCERTDB | NSS_INIT_NOMODDB | NSS_INIT_FORCEOPEN | NSS_INIT_NOCERTDB | NSS_INIT_NOMODDB | NSS_INIT_FORCEOPEN
| NSS_INIT_NOROOTINIT | NSS_INIT_OPTIMIZESPACE | NSS_INIT_PK11RELOAD); | NSS_INIT_NOROOTINIT | NSS_INIT_OPTIMIZESPACE | NSS_INIT_PK11RELOAD);
if(nss_context != NULL) if(nss_context)
return CURLE_OK; return CURLE_OK;
err = PR_GetError(); err = PR_GetError();

View File

@ -360,7 +360,7 @@ cr_set_negotiated_alpn(struct Curl_easy *data, struct connectdata *conn,
size_t len = 0; size_t len = 0;
rustls_connection_get_alpn_protocol(rconn, &protocol, &len); rustls_connection_get_alpn_protocol(rconn, &protocol, &len);
if(NULL == protocol) { if(!protocol) {
infof(data, "ALPN, server did not agree to a protocol"); infof(data, "ALPN, server did not agree to a protocol");
return; return;
} }

View File

@ -599,7 +599,7 @@ schannel_acquire_credential_handle(struct Curl_easy *data,
datablob.pbData = (BYTE*)certdata; datablob.pbData = (BYTE*)certdata;
datablob.cbData = (DWORD)certsize; datablob.cbData = (DWORD)certsize;
if(data->set.ssl.key_passwd != NULL) if(data->set.ssl.key_passwd)
pwd_len = strlen(data->set.ssl.key_passwd); pwd_len = strlen(data->set.ssl.key_passwd);
pszPassword = (WCHAR*)malloc(sizeof(WCHAR)*(pwd_len + 1)); pszPassword = (WCHAR*)malloc(sizeof(WCHAR)*(pwd_len + 1));
if(pszPassword) { if(pszPassword) {
@ -1192,7 +1192,7 @@ schannel_connect_step2(struct Curl_easy *data, struct connectdata *conn,
} }
/* free obsolete buffer */ /* free obsolete buffer */
if(outbuf[i].pvBuffer != NULL) { if(outbuf[i].pvBuffer) {
s_pSecFn->FreeContextBuffer(outbuf[i].pvBuffer); s_pSecFn->FreeContextBuffer(outbuf[i].pvBuffer);
} }
} }
@ -2239,7 +2239,7 @@ static int schannel_shutdown(struct Curl_easy *data, struct connectdata *conn,
} }
/* free internal buffer for received encrypted data */ /* free internal buffer for received encrypted data */
if(backend->encdata_buffer != NULL) { if(backend->encdata_buffer) {
Curl_safefree(backend->encdata_buffer); Curl_safefree(backend->encdata_buffer);
backend->encdata_length = 0; backend->encdata_length = 0;
backend->encdata_offset = 0; backend->encdata_offset = 0;
@ -2247,7 +2247,7 @@ static int schannel_shutdown(struct Curl_easy *data, struct connectdata *conn,
} }
/* free internal buffer for received decrypted data */ /* free internal buffer for received decrypted data */
if(backend->decdata_buffer != NULL) { if(backend->decdata_buffer) {
Curl_safefree(backend->decdata_buffer); Curl_safefree(backend->decdata_buffer);
backend->decdata_length = 0; backend->decdata_length = 0;
backend->decdata_offset = 0; backend->decdata_offset = 0;

View File

@ -997,14 +997,14 @@ CF_INLINE CFStringRef getsubject(SecCertificateRef cert)
#else #else
#if CURL_BUILD_MAC_10_7 #if CURL_BUILD_MAC_10_7
/* Lion & later: Get the long description if we can. */ /* Lion & later: Get the long description if we can. */
if(SecCertificateCopyLongDescription != NULL) if(SecCertificateCopyLongDescription)
server_cert_summary = server_cert_summary =
SecCertificateCopyLongDescription(NULL, cert, NULL); SecCertificateCopyLongDescription(NULL, cert, NULL);
else else
#endif /* CURL_BUILD_MAC_10_7 */ #endif /* CURL_BUILD_MAC_10_7 */
#if CURL_BUILD_MAC_10_6 #if CURL_BUILD_MAC_10_6
/* Snow Leopard: Get the certificate summary. */ /* Snow Leopard: Get the certificate summary. */
if(SecCertificateCopySubjectSummary != NULL) if(SecCertificateCopySubjectSummary)
server_cert_summary = SecCertificateCopySubjectSummary(cert); server_cert_summary = SecCertificateCopySubjectSummary(cert);
else else
#endif /* CURL_BUILD_MAC_10_6 */ #endif /* CURL_BUILD_MAC_10_6 */
@ -1118,7 +1118,7 @@ static OSStatus CopyIdentityWithLabel(char *label,
/* SecItemCopyMatching() was introduced in iOS and Snow Leopard. /* SecItemCopyMatching() was introduced in iOS and Snow Leopard.
kSecClassIdentity was introduced in Lion. If both exist, let's use them kSecClassIdentity was introduced in Lion. If both exist, let's use them
to find the certificate. */ to find the certificate. */
if(SecItemCopyMatching != NULL && kSecClassIdentity != NULL) { if(SecItemCopyMatching && kSecClassIdentity) {
CFTypeRef keys[5]; CFTypeRef keys[5];
CFTypeRef values[5]; CFTypeRef values[5];
CFDictionaryRef query_dict; CFDictionaryRef query_dict;
@ -1248,7 +1248,7 @@ static OSStatus CopyIdentityFromPKCS12File(const char *cPath,
CFDictionaryRef options = CFDictionaryCreate(NULL, cKeys, cValues, CFDictionaryRef options = CFDictionaryCreate(NULL, cKeys, cValues,
password ? 1L : 0L, NULL, NULL); password ? 1L : 0L, NULL, NULL);
if(options != NULL) { if(options) {
status = SecPKCS12Import(pkcs_data, options, &items); status = SecPKCS12Import(pkcs_data, options, &items);
CFRelease(options); CFRelease(options);
} }
@ -1406,7 +1406,7 @@ set_ssl_version_min_max(struct Curl_easy *data, struct connectdata *conn,
} }
#if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS #if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
if(SSLSetProtocolVersionMax != NULL) { if(SSLSetProtocolVersionMax) {
SSLProtocol darwin_ver_min = kTLSProtocol1; SSLProtocol darwin_ver_min = kTLSProtocol1;
SSLProtocol darwin_ver_max = kTLSProtocol1; SSLProtocol darwin_ver_max = kTLSProtocol1;
CURLcode result = sectransp_version_from_curl(&darwin_ver_min, CURLcode result = sectransp_version_from_curl(&darwin_ver_min,
@ -1608,7 +1608,7 @@ static CURLcode sectransp_set_selected_ciphers(struct Curl_easy *data,
if(tls_name) { if(tls_name) {
table_cipher_name = ciphertable[i].name; table_cipher_name = ciphertable[i].name;
} }
else if(ciphertable[i].alias_name != NULL) { else if(ciphertable[i].alias_name) {
table_cipher_name = ciphertable[i].alias_name; table_cipher_name = ciphertable[i].alias_name;
} }
else { else {
@ -1688,7 +1688,7 @@ static CURLcode sectransp_connect_step1(struct Curl_easy *data,
#endif /* CURL_BUILD_MAC */ #endif /* CURL_BUILD_MAC */
#if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS #if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
if(SSLCreateContext != NULL) { /* use the newer API if available */ if(SSLCreateContext) { /* use the newer API if available */
if(backend->ssl_ctx) if(backend->ssl_ctx)
CFRelease(backend->ssl_ctx); CFRelease(backend->ssl_ctx);
backend->ssl_ctx = SSLCreateContext(NULL, kSSLClientSide, kSSLStreamType); backend->ssl_ctx = SSLCreateContext(NULL, kSSLClientSide, kSSLStreamType);
@ -1722,7 +1722,7 @@ static CURLcode sectransp_connect_step1(struct Curl_easy *data,
/* check to see if we've been told to use an explicit SSL/TLS version */ /* check to see if we've been told to use an explicit SSL/TLS version */
#if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS #if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
if(SSLSetProtocolVersionMax != NULL) { if(SSLSetProtocolVersionMax) {
switch(conn->ssl_config.version) { switch(conn->ssl_config.version) {
case CURL_SSLVERSION_TLSv1: case CURL_SSLVERSION_TLSv1:
(void)SSLSetProtocolVersionMin(backend->ssl_ctx, kTLSProtocol1); (void)SSLSetProtocolVersionMin(backend->ssl_ctx, kTLSProtocol1);
@ -1980,9 +1980,9 @@ static CURLcode sectransp_connect_step1(struct Curl_easy *data,
Darwin 15.x.x is El Capitan (10.11) Darwin 15.x.x is El Capitan (10.11)
*/ */
#if CURL_BUILD_MAC #if CURL_BUILD_MAC
if(SSLSetSessionOption != NULL && darwinver_maj >= 13) { if(SSLSetSessionOption && darwinver_maj >= 13) {
#else #else
if(SSLSetSessionOption != NULL) { if(SSLSetSessionOption) {
#endif /* CURL_BUILD_MAC */ #endif /* CURL_BUILD_MAC */
bool break_on_auth = !conn->ssl_config.verifypeer || bool break_on_auth = !conn->ssl_config.verifypeer ||
ssl_cafile || ssl_cablob; ssl_cafile || ssl_cablob;
@ -2065,7 +2065,7 @@ static CURLcode sectransp_connect_step1(struct Curl_easy *data,
#if CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7 #if CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7
/* We want to enable 1/n-1 when using a CBC cipher unless the user /* We want to enable 1/n-1 when using a CBC cipher unless the user
specifically doesn't want us doing that: */ specifically doesn't want us doing that: */
if(SSLSetSessionOption != NULL) { if(SSLSetSessionOption) {
SSLSetSessionOption(backend->ssl_ctx, kSSLSessionOptionSendOneByteRecord, SSLSetSessionOption(backend->ssl_ctx, kSSLSessionOptionSendOneByteRecord,
!SSL_SET_OPTION(enable_beast)); !SSL_SET_OPTION(enable_beast));
SSLSetSessionOption(backend->ssl_ctx, kSSLSessionOptionFalseStart, SSLSetSessionOption(backend->ssl_ctx, kSSLSessionOptionFalseStart,
@ -2521,7 +2521,7 @@ static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data,
} while(0); } while(0);
Curl_safefree(realpubkey); Curl_safefree(realpubkey);
if(publicKeyBits != NULL) if(publicKeyBits)
CFRelease(publicKeyBits); CFRelease(publicKeyBits);
return result; return result;
@ -2947,7 +2947,7 @@ collect_server_cert(struct Curl_easy *data,
private API and doesn't work as expected. So we have to look for private API and doesn't work as expected. So we have to look for
a different symbol to make sure this code is only executed under a different symbol to make sure this code is only executed under
Lion or later. */ Lion or later. */
if(SecTrustEvaluateAsync != NULL) { if(SecTrustEvaluateAsync) {
#pragma unused(server_certs) #pragma unused(server_certs)
err = SSLCopyPeerTrust(backend->ssl_ctx, &trust); err = SSLCopyPeerTrust(backend->ssl_ctx, &trust);
/* For some reason, SSLCopyPeerTrust() can return noErr and yet return /* For some reason, SSLCopyPeerTrust() can return noErr and yet return
@ -3165,7 +3165,7 @@ static void sectransp_close(struct Curl_easy *data, struct connectdata *conn,
if(backend->ssl_ctx) { if(backend->ssl_ctx) {
(void)SSLClose(backend->ssl_ctx); (void)SSLClose(backend->ssl_ctx);
#if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS #if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
if(SSLCreateContext != NULL) if(SSLCreateContext)
CFRelease(backend->ssl_ctx); CFRelease(backend->ssl_ctx);
#if CURL_SUPPORT_MAC_10_8 #if CURL_SUPPORT_MAC_10_8
else else
@ -3329,7 +3329,7 @@ static CURLcode sectransp_sha256sum(const unsigned char *tmp, /* input */
static bool sectransp_false_start(void) static bool sectransp_false_start(void)
{ {
#if CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7 #if CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7
if(SSLSetSessionOption != NULL) if(SSLSetSessionOption)
return TRUE; return TRUE;
#endif #endif
return FALSE; return FALSE;

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -124,12 +124,12 @@ CURLcode create_dir_hierarchy(const char *outfile, FILE *errors)
/* !checksrc! disable BANNEDFUNC 2 */ /* !checksrc! disable BANNEDFUNC 2 */
tempdir = strtok(outdup, PATH_DELIMITERS); tempdir = strtok(outdup, PATH_DELIMITERS);
while(tempdir != NULL) { while(tempdir) {
bool skip = false; bool skip = false;
tempdir2 = strtok(NULL, PATH_DELIMITERS); tempdir2 = strtok(NULL, PATH_DELIMITERS);
/* since strtok returns a token for the last word even /* since strtok returns a token for the last word even
if not ending with DIR_CHAR, we need to prune it */ if not ending with DIR_CHAR, we need to prune it */
if(tempdir2 != NULL) { if(tempdir2) {
size_t dlen = strlen(dirbuildup); size_t dlen = strlen(dirbuildup);
if(dlen) if(dlen)
msnprintf(&dirbuildup[dlen], outlen - dlen, "%s%s", DIR_CHAR, tempdir); msnprintf(&dirbuildup[dlen], outlen - dlen, "%s%s", DIR_CHAR, tempdir);

View File

@ -280,7 +280,7 @@ int main(int argc, char *argv[])
} }
#ifdef __NOVELL_LIBC__ #ifdef __NOVELL_LIBC__
if(getenv("_IN_NETWARE_BASH_") == NULL) if(!getenv("_IN_NETWARE_BASH_"))
tool_pressanykey(); tool_pressanykey();
#endif #endif

View File

@ -100,7 +100,7 @@ int fwrite_xattr(CURL *curl, int fd)
int err = 0; int err = 0;
/* loop through all xattr-curlinfo pairs and abort on a set error */ /* loop through all xattr-curlinfo pairs and abort on a set error */
while(err == 0 && mappings[i].attr != NULL) { while(err == 0 && mappings[i].attr) {
char *value = NULL; char *value = NULL;
CURLcode result = curl_easy_getinfo(curl, mappings[i].info, &value); CURLcode result = curl_easy_getinfo(curl, mappings[i].info, &value);
if(!result && value) { if(!result && value) {

View File

@ -44,7 +44,7 @@ int test(char *URL)
__FILE__, __LINE__, res, curl_easy_strerror(res)); __FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup; goto test_cleanup;
} }
if(scheme != NULL) { if(scheme) {
fprintf(stderr, "%s:%d scheme init failed; expected NULL\n", fprintf(stderr, "%s:%d scheme init failed; expected NULL\n",
__FILE__, __LINE__); __FILE__, __LINE__);
res = CURLE_FAILED_INIT; res = CURLE_FAILED_INIT;

View File

@ -122,7 +122,7 @@ int test(char *URL)
abort_on_test_timeout(); abort_on_test_timeout();
while((message = curl_multi_info_read(multi, &num)) != NULL) { while((message = curl_multi_info_read(multi, &num))) {
if(message->msg == CURLMSG_DONE) { if(message->msg == CURLMSG_DONE) {
res = message->data.result; res = message->data.result;
if(res) if(res)

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -53,7 +53,7 @@ int test(char *URL)
} }
hd_src = fopen(libtest_arg2, "rb"); hd_src = fopen(libtest_arg2, "rb");
if(NULL == hd_src) { if(!hd_src) {
fprintf(stderr, "fopen failed with error: %d %s\n", fprintf(stderr, "fopen failed with error: %d %s\n",
errno, strerror(errno)); errno, strerror(errno));
fprintf(stderr, "Error opening file: %s\n", libtest_arg2); fprintf(stderr, "Error opening file: %s\n", libtest_arg2);

View File

@ -91,7 +91,7 @@ static int fopen_works(void)
} }
} }
for(i = 0; i < 3; i++) { for(i = 0; i < 3; i++) {
if(fpa[i] != NULL) if(fpa[i])
fclose(fpa[i]); fclose(fpa[i]);
} }
return ret; return ret;

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -53,7 +53,7 @@ int test(char *URL)
} }
hd_src = fopen(libtest_arg2, "rb"); hd_src = fopen(libtest_arg2, "rb");
if(NULL == hd_src) { if(!hd_src) {
fprintf(stderr, "fopen failed with error: %d (%s)\n", fprintf(stderr, "fopen failed with error: %d (%s)\n",
errno, strerror(errno)); errno, strerror(errno));
fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2); fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2);

View File

@ -179,7 +179,7 @@ static int checkForCompletion(CURLM *curl, int *success)
CURLMsg *message; CURLMsg *message;
int result = 0; int result = 0;
*success = 0; *success = 0;
while((message = curl_multi_info_read(curl, &numMessages)) != NULL) { while((message = curl_multi_info_read(curl, &numMessages))) {
if(message->msg == CURLMSG_DONE) { if(message->msg == CURLMSG_DONE) {
result = 1; result = 1;
if(message->data.result == CURLE_OK) if(message->data.result == CURLE_OK)

View File

@ -92,7 +92,7 @@ static int fopen_works(void)
} }
} }
for(i = 0; i < 3; i++) { for(i = 0; i < 3; i++) {
if(fpa[i] != NULL) if(fpa[i])
fclose(fpa[i]); fclose(fpa[i]);
} }
return ret; return ret;

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -155,7 +155,7 @@ static int loop(int num, CURLM *cm, const char *url, const char *userpwd,
return res; return res;
} }
while((msg = curl_multi_info_read(cm, &Q)) != NULL) { while((msg = curl_multi_info_read(cm, &Q))) {
if(msg->msg == CURLMSG_DONE) { if(msg->msg == CURLMSG_DONE) {
int i; int i;
CURL *e = msg->easy_handle; CURL *e = msg->easy_handle;

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -45,7 +45,7 @@ int test(char *URL)
} }
hd_src = fopen(libtest_arg2, "rb"); hd_src = fopen(libtest_arg2, "rb");
if(NULL == hd_src) { if(!hd_src) {
fprintf(stderr, "fopen failed with error: %d %s\n", fprintf(stderr, "fopen failed with error: %d %s\n",
errno, strerror(errno)); errno, strerror(errno));
fprintf(stderr, "Error opening file: %s\n", libtest_arg2); fprintf(stderr, "Error opening file: %s\n", libtest_arg2);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -151,7 +151,7 @@ static int checkForCompletion(CURLM *curl, int *success)
CURLMsg *message; CURLMsg *message;
int result = 0; int result = 0;
*success = 0; *success = 0;
while((message = curl_multi_info_read(curl, &numMessages)) != NULL) { while((message = curl_multi_info_read(curl, &numMessages))) {
if(message->msg == CURLMSG_DONE) { if(message->msg == CURLMSG_DONE) {
result = 1; result = 1;
if(message->data.result == CURLE_OK) if(message->data.result == CURLE_OK)
@ -242,7 +242,7 @@ int test(char *URL)
} }
hd_src = fopen(libtest_arg2, "rb"); hd_src = fopen(libtest_arg2, "rb");
if(NULL == hd_src) { if(!hd_src) {
fprintf(stderr, "fopen() failed with error: %d (%s)\n", fprintf(stderr, "fopen() failed with error: %d (%s)\n",
errno, strerror(errno)); errno, strerror(errno));
fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2); fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2);

View File

@ -129,7 +129,7 @@ UNITTEST_START
printf("Removing nodes not larger than %d\n", i); printf("Removing nodes not larger than %d\n", i);
tv_now.tv_usec = i; tv_now.tv_usec = i;
root = Curl_splaygetbest(tv_now, root, &removed); root = Curl_splaygetbest(tv_now, root, &removed);
while(removed != NULL) { while(removed) {
printf("removed payload %zu[%zu]\n", printf("removed payload %zu[%zu]\n",
(*(size_t *)removed->payload) / 10, (*(size_t *)removed->payload) / 10,
(*(size_t *)removed->payload) % 10); (*(size_t *)removed->payload) % 10);