1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-09-11 13:30:44 +03:00

checksrc: fix EQUALSNULL warnings

`s/([a-z0-9._>*-]+) == NULL/!\1/g`

Closes #964
This commit is contained in:
Viktor Szakats
2023-04-15 02:46:09 +00:00
parent cd5b114e7d
commit 5d399233d8
20 changed files with 248 additions and 244 deletions

View File

@@ -84,7 +84,6 @@ checksrc:
-ASNPRINTF \
-ACOPYRIGHT \
-AFOPENMODE \
-AEQUALSNULL \
-ATYPEDEFSTRUCT \
-Wsrc/libssh2_config.h src/*.[ch] include/*.h example/*.c \
tests/*.[ch]

View File

@@ -9,6 +9,5 @@ perl ./ci/checksrc.pl -i4 -m79 \
-ASNPRINTF \
-ACOPYRIGHT \
-AFOPENMODE \
-AEQUALSNULL \
-ATYPEDEFSTRUCT \
$WHITELIST $FILES

View File

@@ -299,12 +299,12 @@ agent_transact_pageant(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
filemap = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
0, PAGEANT_MAX_MSGLEN, mapname);
if(filemap == NULL || filemap == INVALID_HANDLE_VALUE)
if(!filemap || filemap == INVALID_HANDLE_VALUE)
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
"failed setting up pageant filemap");
p2 = p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0);
if(p == NULL || p2 == NULL) {
if(!p || !p2) {
CloseHandle(filemap);
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
"failed to open pageant filemap for writing");
@@ -858,7 +858,7 @@ libssh2_agent_free(LIBSSH2_AGENT *agent)
libssh2_agent_disconnect(agent);
}
if(agent->identity_agent_path != NULL)
if(agent->identity_agent_path)
LIBSSH2_FREE(agent->session, agent->identity_agent_path);
agent_free_identities(agent);

View File

@@ -184,7 +184,7 @@ agent_connect_openssh(LIBSSH2_AGENT *agent)
}
event = CreateEventA(NULL, TRUE, FALSE, NULL);
if(event == NULL) {
if(!event) {
ret = _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
"unable to create async I/O event");
goto cleanup;
@@ -197,7 +197,7 @@ agent_connect_openssh(LIBSSH2_AGENT *agent)
agent->fd = 0; /* Mark as the connection has been established */
cleanup:
if(event != NULL)
if(event)
CloseHandle(event);
if(pipe != INVALID_HANDLE_VALUE)
CloseHandle(pipe);

View File

@@ -123,7 +123,7 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt,
keylen > sizeof(out) * sizeof(out) || saltlen > 1<<20)
return -1;
countsalt = calloc(1, saltlen + 4);
if(countsalt == NULL)
if(!countsalt)
return -1;
stride = (keylen + sizeof(out) - 1) / sizeof(out);
amt = (keylen + stride - 1) / stride;

View File

