diff --git a/Makefile.am b/Makefile.am index b0f696ac..677be76a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -84,7 +84,6 @@ checksrc: -ASNPRINTF \ -ACOPYRIGHT \ -AFOPENMODE \ - -AEQUALSNULL \ -ATYPEDEFSTRUCT \ -Wsrc/libssh2_config.h src/*.[ch] include/*.h example/*.c \ tests/*.[ch] diff --git a/ci/checksrc.sh b/ci/checksrc.sh index a1cdb035..13a57ffe 100755 --- a/ci/checksrc.sh +++ b/ci/checksrc.sh @@ -9,6 +9,5 @@ perl ./ci/checksrc.pl -i4 -m79 \ -ASNPRINTF \ -ACOPYRIGHT \ -AFOPENMODE \ - -AEQUALSNULL \ -ATYPEDEFSTRUCT \ $WHITELIST $FILES diff --git a/src/agent.c b/src/agent.c index 9ad68a04..de22112f 100644 --- a/src/agent.c +++ b/src/agent.c @@ -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); diff --git a/src/agent_win.c b/src/agent_win.c index db500ec1..323ed6ba 100644 --- a/src/agent_win.c +++ b/src/agent_win.c @@ -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); diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index 2b84c707..c9e6acb0 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -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; diff --git a/src/channel.c b/src/channel.c index ff5c17e5..4573556e 100644 --- a/src/channel.c +++ b/src/channel.c @@ -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) { diff --git a/src/comp.c b/src/comp.c index 81ca89bf..cd1146e4 100644 --- a/src/comp.c +++ b/src/comp.c @@ -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"); diff --git a/src/hostkey.c b/src/hostkey.c index 5e973cab..5384593f 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -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; diff --git a/src/kex.c b/src/kex.c index 10171b0c..2b12fdfb 100644 --- a/src/kex.c +++ b/src/kex.c @@ -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; diff --git a/src/mbedtls.c b/src/mbedtls.c index d857358a..b6e1ba0f 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -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) diff --git a/src/misc.c b/src/misc.c index c9706573..74c7573f 100644 --- a/src/misc.c +++ b/src/misc.c @@ -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); diff --git a/src/openssl.c b/src/openssl.c index 60076d3b..af5fa6c1 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -187,7 +187,7 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, int ret; int nid_type; unsigned char *hash = malloc(hash_len); - if(hash == NULL) + if(!hash) return -1; if(hash_len == SHA_DIGEST_LENGTH) { @@ -352,7 +352,7 @@ _libssh2_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) @@ -400,10 +400,10 @@ _libssh2_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx ** ec_ctx, ret = EC_POINT_oct2point(ec_group, point, k, k_len, NULL); ret = EC_KEY_set_public_key(ec_key, point); - if(point != NULL) + if(point) EC_POINT_free(point); - if(ec_ctx != NULL) + if(ec_ctx) *ec_ctx = ec_key; } @@ -655,7 +655,7 @@ gen_publickey_from_rsa(LIBSSH2_SESSION *session, RSA *rsa, len = 4 + 7 + 4 + e_bytes + 4 + n_bytes; key = LIBSSH2_ALLOC(session, len); - if(key == NULL) { + if(!key) { return NULL; } @@ -692,18 +692,18 @@ gen_publickey_from_rsa_evp(LIBSSH2_SESSION *session, "Computing public key from RSA private key envelope")); rsa = EVP_PKEY_get1_RSA(pk); - if(rsa == NULL) { + if(!rsa) { /* Assume memory allocation error... what else could it be ? */ goto __alloc_error; } method_buf = LIBSSH2_ALLOC(session, 7); /* ssh-rsa. */ - if(method_buf == NULL) { + if(!method_buf) { goto __alloc_error; } key = gen_publickey_from_rsa(session, rsa, &key_len); - if(key == NULL) { + if(!key) { goto __alloc_error; } RSA_free(rsa); @@ -716,10 +716,10 @@ gen_publickey_from_rsa_evp(LIBSSH2_SESSION *session, return 0; __alloc_error: - if(rsa != NULL) { + if(rsa) { RSA_free(rsa); } - if(method_buf != NULL) { + if(method_buf) { LIBSSH2_FREE(session, method_buf); } @@ -749,23 +749,23 @@ static int _libssh2_rsa_new_additional_parameters(RSA *rsa) #endif ctx = BN_CTX_new(); - if(ctx == NULL) + if(!ctx) return -1; aux = BN_new(); - if(aux == NULL) { + if(!aux) { rc = -1; goto out; } dmp1 = BN_new(); - if(dmp1 == NULL) { + if(!dmp1) { rc = -1; goto out; } dmq1 = BN_new(); - if(dmq1 == NULL) { + if(!dmq1) { rc = -1; goto out; } @@ -877,10 +877,10 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session, goto fail; } - if(rsa != NULL) + if(rsa) rc = _libssh2_rsa_new_additional_parameters(rsa); - if(rsa != NULL && pubkeydata != NULL && method != NULL) { + if(rsa && pubkeydata && method) { EVP_PKEY *pk = EVP_PKEY_new(); EVP_PKEY_set1_RSA(pk, rsa); @@ -892,7 +892,7 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session, EVP_PKEY_free(pk); } - if(rsa_ctx != NULL) + if(rsa_ctx) *rsa_ctx = rsa; else RSA_free(rsa); @@ -901,7 +901,7 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session, fail: - if(rsa != NULL) + if(rsa) RSA_free(rsa); return _libssh2_error(session, @@ -920,7 +920,7 @@ _libssh2_rsa_new_openssh_private(libssh2_rsa_ctx ** rsa, unsigned char *buf = NULL; struct string_buf *decrypted = NULL; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -944,7 +944,7 @@ _libssh2_rsa_new_openssh_private(libssh2_rsa_ctx ** rsa, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -1048,7 +1048,7 @@ gen_publickey_from_dsa(LIBSSH2_SESSION* session, DSA *dsa, len = 4 + 7 + 4 + p_bytes + 4 + q_bytes + 4 + g_bytes + 4 + k_bytes; key = LIBSSH2_ALLOC(session, len); - if(key == NULL) { + if(!key) { return NULL; } @@ -1087,18 +1087,18 @@ gen_publickey_from_dsa_evp(LIBSSH2_SESSION *session, "Computing public key from DSA private key envelope")); dsa = EVP_PKEY_get1_DSA(pk); - if(dsa == NULL) { + if(!dsa) { /* Assume memory allocation error... what else could it be ? */ goto __alloc_error; } method_buf = LIBSSH2_ALLOC(session, 7); /* ssh-dss. */ - if(method_buf == NULL) { + if(!method_buf) { goto __alloc_error; } key = gen_publickey_from_dsa(session, dsa, &key_len); - if(key == NULL) { + if(!key) { goto __alloc_error; } DSA_free(dsa); @@ -1111,10 +1111,10 @@ gen_publickey_from_dsa_evp(LIBSSH2_SESSION *session, return 0; __alloc_error: - if(dsa != NULL) { + if(dsa) { DSA_free(dsa); } - if(method_buf != NULL) { + if(method_buf) { LIBSSH2_FREE(session, method_buf); } @@ -1184,7 +1184,7 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session, goto fail; } - if(dsa != NULL && pubkeydata != NULL && method != NULL) { + if(dsa && pubkeydata && method) { EVP_PKEY *pk = EVP_PKEY_new(); EVP_PKEY_set1_DSA(pk, dsa); @@ -1196,7 +1196,7 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session, EVP_PKEY_free(pk); } - if(dsa_ctx != NULL) + if(dsa_ctx) *dsa_ctx = dsa; else DSA_free(dsa); @@ -1205,7 +1205,7 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session, fail: - if(dsa != NULL) + if(dsa) DSA_free(dsa); return _libssh2_error(session, @@ -1224,7 +1224,7 @@ _libssh2_dsa_new_openssh_private(libssh2_dsa_ctx ** dsa, unsigned char *buf = NULL; struct string_buf *decrypted = NULL; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -1248,7 +1248,7 @@ _libssh2_dsa_new_openssh_private(libssh2_dsa_ctx ** dsa, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -1366,7 +1366,7 @@ _libssh2_curve25519_new(LIBSSH2_SESSION *session, int rc = -1; pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_X25519, NULL); - if(pctx == NULL) + if(!pctx) return -1; if(EVP_PKEY_keygen_init(pctx) != 1 || @@ -1374,10 +1374,10 @@ _libssh2_curve25519_new(LIBSSH2_SESSION *session, goto cleanExit; } - if(out_private_key != NULL) { + if(out_private_key) { privLen = LIBSSH2_ED25519_KEY_LEN; priv = LIBSSH2_ALLOC(session, privLen); - if(priv == NULL) + if(!priv) goto cleanExit; if(EVP_PKEY_get_raw_private_key(key, priv, &privLen) != 1 || @@ -1389,10 +1389,10 @@ _libssh2_curve25519_new(LIBSSH2_SESSION *session, priv = NULL; } - if(out_public_key != NULL) { + if(out_public_key) { pubLen = LIBSSH2_ED25519_KEY_LEN; pub = LIBSSH2_ALLOC(session, pubLen); - if(pub == NULL) + if(!pub) goto cleanExit; if(EVP_PKEY_get_raw_public_key(key, pub, &pubLen) != 1 || @@ -1539,7 +1539,7 @@ gen_publickey_from_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, if(tmp_len > 0) { unsigned char *comment = LIBSSH2_CALLOC(session, tmp_len + 1); - if(comment != NULL) { + if(comment) { memcpy(comment, buf, tmp_len); memcpy(comment + tmp_len, "\0", 1); @@ -1570,7 +1570,7 @@ gen_publickey_from_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, "private key envelope")); method_buf = LIBSSH2_ALLOC(session, 11); /* ssh-ed25519. */ - if(method_buf == NULL) { + if(!method_buf) { _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for ED25519 key"); goto clean_exit; @@ -1580,7 +1580,7 @@ gen_publickey_from_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, pub_key(32). */ key_len = LIBSSH2_ED25519_KEY_LEN + 19; key = LIBSSH2_CALLOC(session, key_len); - if(key == NULL) { + if(!key) { _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for ED25519 key"); goto clean_exit; @@ -1593,25 +1593,25 @@ gen_publickey_from_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, memcpy(method_buf, "ssh-ed25519", 11); - if(method != NULL) + if(method) *method = method_buf; else LIBSSH2_FREE(session, method_buf); - if(method_len != NULL) + if(method_len) *method_len = 11; - if(pubkeydata != NULL) + if(pubkeydata) *pubkeydata = key; else LIBSSH2_FREE(session, key); - if(pubkeydata_len != NULL) + if(pubkeydata_len) *pubkeydata_len = key_len; - if(out_ctx != NULL) + if(out_ctx) *out_ctx = ctx; - else if(ctx != NULL) + else if(ctx) _libssh2_ed25519_free(ctx); return 0; @@ -1671,13 +1671,13 @@ gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, return -1; } - if(flags != NULL && _libssh2_get_byte(decrypted, flags)) { + if(flags && _libssh2_get_byte(decrypted, flags)) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "No SK flags."); return -1; } - if(key_handle != NULL && handle_len != NULL) { + if(key_handle && handle_len) { unsigned char *handle = NULL; if(_libssh2_get_string(decrypted, &handle, handle_len)) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, @@ -1706,7 +1706,7 @@ gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, /* sk-ssh-ed25519@openssh.com. */ method_buf = LIBSSH2_ALLOC(session, strlen(key_type)); - if(method_buf == NULL) { + if(!method_buf) { _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for ED25519 key"); goto clean_exit; @@ -1716,7 +1716,7 @@ gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, pub_key(32) + application_len(4) + application(X). */ key_len = LIBSSH2_ED25519_KEY_LEN + 38 + app_len; key = LIBSSH2_CALLOC(session, key_len); - if(key == NULL) { + if(!key) { _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for ED25519 key"); goto clean_exit; @@ -1728,7 +1728,7 @@ gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, _libssh2_store_str(&p, (const char *)pub_key, LIBSSH2_ED25519_KEY_LEN); _libssh2_store_str(&p, (const char *)app, app_len); - if(application != NULL && app_len > 0) { + if(application && app_len > 0) { *application = (const char *)LIBSSH2_ALLOC(session, app_len + 1); _libssh2_explicit_zero((void *)*application, app_len + 1); memcpy((void *)*application, app, app_len); @@ -1736,25 +1736,25 @@ gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, memcpy(method_buf, key_type, strlen(key_type)); - if(method != NULL) + if(method) *method = method_buf; else LIBSSH2_FREE(session, method_buf); - if(method_len != NULL) + if(method_len) *method_len = strlen(key_type); - if(pubkeydata != NULL) + if(pubkeydata) *pubkeydata = key; - else if(key != NULL) + else if(key) LIBSSH2_FREE(session, key); - if(pubkeydata_len != NULL) + if(pubkeydata_len) *pubkeydata_len = key_len; - if(out_ctx != NULL) + if(out_ctx) *out_ctx = ctx; - else if(ctx != NULL) + else if(ctx) _libssh2_ed25519_free(ctx); return 0; @@ -1771,12 +1771,12 @@ clean_exit: if(key) LIBSSH2_FREE(session, key); - if(application != NULL && *application != NULL) { + if(application && *application) { LIBSSH2_FREE(session, (void *)application); *application = NULL; } - if(key_handle != NULL && *key_handle != NULL) { + if(key_handle && *key_handle) { LIBSSH2_FREE(session, (void *)key_handle); *key_handle = NULL; } @@ -1796,7 +1796,7 @@ _libssh2_ed25519_new_private(libssh2_ed25519_ctx ** ed_ctx, struct string_buf *decrypted = NULL; libssh2_ed25519_ctx *ctx = NULL; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -1820,7 +1820,7 @@ _libssh2_ed25519_new_private(libssh2_ed25519_ctx ** ed_ctx, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -1843,9 +1843,9 @@ _libssh2_ed25519_new_private(libssh2_ed25519_ctx ** ed_ctx, _libssh2_string_buf_free(session, decrypted); if(rc == 0) { - if(ed_ctx != NULL) + if(ed_ctx) *ed_ctx = ctx; - else if(ctx != NULL) + else if(ctx) _libssh2_ed25519_free(ctx); } @@ -1868,7 +1868,7 @@ _libssh2_ed25519_new_private_sk(libssh2_ed25519_ctx **ed_ctx, struct string_buf *decrypted = NULL; libssh2_ed25519_ctx *ctx = NULL; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -1892,7 +1892,7 @@ _libssh2_ed25519_new_private_sk(libssh2_ed25519_ctx **ed_ctx, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -1919,9 +1919,9 @@ _libssh2_ed25519_new_private_sk(libssh2_ed25519_ctx **ed_ctx, _libssh2_string_buf_free(session, decrypted); if(rc == 0) { - if(ed_ctx != NULL) + if(ed_ctx) *ed_ctx = ctx; - else if(ctx != NULL) + else if(ctx) _libssh2_ed25519_free(ctx); } @@ -1996,7 +1996,7 @@ _libssh2_ed25519_new_public(libssh2_ed25519_ctx ** ed_ctx, { libssh2_ed25519_ctx *ctx = NULL; - if(ed_ctx == NULL) + if(!ed_ctx) return -1; ctx = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519, NULL, @@ -2005,7 +2005,7 @@ _libssh2_ed25519_new_public(libssh2_ed25519_ctx ** ed_ctx, return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "could not create ED25519 public key"); - if(ed_ctx != NULL) + if(ed_ctx) *ed_ctx = ctx; else if(ctx) _libssh2_ed25519_free(ctx); @@ -2133,7 +2133,7 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx, unsigned char *out_buffer = NULL; ECDSA_SIG *sig = ECDSA_do_sign(hash, (int) hash_len, ec_ctx); - if(sig == NULL) + if(!sig) return -1; #ifdef HAVE_OPAQUE_STRUCTS ECDSA_SIG_get0(sig, &pr, &ps); @@ -2146,7 +2146,7 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx, s_len = BN_num_bytes(ps) + 1; temp_buffer = malloc(r_len + s_len + 8); - if(temp_buffer == NULL) { + if(!temp_buffer) { rc = -1; goto clean_exit; } @@ -2158,7 +2158,7 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx, out_buffer_len = (size_t)(sp - temp_buffer); out_buffer = LIBSSH2_CALLOC(session, out_buffer_len); - if(out_buffer == NULL) { + if(!out_buffer) { rc = -1; goto clean_exit; } @@ -2170,7 +2170,7 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx, clean_exit: - if(temp_buffer != NULL) + if(temp_buffer) free(temp_buffer); if(sig) @@ -2186,7 +2186,7 @@ _libssh2_sha1_init(libssh2_sha1_ctx *ctx) #ifdef HAVE_OPAQUE_STRUCTS *ctx = EVP_MD_CTX_new(); - if(*ctx == NULL) + if(!*ctx) return 0; if(EVP_DigestInit(*ctx, EVP_get_digestbyname("sha1"))) @@ -2209,7 +2209,7 @@ _libssh2_sha1(const unsigned char *message, size_t len, #ifdef HAVE_OPAQUE_STRUCTS EVP_MD_CTX * ctx = EVP_MD_CTX_new(); - if(ctx == NULL) + if(!ctx) return 1; /* error */ if(EVP_DigestInit(ctx, EVP_get_digestbyname("sha1"))) { @@ -2238,7 +2238,7 @@ _libssh2_sha256_init(libssh2_sha256_ctx *ctx) #ifdef HAVE_OPAQUE_STRUCTS *ctx = EVP_MD_CTX_new(); - if(*ctx == NULL) + if(!*ctx) return 0; if(EVP_DigestInit(*ctx, EVP_get_digestbyname("sha256"))) @@ -2261,7 +2261,7 @@ _libssh2_sha256(const unsigned char *message, size_t len, #ifdef HAVE_OPAQUE_STRUCTS EVP_MD_CTX * ctx = EVP_MD_CTX_new(); - if(ctx == NULL) + if(!ctx) return 1; /* error */ if(EVP_DigestInit(ctx, EVP_get_digestbyname("sha256"))) { @@ -2290,7 +2290,7 @@ _libssh2_sha384_init(libssh2_sha384_ctx *ctx) #ifdef HAVE_OPAQUE_STRUCTS *ctx = EVP_MD_CTX_new(); - if(*ctx == NULL) + if(!*ctx) return 0; if(EVP_DigestInit(*ctx, EVP_get_digestbyname("sha384"))) @@ -2313,7 +2313,7 @@ _libssh2_sha384(const unsigned char *message, size_t len, #ifdef HAVE_OPAQUE_STRUCTS EVP_MD_CTX * ctx = EVP_MD_CTX_new(); - if(ctx == NULL) + if(!ctx) return 1; /* error */ if(EVP_DigestInit(ctx, EVP_get_digestbyname("sha384"))) { @@ -2342,7 +2342,7 @@ _libssh2_sha512_init(libssh2_sha512_ctx *ctx) #ifdef HAVE_OPAQUE_STRUCTS *ctx = EVP_MD_CTX_new(); - if(*ctx == NULL) + if(!*ctx) return 0; if(EVP_DigestInit(*ctx, EVP_get_digestbyname("sha512"))) @@ -2365,7 +2365,7 @@ _libssh2_sha512(const unsigned char *message, size_t len, #ifdef HAVE_OPAQUE_STRUCTS EVP_MD_CTX * ctx = EVP_MD_CTX_new(); - if(ctx == NULL) + if(!ctx) return 1; /* error */ if(EVP_DigestInit(ctx, EVP_get_digestbyname("sha512"))) { @@ -2407,7 +2407,7 @@ _libssh2_md5_init(libssh2_md5_ctx *ctx) #ifdef HAVE_OPAQUE_STRUCTS *ctx = EVP_MD_CTX_new(); - if(*ctx == NULL) + if(!*ctx) return 0; if(EVP_DigestInit(*ctx, EVP_get_digestbyname("md5"))) @@ -2452,11 +2452,11 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, "Computing public key from EC private key envelope")); bn_ctx = BN_CTX_new(); - if(bn_ctx == NULL) + if(!bn_ctx) return -1; ec = EVP_PKEY_get1_EC_KEY(pk); - if(ec == NULL) { + if(!ec) { rc = -1; goto clean_exit; } @@ -2471,7 +2471,7 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, *method_len = 19; method_buf = LIBSSH2_ALLOC(session, *method_len); - if(method_buf == NULL) { + if(!method_buf) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "out of memory"); } @@ -2502,7 +2502,7 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, } octal_value = malloc(octal_len); - if(octal_value == NULL) { + if(!octal_value) { rc = -1; goto clean_exit; } @@ -2518,7 +2518,7 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, + pub_key_len(4) + pub_key(~65). */ key_len = 4 + *method_len + 4 + 8 + 4 + octal_len; key = LIBSSH2_ALLOC(session, key_len); - if(key == NULL) { + if(!key) { rc = -1; goto clean_exit; } @@ -2546,20 +2546,20 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, clean_exit: - if(ec != NULL) + if(ec) EC_KEY_free(ec); - if(bn_ctx != NULL) { + if(bn_ctx) { BN_CTX_free(bn_ctx); } - if(octal_value != NULL) + if(octal_value) free(octal_value); if(rc == 0) return 0; - if(method_buf != NULL) + if(method_buf) LIBSSH2_FREE(session, method_buf); return -1; @@ -2615,7 +2615,7 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, } bn_exponent = BN_new(); - if(bn_exponent == NULL) { + if(!bn_exponent) { rc = -1; _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for private key data"); @@ -2625,7 +2625,7 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, BN_bin2bn(exponent, (int) exponentlen, bn_exponent); rc = (EC_KEY_set_private_key(ec_key, bn_exponent) != 1); - if(rc == 0 && ec_key != NULL && pubkeydata != NULL && method != NULL) { + if(rc == 0 && ec_key && pubkeydata && method) { EVP_PKEY *pk = EVP_PKEY_new(); EVP_PKEY_set1_EC_KEY(pk, ec_key); @@ -2637,7 +2637,7 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, EVP_PKEY_free(pk); } - if(ec_ctx != NULL) + if(ec_ctx) *ec_ctx = ec_key; else EC_KEY_free(ec_key); @@ -2645,7 +2645,7 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, return rc; fail: - if(ec_key != NULL) + if(ec_key) EC_KEY_free(ec_key); return rc; @@ -2702,13 +2702,13 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, goto fail; } - if(flags != NULL && _libssh2_get_byte(decrypted, flags)) { + if(flags && _libssh2_get_byte(decrypted, flags)) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "No SK flags."); goto fail; } - if(key_handle != NULL && handle_len != NULL) { + if(key_handle && handle_len) { unsigned char *handle = NULL; if(_libssh2_get_string(decrypted, &handle, handle_len)) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, @@ -2725,7 +2725,7 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, } } - if(rc == 0 && ec_key != NULL && pubkeydata != NULL && method != NULL) { + if(rc == 0 && ec_key && pubkeydata && method) { EVP_PKEY *pk = EVP_PKEY_new(); EVP_PKEY_set1_EC_KEY(pk, ec_key); @@ -2737,11 +2737,11 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, EVP_PKEY_free(pk); } - if(rc == 0 && pubkeydata != NULL) { + if(rc == 0 && pubkeydata) { key_len = *pubkeydata_len + app_len + 4; key = LIBSSH2_ALLOC(session, key_len); - if(key == NULL) { + if(!key) { rc = -1; goto fail; } @@ -2751,7 +2751,7 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, memcpy(key, *pubkeydata, *pubkeydata_len); _libssh2_store_str(&p, (const char *)app, app_len); - if(application != NULL && app_len > 0) { + if(application && app_len > 0) { *application = (const char *)LIBSSH2_ALLOC(session, app_len + 1); _libssh2_explicit_zero((void *)*application, app_len + 1); memcpy((void *)*application, app, app_len); @@ -2760,13 +2760,13 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, LIBSSH2_FREE(session, *pubkeydata); *pubkeydata_len = key_len; - if(pubkeydata != NULL) + if(pubkeydata) *pubkeydata = key; - else if(key != NULL) + else if(key) LIBSSH2_FREE(session, key); } - if(ec_ctx != NULL) + if(ec_ctx) *ec_ctx = ec_key; else EC_KEY_free(ec_key); @@ -2774,15 +2774,15 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, return rc; fail: - if(ec_key != NULL) + if(ec_key) EC_KEY_free(ec_key); - if(application != NULL && *application != NULL) { + if(application && *application) { LIBSSH2_FREE(session, (void *)application); *application = NULL; } - if(key_handle != NULL && *key_handle != NULL) { + if(key_handle && *key_handle) { LIBSSH2_FREE(session, (void *)key_handle); *key_handle = NULL; } @@ -2803,7 +2803,7 @@ _libssh2_ecdsa_new_openssh_private(libssh2_ecdsa_ctx ** ec_ctx, libssh2_curve_type type; struct string_buf *decrypted = NULL; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -2827,7 +2827,7 @@ _libssh2_ecdsa_new_openssh_private(libssh2_ecdsa_ctx ** ec_ctx, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -2865,7 +2865,7 @@ _libssh2_ecdsa_new_openssh_private_sk(libssh2_ecdsa_ctx ** ec_ctx, unsigned char *buf = NULL; struct string_buf *decrypted = NULL; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -2889,7 +2889,7 @@ _libssh2_ecdsa_new_openssh_private_sk(libssh2_ecdsa_ctx ** ec_ctx, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -3021,12 +3021,12 @@ _libssh2_ecdsa_create_key(LIBSSH2_SESSION *session, goto clean_exit; } - if(out_private_key != NULL) + if(out_private_key) *out_private_key = private_key; if(out_public_key_octal) { *out_public_key_octal = LIBSSH2_ALLOC(session, octal_len); - if(*out_public_key_octal == NULL) { + if(!*out_public_key_octal) { ret = -1; goto clean_exit; } @@ -3034,7 +3034,7 @@ _libssh2_ecdsa_create_key(LIBSSH2_SESSION *session, memcpy(*out_public_key_octal, octal_value, octal_len); } - if(out_public_key_octal_len != NULL) + if(out_public_key_octal_len) *out_public_key_octal_len = octal_len; clean_exit: @@ -3067,13 +3067,13 @@ _libssh2_ecdh_gen_k(_libssh2_bn **k, _libssh2_ec_key *private_key, if(!bn_ctx) return -1; - if(k == NULL) + if(!k) return -1; private_key_group = EC_KEY_get0_group(private_key); server_public_key_point = EC_POINT_new(private_key_group); - if(server_public_key_point == NULL) + if(!server_public_key_point) return -1; rc = EC_POINT_oct2point(private_key_group, server_public_key_point, @@ -3102,13 +3102,13 @@ _libssh2_ecdh_gen_k(_libssh2_bn **k, _libssh2_ec_key *private_key, clean_exit: - if(server_public_key_point != NULL) + if(server_public_key_point) EC_POINT_free(server_public_key_point); - if(bn_ctx != NULL) + if(bn_ctx) BN_CTX_free(bn_ctx); - if(secret != NULL) + if(secret) free(secret); return ret; @@ -3129,7 +3129,7 @@ _libssh2_ed25519_sign(libssh2_ed25519_ctx *ctx, LIBSSH2_SESSION *session, size_t sig_len = 0; unsigned char *sig = NULL; - if(md_ctx != NULL) { + if(md_ctx) { if(EVP_DigestSignInit(md_ctx, NULL, NULL, NULL, ctx) != 1) goto clean_exit; if(EVP_DigestSign(md_ctx, NULL, &sig_len, message, message_len) != 1) @@ -3139,7 +3139,7 @@ _libssh2_ed25519_sign(libssh2_ed25519_ctx *ctx, LIBSSH2_SESSION *session, goto clean_exit; sig = LIBSSH2_CALLOC(session, sig_len); - if(sig == NULL) + if(!sig) goto clean_exit; rc = EVP_DigestSign(md_ctx, sig, &sig_len, message, message_len); @@ -3175,11 +3175,11 @@ _libssh2_curve25519_gen_k(_libssh2_bn **k, BN_CTX *bn_ctx = NULL; size_t out_len = 0; - if(k == NULL || *k == NULL) + if(!k || !*k) return -1; bn_ctx = BN_CTX_new(); - if(bn_ctx == NULL) + if(!bn_ctx) return -1; peer_key = EVP_PKEY_new_raw_public_key(EVP_PKEY_X25519, NULL, @@ -3190,12 +3190,12 @@ _libssh2_curve25519_gen_k(_libssh2_bn **k, private_key, LIBSSH2_ED25519_KEY_LEN); - if(peer_key == NULL || server_key == NULL) { + if(!peer_key || !server_key) { goto cleanExit; } server_key_ctx = EVP_PKEY_CTX_new(server_key, NULL); - if(server_key_ctx == NULL) { + if(!server_key_ctx) { goto cleanExit; } @@ -3236,7 +3236,7 @@ cleanExit: EVP_PKEY_free(peer_key); if(server_key) EVP_PKEY_free(server_key); - if(bn_ctx != NULL) + if(bn_ctx) BN_CTX_free(bn_ctx); return (rc == 1) ? 0 : -1; @@ -3250,7 +3250,7 @@ _libssh2_ed25519_verify(libssh2_ed25519_ctx *ctx, const uint8_t *s, int ret = -1; EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); - if(NULL == md_ctx) + if(!md_ctx) return -1; ret = EVP_DigestVerifyInit(md_ctx, NULL, NULL, NULL, ctx); @@ -3282,7 +3282,7 @@ _libssh2_pub_priv_openssh_keyfile(LIBSSH2_SESSION *session, struct string_buf *decrypted = NULL; int rc = 0; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -3309,7 +3309,7 @@ _libssh2_pub_priv_openssh_keyfile(LIBSSH2_SESSION *session, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -3392,7 +3392,7 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, privatekey)); bp = BIO_new_file(privatekey, "r"); - if(bp == NULL) { + if(!bp) { return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Unable to extract public key from private key " @@ -3403,7 +3403,7 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase); BIO_free(bp); - if(pk == NULL) { + if(!pk) { /* Try OpenSSH format */ rc = _libssh2_pub_priv_openssh_keyfile(session, @@ -3484,14 +3484,14 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, unsigned char *buf = NULL; struct string_buf *decrypted = NULL; - if(key_ctx != NULL) + if(key_ctx) *key_ctx = NULL; - if(session == NULL) + if(!session) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); - if(key_type != NULL && (strlen(key_type) > 11 || strlen(key_type) < 7)) + if(key_type && (strlen(key_type) > 11 || strlen(key_type) < 7)) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "type is invalid"); @@ -3507,7 +3507,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) + if(rc || !buf) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted " "key data not found"); @@ -3516,7 +3516,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, #if LIBSSH2_ED25519 if(strcmp("ssh-ed25519", (const char *)buf) == 0) { - if(key_type == NULL || strcmp("ssh-ed25519", key_type) == 0) { + if(!key_type || strcmp("ssh-ed25519", key_type) == 0) { rc = gen_publickey_from_ed25519_openssh_priv_data(session, decrypted, method, @@ -3528,7 +3528,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, } if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) { - if(key_type == NULL || + if(!key_type || strcmp("sk-ssh-ed25519@openssh.com", key_type) == 0) { rc = gen_publickey_from_sk_ed25519_openssh_priv_data(session, decrypted, @@ -3546,7 +3546,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, #endif #if LIBSSH2_RSA if(strcmp("ssh-rsa", (const char *)buf) == 0) { - if(key_type == NULL || strcmp("ssh-rsa", key_type) == 0) { + if(!key_type || strcmp("ssh-rsa", key_type) == 0) { rc = gen_publickey_from_rsa_openssh_priv_data(session, decrypted, method, method_len, pubkeydata, @@ -3557,7 +3557,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, #endif #if LIBSSH2_DSA if(strcmp("ssh-dss", (const char *)buf) == 0) { - if(key_type == NULL || strcmp("ssh-dss", key_type) == 0) { + if(!key_type || strcmp("ssh-dss", key_type) == 0) { rc = gen_publickey_from_dsa_openssh_priv_data(session, decrypted, method, method_len, pubkeydata, @@ -3582,7 +3582,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, } else if(_libssh2_ecdsa_curve_type_from_name((const char *)buf, &type) == 0) { - if(key_type == NULL || strcmp("ssh-ecdsa", key_type) == 0) { + if(!key_type || strcmp("ssh-ecdsa", key_type) == 0) { rc = gen_publickey_from_ecdsa_openssh_priv_data(session, type, decrypted, method, method_len, @@ -3626,14 +3626,14 @@ _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, unsigned char *buf = NULL; struct string_buf *decrypted = NULL; - if(key_ctx != NULL) + if(key_ctx) *key_ctx = NULL; - if(session == NULL) + if(!session) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); - if(key_type != NULL && strlen(key_type) < 7) + if(key_type && strlen(key_type) < 7) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "type is invalid"); @@ -3649,7 +3649,7 @@ _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) + if(rc || !buf) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted " "key data not found"); @@ -3659,7 +3659,7 @@ _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, #if LIBSSH2_ED25519 if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) { *algorithm = LIBSSH2_HOSTKEY_TYPE_ED25519; - if(key_type == NULL || + if(!key_type || strcmp("sk-ssh-ed25519@openssh.com", key_type) == 0) { rc = gen_publickey_from_sk_ed25519_openssh_priv_data(session, decrypted, @@ -3748,7 +3748,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase); BIO_free(bp); - if(pk == NULL) { + if(!pk) { /* Try OpenSSH format */ st = _libssh2_pub_priv_openssh_keyfilememory(session, NULL, NULL, method, @@ -3842,7 +3842,7 @@ _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session, pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase); BIO_free(bp); - if(pk == NULL) { + if(!pk) { /* Try OpenSSH format */ st = _libssh2_sk_pub_openssh_keyfilememory(session, NULL, NULL, method, diff --git a/src/packet.c b/src/packet.c index 644386a8..a5e32d17 100644 --- a/src/packet.c +++ b/src/packet.c @@ -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", diff --git a/src/pem.c b/src/pem.c index e4dc1f74..69120e64 100644 --- a/src/pem.c +++ b/src/pem.c @@ -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"); diff --git a/src/session.c b/src/session.c index a37eccef..c5800a36 100644 --- a/src/session.c +++ b/src/session.c @@ -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; diff --git a/src/sftp.c b/src/sftp.c index f098a45a..37367812 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -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; } diff --git a/src/transport.c b/src/transport.c index 14d511e5..f0e99848 100644 --- a/src/transport.c +++ b/src/transport.c @@ -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); diff --git a/src/userauth.c b/src/userauth.c index 80fffb07..274fd0c3 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -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 = ""; diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 7e61bc63..86b5d23d 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -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) { diff --git a/tests/test_agent_forward_succeeds.c b/tests/test_agent_forward_succeeds.c index c82413ee..cb70baee 100644 --- a/tests/test_agent_forward_succeeds.c +++ b/tests/test_agent_forward_succeeds.c @@ -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) {