@@ -2274,7 +2274,7 @@ _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel, int stream_id)
uint32_t read_local_id;
read_packet = _libssh2_list_first(&session->packets);
if(read_packet == NULL)
if(!read_packet)
return 0;
while(read_packet) {

View File

@@ -235,7 +235,7 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session,
out_maxlen = payload_limit;
/* If strm is null, then we have not yet been initialized. */
if(strm == NULL)
if(!strm)
return _libssh2_error(session, LIBSSH2_ERROR_COMPRESS,
"decompression uninitialized");

View File

@@ -722,7 +722,7 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session,
libssh2_curve_type type;
struct string_buf buf;
if(abstract != NULL && *abstract) {
if(abstract && *abstract) {
hostkey_method_ssh_ecdsa_dtor(session, abstract);
*abstract = NULL;
}
@@ -780,7 +780,7 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session,
key_len, type))
return -1;
if(abstract != NULL)
if(abstract)
*abstract = ecdsactx;
return 0;
@@ -800,7 +800,7 @@ hostkey_method_ssh_ecdsa_initPEM(LIBSSH2_SESSION * session,
libssh2_ecdsa_ctx *ec_ctx = NULL;
int ret;
if(abstract != NULL && *abstract) {
if(abstract && *abstract) {
hostkey_method_ssh_ecdsa_dtor(session, abstract);
*abstract = NULL;
}
@@ -808,7 +808,7 @@ hostkey_method_ssh_ecdsa_initPEM(LIBSSH2_SESSION * session,
ret = _libssh2_ecdsa_new_private(&ec_ctx, session,
privkeyfile, passphrase);
if(abstract != NULL)
if(abstract)
*abstract = ec_ctx;
return ret;
@@ -829,7 +829,7 @@ hostkey_method_ssh_ecdsa_initPEMFromMemory(LIBSSH2_SESSION * session,
libssh2_ecdsa_ctx *ec_ctx = NULL;
int ret;
if(abstract != NULL && *abstract) {
if(abstract && *abstract) {
hostkey_method_ssh_ecdsa_dtor(session, abstract);
*abstract = NULL;
}
@@ -842,7 +842,7 @@ hostkey_method_ssh_ecdsa_initPEMFromMemory(LIBSSH2_SESSION * session,
return -1;
}
if(abstract != NULL)
if(abstract)
*abstract = ec_ctx;
return 0;
@@ -954,7 +954,7 @@ hostkey_method_ssh_ecdsa_dtor(LIBSSH2_SESSION * session, void **abstract)
libssh2_ecdsa_ctx *keyctx = (libssh2_ecdsa_ctx *) (*abstract);
(void) session;
if(keyctx != NULL)
if(keyctx)
_libssh2_ecdsa_free(keyctx);
*abstract = NULL;
@@ -1140,7 +1140,7 @@ hostkey_method_ssh_ed25519_initPEMFromMemory(LIBSSH2_SESSION * session,
libssh2_ed25519_ctx *ed_ctx = NULL;
int ret;
if(abstract != NULL && *abstract) {
if(abstract && *abstract) {
hostkey_method_ssh_ed25519_dtor(session, abstract);
*abstract = NULL;
}
@@ -1153,7 +1153,7 @@ hostkey_method_ssh_ed25519_initPEMFromMemory(LIBSSH2_SESSION * session,
return -1;
}
if(abstract != NULL)
if(abstract)
*abstract = ed_ctx;
return 0;

View File

@@ -468,7 +468,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session,
(const char *)
session->server_hostkey_sha256,
SHA256_DIGEST_LENGTH, &base64Fingerprint);
if(base64Fingerprint != NULL) {
if(base64Fingerprint) {
_libssh2_debug((session, LIBSSH2_TRACE_KEX,
"Server's SHA256 Fingerprint: %s",
base64Fingerprint));
@@ -1675,7 +1675,7 @@ kex_session_ecdh_curve_type(const char *name, libssh2_curve_type *out_type)
int ret = 0;
libssh2_curve_type type;
if(name == NULL)
if(!name)
return -1;
if(strcmp(name, "ecdh-sha2-nistp256") == 0)
@@ -1830,7 +1830,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
(const char *)
session->server_hostkey_sha256,
SHA256_DIGEST_LENGTH, &base64Fingerprint);
if(base64Fingerprint != NULL) {
if(base64Fingerprint) {
_libssh2_debug((session, LIBSSH2_TRACE_KEX,
"Server's SHA256 Fingerprint: %s",
base64Fingerprint));
@@ -2462,7 +2462,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data,
(const char *)
session->server_hostkey_sha256,
SHA256_DIGEST_LENGTH, &base64Fingerprint);
if(base64Fingerprint != NULL) {
if(base64Fingerprint) {
_libssh2_debug((session, LIBSSH2_TRACE_KEX,
"Server's SHA256 Fingerprint: %s",
base64Fingerprint));
@@ -3306,7 +3306,7 @@ kex_agree_instr(unsigned char *haystack, size_t haystack_len,
unsigned char *end_haystack;
size_t left;
if(haystack == NULL || needle == NULL) {
if(!haystack || !needle) {
return NULL;
}
@@ -3327,6 +3327,7 @@ kex_agree_instr(unsigned char *haystack, size_t haystack_len,
/* Search until we run out of comas or we run out of haystack,
whichever comes first */
/* !checksrc! disable EQUALSNULL 1 */
while((s = (unsigned char *) memchr((char *) s, ',', left)) != NULL) {
/* Advance buffer past coma if we can */
left = end_haystack - s;
@@ -4070,7 +4071,7 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
const LIBSSH2_COMMON_METHOD **mlist;
/* to prevent coredumps due to dereferencing of NULL */
if(NULL == algs)
if(!algs)
return _libssh2_error(session, LIBSSH2_ERROR_BAD_USE,
"algs must not be NULL");
@@ -4110,7 +4111,7 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
} /* switch */
/* weird situation */
if(NULL == mlist)
if(!mlist)
return _libssh2_error(session, LIBSSH2_ERROR_INVAL,
"No algorithm found");
@@ -4127,7 +4128,7 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
*/
/* count the number of supported algorithms */
for(i = 0, ialg = 0; NULL != mlist[i]; i++) {
for(i = 0, ialg = 0; mlist[i]; i++) {
/* do not count fields with NULL name */
if(mlist[i]->name)
ialg++;
@@ -4140,15 +4141,15 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
/* allocate buffer */
*algs = (const char **) LIBSSH2_ALLOC(session, ialg*sizeof(const char *));
if(NULL == *algs) {
if(!*algs) {
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Memory allocation failed");
}
/* Past this point *algs must be deallocated in case of an error!! */
/* copy non-NULL pointers only */
for(i = 0, j = 0; NULL != mlist[i] && j < ialg; i++) {
if(NULL == mlist[i]->name) {
for(i = 0, j = 0; mlist[i] && j < ialg; i++) {
if(!mlist[i]->name) {
/* maybe a weird situation but if it occurs, do not include NULL
pointers */
continue;

View File

@@ -192,7 +192,7 @@ _libssh2_mbedtls_hash_init(mbedtls_md_context_t *ctx,
if(!md_info)
return 0;
hmac = key == NULL ? 0 : 1;
hmac = key ? 1 : 0;
mbedtls_md_init(ctx);
ret = mbedtls_md_setup(ctx, md_info, hmac);
@@ -336,7 +336,7 @@ _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa,
libssh2_rsa_ctx *ctx;
ctx = (libssh2_rsa_ctx *) mbedtls_calloc(1, sizeof(libssh2_rsa_ctx));
if(ctx != NULL) {
if(ctx) {
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
mbedtls_rsa_init(ctx);
#else
@@ -400,7 +400,7 @@ _libssh2_mbedtls_rsa_new_private(libssh2_rsa_ctx **rsa,
mbedtls_rsa_context *pk_rsa;
*rsa = (libssh2_rsa_ctx *) LIBSSH2_ALLOC(session, sizeof(libssh2_rsa_ctx));
if(*rsa == NULL)
if(!*rsa)
return -1;
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
@@ -446,7 +446,7 @@ _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa,
size_t pwd_len;
*rsa = (libssh2_rsa_ctx *) mbedtls_calloc(1, sizeof(libssh2_rsa_ctx));
if(*rsa == NULL)
if(!*rsa)
return -1;
/*
@@ -454,14 +454,14 @@ _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa,
private-key from memory will fail if the last byte is not a null byte
*/
filedata_nullterm = mbedtls_calloc(filedata_len + 1, 1);
if(filedata_nullterm == NULL) {
if(!filedata_nullterm) {
return -1;
}
memcpy(filedata_nullterm, filedata, filedata_len);
mbedtls_pk_init(&pkey);
pwd_len = passphrase != NULL ? strlen((const char *)passphrase) : 0;
pwd_len = passphrase ? strlen((const char *)passphrase) : 0;
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
ret = mbedtls_pk_parse_key(&pkey, (unsigned char *)filedata_nullterm,
filedata_len + 1,
@@ -505,7 +505,7 @@ _libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx,
return -1;
hash = malloc(hash_len);
if(hash == NULL)
if(!hash)
return -1;
if(hash_len == SHA_DIGEST_LENGTH) {
@@ -699,7 +699,7 @@ _libssh2_mbedtls_pub_priv_key(LIBSSH2_SESSION *session,
rsa = mbedtls_pk_rsa(*pkey);
key = gen_publickey_from_rsa(session, rsa, &keylen);
if(key == NULL) {
if(!key) {
ret = -1;
}
@@ -776,14 +776,14 @@ _libssh2_mbedtls_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
private-key from memory will fail if the last byte is not a null byte
*/
privatekeydata_nullterm = mbedtls_calloc(privatekeydata_len + 1, 1);
if(privatekeydata_nullterm == NULL) {
if(!privatekeydata_nullterm) {
return -1;
}
memcpy(privatekeydata_nullterm, privatekeydata, privatekeydata_len);
mbedtls_pk_init(&pkey);
pwd_len = passphrase != NULL ? strlen((const char *)passphrase) : 0;
pwd_len = passphrase ? strlen((const char *)passphrase) : 0;
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
ret = mbedtls_pk_parse_key(&pkey,
(unsigned char *)privatekeydata_nullterm,
@@ -915,7 +915,7 @@ _libssh2_mbedtls_ecdsa_create_key(LIBSSH2_SESSION *session,
*privkey = LIBSSH2_ALLOC(session, sizeof(mbedtls_ecp_keypair));
if(*privkey == NULL)
if(!*privkey)
goto failed;
mbedtls_ecdsa_init(*privkey);
@@ -928,7 +928,7 @@ _libssh2_mbedtls_ecdsa_create_key(LIBSSH2_SESSION *session,
plen = 2 * mbedtls_mpi_size(&(*privkey)->MBEDTLS_PRIVATE(grp).P) + 1;
*pubkey_oct = LIBSSH2_ALLOC(session, plen);
if(*pubkey_oct == NULL)
if(!*pubkey_oct)
goto failed;
if(mbedtls_ecp_point_write_binary(&(*privkey)->MBEDTLS_PRIVATE(grp),
@@ -960,7 +960,7 @@ _libssh2_mbedtls_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx **ctx,
{
*ctx = mbedtls_calloc(1, sizeof(mbedtls_ecp_keypair));
if(*ctx == NULL)
if(!*ctx)
goto failed;
mbedtls_ecdsa_init(*ctx);
@@ -1001,7 +1001,7 @@ _libssh2_mbedtls_ecdh_gen_k(_libssh2_bn **k,
mbedtls_ecp_point pubkey;
int rc = 0;
if(*k == NULL)
if(!*k)
return -1;
mbedtls_ecp_point_init(&pubkey);
@@ -1117,7 +1117,7 @@ _libssh2_mbedtls_parse_eckey(libssh2_ecdsa_ctx **ctx,
*ctx = LIBSSH2_ALLOC(session, sizeof(libssh2_ecdsa_ctx));
if(*ctx == NULL)
if(!*ctx)
goto failed;
mbedtls_ecdsa_init(*ctx);
@@ -1169,7 +1169,7 @@ _libssh2_mbedtls_parse_openssh_key(libssh2_ecdsa_ctx **ctx,
*ctx = LIBSSH2_ALLOC(session, sizeof(libssh2_ecdsa_ctx));
if(*ctx == NULL)
if(!*ctx)
goto failed;
mbedtls_ecdsa_init(*ctx);
@@ -1205,7 +1205,7 @@ cleanup:
_libssh2_string_buf_free(session, decrypted);
}
return (*ctx == NULL) ? -1 : 0;
return *ctx ? 0 : -1;
}
/* _libssh2_ecdsa_new_private
@@ -1241,7 +1241,7 @@ cleanup:
_libssh2_mbedtls_safe_free(data, data_len);
return (*ctx == NULL) ? -1 : 0;
return *ctx ? 0 : -1;
}
/* _libssh2_ecdsa_new_private
@@ -1264,7 +1264,7 @@ _libssh2_mbedtls_ecdsa_new_private_frommemory(libssh2_ecdsa_ctx **ctx,
ntdata = LIBSSH2_ALLOC(session, data_len + 1);
if(ntdata == NULL)
if(!ntdata)
goto cleanup;
memcpy(ntdata, data, data_len);
@@ -1282,7 +1282,7 @@ cleanup:
_libssh2_mbedtls_safe_free(ntdata, data_len);
return (*ctx == NULL) ? -1 : 0;
return *ctx ? 0 : -1;
}
static unsigned char *
@@ -1349,7 +1349,7 @@ _libssh2_mbedtls_ecdsa_sign(LIBSSH2_SESSION *session,
tmp_sign = LIBSSH2_CALLOC(session, tmp_sign_len);
if(tmp_sign == NULL)
if(!tmp_sign)
goto cleanup;
sp = tmp_sign;
@@ -1360,7 +1360,7 @@ _libssh2_mbedtls_ecdsa_sign(LIBSSH2_SESSION *session,
*sign = LIBSSH2_CALLOC(session, *sign_len);
if(*sign == NULL)
if(!*sign)
goto cleanup;
memcpy(*sign, tmp_sign, *sign_len);
@@ -1372,7 +1372,7 @@ cleanup:
_libssh2_mbedtls_safe_free(tmp_sign, tmp_sign_len);
return (*sign == NULL) ? -1 : 0;
return *sign ? 0 : -1;
}
/* _libssh2_ecdsa_get_curve_type
@@ -1400,7 +1400,7 @@ _libssh2_mbedtls_ecdsa_curve_type_from_name(const char *name,
int ret = 0;
libssh2_curve_type type;
if(name == NULL || strlen(name) != 19)
if(!name || strlen(name) != 19)
return -1;
if(strcmp(name, "ecdsa-sha2-nistp256") == 0)

View File

@@ -86,8 +86,8 @@ int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...)
int _libssh2_error_flags(LIBSSH2_SESSION* session, int errcode,
const char *errmsg, int errflags)
{
if(session == NULL) {
if(errmsg != NULL)
if(!session) {
if(errmsg)
fprintf(stderr, "Session is NULL, error: %s\n", errmsg);
return errcode;
}
@@ -98,7 +98,7 @@ int _libssh2_error_flags(LIBSSH2_SESSION* session, int errcode,
session->err_code = errcode;
session->err_flags = 0;
if((errmsg != NULL) && ((errflags & LIBSSH2_ERR_FLAG_DUP) != 0)) {
if(errmsg && ((errflags & LIBSSH2_ERR_FLAG_DUP) != 0)) {
size_t len = strlen(errmsg);
char *copy = LIBSSH2_ALLOC(session, len + 1);
if(copy) {
@@ -400,7 +400,7 @@ size_t _libssh2_base64_encode(LIBSSH2_SESSION *session,
insize = strlen(indata);
base64data = output = LIBSSH2_ALLOC(session, insize * 4 / 3 + 4);
if(NULL == output)
if(!output)
return 0;
while(insize > 0) {
@@ -756,7 +756,7 @@ struct string_buf *_libssh2_string_buf_new(LIBSSH2_SESSION *session)
struct string_buf *ret;
ret = _libssh2_calloc(session, sizeof(*ret));
if(ret == NULL)
if(!ret)
return NULL;
return ret;
@@ -764,10 +764,10 @@ struct string_buf *_libssh2_string_buf_new(LIBSSH2_SESSION *session)
void _libssh2_string_buf_free(LIBSSH2_SESSION *session, struct string_buf *buf)
{
if(buf == NULL)
if(!buf)
return;
if(buf->data != NULL)
if(buf->data)
LIBSSH2_FREE(session, buf->data);
LIBSSH2_FREE(session, buf);

File diff suppressed because it is too large Load Diff

View File

@@ -649,7 +649,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
_libssh2_get_string(&buf, &name, &name_len);
_libssh2_get_string(&buf, &value, &value_len);
if(name != NULL && value != NULL) {
if(name && value) {
_libssh2_debug((session,
LIBSSH2_TRACE_KEX,
"Server to Client extension %.*s: %.*s",

View File

@@ -142,6 +142,7 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session,
}
all_methods = libssh2_crypt_methods();
/* !checksrc! disable EQUALSNULL 1 */
while((cur_method = *all_methods++) != NULL) {
if(*cur_method->pem_annotation &&
memcmp(line, cur_method->pem_annotation,
@@ -153,7 +154,7 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session,
}
/* None of the available crypt methods were able to decrypt the key */
if(method == NULL)
if(!method)
return -1;
/* Decode IV from hex */
@@ -441,7 +442,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
kdf_buf.len = kdf_len;
}
if((passphrase == NULL || strlen((const char *)passphrase) == 0) &&
if((!passphrase || strlen((const char *)passphrase) == 0) &&
strcmp((const char *)ciphername, "none") != 0) {
/* passphrase required */
ret = LIBSSH2_ERROR_KEYFILE_AUTH_FAILED;
@@ -491,6 +492,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
const LIBSSH2_CRYPT_METHOD **all_methods, *cur_method;
all_methods = libssh2_crypt_methods();
/* !checksrc! disable EQUALSNULL 1 */
while((cur_method = *all_methods++) != NULL) {
if(*cur_method->name &&
memcmp(ciphername, cur_method->name,
@@ -501,7 +503,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
/* None of the available crypt methods were able to decrypt the key */
if(method == NULL) {
if(!method) {
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"No supported cipher found");
goto out;
@@ -518,14 +520,13 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
total_len = keylen + ivlen;
key = LIBSSH2_CALLOC(session, total_len);
if(key == NULL) {
if(!key) {
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Could not alloc key");
goto out;
}
if(strcmp((const char *)kdfname, "bcrypt") == 0 &&
passphrase != NULL) {
if(strcmp((const char *)kdfname, "bcrypt") == 0 && passphrase) {
if((_libssh2_get_string(&kdf_buf, &salt, &salt_len)) ||
(_libssh2_get_u32(&kdf_buf, &rounds) != 0) ) {
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
@@ -555,14 +556,14 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
blocksize = method->blocksize;
key_part = LIBSSH2_CALLOC(session, keylen);
if(key_part == NULL) {
if(!key_part) {
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Could not alloc key part");
goto out;
}
iv_part = LIBSSH2_CALLOC(session, ivlen);
if(iv_part == NULL) {
if(!iv_part) {
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Could not alloc iv part");
goto out;
@@ -613,7 +614,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
goto out;
}
if(decrypted_buf != NULL) {
if(decrypted_buf) {
/* copy data to out-going buffer */
struct string_buf *out_buf = _libssh2_string_buf_new(session);
if(!out_buf) {
@@ -624,7 +625,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
}
out_buf->data = LIBSSH2_CALLOC(session, decrypted.len);
if(out_buf->data == NULL) {
if(!out_buf->data) {
ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"decrypted struct");
@@ -745,7 +746,7 @@ _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION * session,
size_t off = 0;
int ret;
if(filedata == NULL || filedata_len <= 0)
if(!filedata || filedata_len <= 0)
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Error parsing PEM: filedata missing");

View File

@@ -911,8 +911,8 @@ session_free(LIBSSH2_SESSION *session)
}
if(session->free_state == libssh2_NB_state_created) {
/* !checksrc! disable EQUALSNULL 1 */
while((ch = _libssh2_list_first(&session->channels)) != NULL) {
rc = _libssh2_channel_free(ch);
if(rc == LIBSSH2_ERROR_EAGAIN)
return rc;
@@ -922,6 +922,7 @@ session_free(LIBSSH2_SESSION *session)
}
if(session->free_state == libssh2_NB_state_sent) {
/* !checksrc! disable EQUALSNULL 1 */
while((l = _libssh2_list_first(&session->listeners)) != NULL) {
rc = _libssh2_channel_forward_cancel(l);
if(rc == LIBSSH2_ERROR_EAGAIN)
@@ -1108,6 +1109,7 @@ session_free(LIBSSH2_SESSION *session)
}
/* Cleanup all remaining packets */
/* !checksrc! disable EQUALSNULL 1 */
while((pkg = _libssh2_list_first(&session->packets)) != NULL) {
packets_left++;
_libssh2_debug((session, LIBSSH2_TRACE_TRANS,
@@ -1901,10 +1903,10 @@ LIBSSH2_API const char *
libssh2_session_banner_get(LIBSSH2_SESSION *session)
{
/* to avoid a coredump when session is NULL */
if(NULL == session)
if(!session)
return NULL;
if(NULL == session->remote.banner)
if(!session->remote.banner)
return NULL;
return (const char *) session->remote.banner;

View File

@@ -508,7 +508,7 @@ sftp_packet_require(LIBSSH2_SFTP *sftp, unsigned char packet_type,
LIBSSH2_SESSION *session = sftp->channel->session;
int rc;
if(data == NULL || data_len == NULL || required_size == 0) {
if(!data || !data_len || required_size == 0) {
return LIBSSH2_ERROR_BAD_USE;
}
@@ -562,7 +562,7 @@ sftp_packet_requirev(LIBSSH2_SFTP *sftp, int num_valid_responses,
int i;
int rc;
if(data == NULL || data_len == NULL || required_size == 0) {
if(!data || !data_len || required_size == 0) {
return LIBSSH2_ERROR_BAD_USE;
}
@@ -785,7 +785,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
* including *EAGAIN).
*/
assert(session->sftpInit_sftp == NULL);
assert(!session->sftpInit_sftp);
session->sftpInit_sftp = NULL;
session->sftpInit_state = libssh2_NB_state_created;
}

View File

@@ -202,7 +202,7 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ )
/* Check for and deal with decompression */
compressed =
session->local.comp != NULL &&
session->local.comp &&
session->local.comp->compress &&
((session->state & LIBSSH2_STATE_AUTHENTICATED) ||
session->local.comp->use_in_auth);
@@ -772,7 +772,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
encrypted = (session->state & LIBSSH2_STATE_NEWKEYS) ? 1 : 0;
compressed =
session->local.comp != NULL &&
session->local.comp &&
session->local.comp->compress &&
((session->state & LIBSSH2_STATE_AUTHENTICATED) ||
session->local.comp->use_in_auth);

View File

@@ -252,7 +252,7 @@ libssh2_userauth_list(LIBSSH2_SESSION * session, const char *user,
LIBSSH2_API int
libssh2_userauth_banner(LIBSSH2_SESSION *session, char **banner)
{
if(NULL == session)
if(!session)
return LIBSSH2_ERROR_MISSING_USERAUTH_BANNER;
if(!session->userauth_banner) {
@@ -261,7 +261,7 @@ libssh2_userauth_banner(LIBSSH2_SESSION *session, char **banner)
"Missing userauth banner");
}
if(banner != NULL)
if(banner)
*banner = session->userauth_banner;
return LIBSSH2_ERROR_NONE;
@@ -596,7 +596,7 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
}
sp1 = memchr(pubkey, ' ', pubkey_len);
if(sp1 == NULL) {
if(!sp1) {
LIBSSH2_FREE(session, pubkey);
return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid public key data");
@@ -605,7 +605,7 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
sp1++;
sp2 = memchr(sp1, ' ', pubkey_len - (sp1 - pubkey));
if(sp2 == NULL) {
if(!sp2) {
/* Assume that the id string is missing, but that it's okay */
sp2 = pubkey + pubkey_len;
}
@@ -700,7 +700,7 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
}
sp1 = memchr(pubkey, ' ', pubkey_len);
if(sp1 == NULL) {
if(!sp1) {
LIBSSH2_FREE(session, pubkey);
return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid public key data");
@@ -710,7 +710,7 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
sp_len = sp1 > pubkey ? (sp1 - pubkey) : 0;
sp2 = memchr(sp1, ' ', pubkey_len - sp_len);
if(sp2 == NULL) {
if(!sp2) {
/* Assume that the id string is missing, but that it's okay */
sp2 = pubkey + pubkey_len;
}
@@ -979,7 +979,7 @@ libssh2_sign_sk(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len,
LIBSSH2_FREE(session, sig_info.sig_r);
if(sig_info.sig_s != NULL) {
if(sig_info.sig_s) {
LIBSSH2_FREE(session, sig_info.sig_s);
}
}
@@ -1305,7 +1305,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session,
*key_method,
*key_method_len);
if(supported_algs == NULL || session->server_sign_algorithms == NULL) {
if(!supported_algs || !session->server_sign_algorithms) {
/* no upgrading key algorithm supported, do nothing */
return LIBSSH2_ERROR_NONE;
}
@@ -1383,7 +1383,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session,
s = p ? (p + 1) : NULL;
}
if(match != NULL) {
if(match) {
if(*key_method)
LIBSSH2_FREE(session, *key_method);
@@ -1923,7 +1923,7 @@ libssh2_userauth_publickey_frommemory(LIBSSH2_SESSION *session,
{
int rc;
if(NULL == passphrase)
if(!passphrase)
/* if given a NULL pointer, make it point to a zero-length
string to save us from having to check this all over */
passphrase = "";
@@ -1951,7 +1951,7 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
{
int rc;
if(NULL == passphrase)
if(!passphrase)
/* if given a NULL pointer, make it point to a zero-length
string to save us from having to check this all over */
passphrase = "";

View File

@@ -430,7 +430,7 @@ int start_openssh_fixture(void)
}
#endif
have_docker = (getenv("OPENSSH_NO_DOCKER") == NULL);
have_docker = !getenv("OPENSSH_NO_DOCKER");
ret = build_openssh_server_docker_image();
if(!ret) {

View File

@@ -33,10 +33,12 @@ int test(LIBSSH2_SESSION *session)
}
channel = libssh2_channel_open_session(session);
/* if(channel == NULL) { */
/* printf("Error opening channel\n"); */
/* return 1; */
/* } */
#if 0
if(!channel) {
printf("Error opening channel\n");
return 1;
}
#endif
rc = libssh2_channel_request_auth_agent(channel);
if(rc) {