mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-29 13:01:14 +03:00
@ -84,7 +84,6 @@ checksrc:
|
||||
-ACOPYRIGHT \
|
||||
-AFOPENMODE \
|
||||
-AEQUALSNULL \
|
||||
-ANOTEQUALSZERO \
|
||||
-ATYPEDEFSTRUCT \
|
||||
-Wsrc/libssh2_config.h src/*.[ch] include/*.h example/*.c \
|
||||
tests/*.[ch]
|
||||
|
@ -10,6 +10,5 @@ perl ./ci/checksrc.pl -i4 -m79 \
|
||||
-ACOPYRIGHT \
|
||||
-AFOPENMODE \
|
||||
-AEQUALSNULL \
|
||||
-ANOTEQUALSZERO \
|
||||
-ATYPEDEFSTRUCT \
|
||||
$WHITELIST $FILES
|
||||
|
@ -265,7 +265,7 @@ int main(int argc, char *argv[])
|
||||
fprintf(stderr, "failed to recv()!\n");
|
||||
goto shutdown;
|
||||
}
|
||||
else if(0 == len) {
|
||||
else if(len == 0) {
|
||||
fprintf(stderr, "The client at %s:%d disconnected!\n", shost,
|
||||
sport);
|
||||
goto shutdown;
|
||||
|
@ -262,7 +262,7 @@ int main(int argc, char *argv[])
|
||||
fprintf(stderr, "failed to recv()!\n");
|
||||
goto shutdown;
|
||||
}
|
||||
else if(0 == len) {
|
||||
else if(len == 0) {
|
||||
fprintf(stderr, "The local server at %s:%d disconnected!\n",
|
||||
local_destip, local_destport);
|
||||
goto shutdown;
|
||||
|
22
src/kex.c
22
src/kex.c
@ -1866,7 +1866,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
|
||||
/* Compute the shared secret K */
|
||||
rc = _libssh2_ecdh_gen_k(&exchange_state->k, private_key,
|
||||
server_public_key, server_public_key_len);
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_KEX_FAILURE,
|
||||
"Unable to create ECDH shared secret");
|
||||
goto clean_exit;
|
||||
@ -1909,7 +1909,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
|
||||
break;
|
||||
}
|
||||
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN,
|
||||
"Unable to verify hostkey signature");
|
||||
goto clean_exit;
|
||||
@ -2214,7 +2214,7 @@ kex_method_ecdh_key_exchange
|
||||
if(key_state->state == libssh2_NB_state_created) {
|
||||
rc = kex_session_ecdh_curve_type(session->kex->name, &type);
|
||||
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
ret = _libssh2_error(session, -1,
|
||||
"Unknown KEX nistp curve type");
|
||||
goto ecdh_clean_exit;
|
||||
@ -2224,7 +2224,7 @@ kex_method_ecdh_key_exchange
|
||||
&key_state->public_key_oct,
|
||||
&key_state->public_key_oct_len, type);
|
||||
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
ret = _libssh2_error(session, rc,
|
||||
"Unable to create private key");
|
||||
goto ecdh_clean_exit;
|
||||
@ -2277,7 +2277,7 @@ kex_method_ecdh_key_exchange
|
||||
|
||||
rc = kex_session_ecdh_curve_type(session->kex->name, &type);
|
||||
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
ret = _libssh2_error(session, -1,
|
||||
"Unknown KEX nistp curve type");
|
||||
goto ecdh_clean_exit;
|
||||
@ -2505,7 +2505,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data,
|
||||
/* Compute the shared secret K */
|
||||
rc = _libssh2_curve25519_gen_k(&exchange_state->k, private_key,
|
||||
server_public_key);
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_KEX_FAILURE,
|
||||
"Unable to create ECDH shared secret");
|
||||
goto clean_exit;
|
||||
@ -2536,7 +2536,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data,
|
||||
/*/ verify hash */
|
||||
LIBSSH2_KEX_METHOD_EC_SHA_HASH_CREATE_VERIFY(256);
|
||||
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN,
|
||||
"Unable to verify hostkey signature");
|
||||
goto clean_exit;
|
||||
@ -2827,10 +2827,10 @@ kex_method_curve25519_key_exchange
|
||||
unsigned char *s = NULL;
|
||||
|
||||
rc = strcmp(session->kex->name, "curve25519-sha256@libssh.org");
|
||||
if(rc != 0)
|
||||
if(rc)
|
||||
rc = strcmp(session->kex->name, "curve25519-sha256");
|
||||
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
ret = _libssh2_error(session, -1,
|
||||
"Unknown KEX curve25519 curve type");
|
||||
goto clean_exit;
|
||||
@ -2840,7 +2840,7 @@ kex_method_curve25519_key_exchange
|
||||
&key_state->curve25519_public_key,
|
||||
&key_state->curve25519_private_key);
|
||||
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
ret = _libssh2_error(session, rc,
|
||||
"Unable to create private key");
|
||||
goto clean_exit;
|
||||
@ -4134,7 +4134,7 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
|
||||
}
|
||||
|
||||
/* weird situation, no algorithm found */
|
||||
if(0 == ialg)
|
||||
if(ialg == 0)
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_INVAL,
|
||||
"No algorithm found");
|
||||
|
||||
|
@ -98,12 +98,12 @@ _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa,
|
||||
rc = gcry_sexp_build(&s_hash, NULL,
|
||||
"(data (flags pkcs1) (hash sha1 %b))",
|
||||
SHA_DIGEST_LENGTH, hash);
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = gcry_sexp_build(&s_sig, NULL, "(sig-val(rsa(s %b)))", sig_len, sig);
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
gcry_sexp_release(s_hash);
|
||||
return -1;
|
||||
}
|
||||
@ -200,55 +200,55 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
|
||||
}
|
||||
/* First read Version field (should be 0). */
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &n, &nlen);
|
||||
if(ret != 0 || (nlen != 1 && *n != '\0')) {
|
||||
if(ret || (nlen != 1 && *n != '\0')) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &n, &nlen);
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &e, &elen);
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &d, &dlen);
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &p, &plen);
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &q, &qlen);
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &e1, &e1len);
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &e2, &e2len);
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &coeff, &coefflen);
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
@ -318,42 +318,42 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa,
|
||||
|
||||
/* First read Version field (should be 0). */
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &p, &plen);
|
||||
if(ret != 0 || (plen != 1 && *p != '\0')) {
|
||||
if(ret || (plen != 1 && *p != '\0')) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &p, &plen);
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &q, &qlen);
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &g, &glen);
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &y, &ylen);
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &x, &xlen);
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if(datalen != 0) {
|
||||
if(datalen) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
@ -397,7 +397,7 @@ _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session,
|
||||
|
||||
gcry_sexp_release(data);
|
||||
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -458,7 +458,7 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
|
||||
|
||||
gcry_sexp_release(data);
|
||||
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ _libssh2_mbedtls_init(void)
|
||||
ret = mbedtls_ctr_drbg_seed(&_libssh2_mbedtls_ctr_drbg,
|
||||
mbedtls_entropy_func,
|
||||
&_libssh2_mbedtls_entropy, NULL, 0);
|
||||
if(ret != 0)
|
||||
if(ret)
|
||||
mbedtls_ctr_drbg_free(&_libssh2_mbedtls_ctr_drbg);
|
||||
}
|
||||
|
||||
@ -348,9 +348,9 @@ _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa,
|
||||
|
||||
/* !checksrc! disable ASSIGNWITHINCONDITION 1 */
|
||||
if((ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(E)),
|
||||
edata, elen) ) != 0 ||
|
||||
edata, elen)) ||
|
||||
(ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(N)),
|
||||
ndata, nlen) ) != 0) {
|
||||
ndata, nlen))) {
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
@ -362,18 +362,17 @@ _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa,
|
||||
if(!ret && ddata) {
|
||||
/* !checksrc! disable ASSIGNWITHINCONDITION 1 */
|
||||
if((ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(D)),
|
||||
ddata, dlen) ) != 0 ||
|
||||
ddata, dlen)) ||
|
||||
(ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(P)),
|
||||
pdata, plen) ) != 0 ||
|
||||
pdata, plen)) ||
|
||||
(ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(Q)),
|
||||
qdata, qlen) ) != 0 ||
|
||||
qdata, qlen)) ||
|
||||
(ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(DP)),
|
||||
e1data, e1len) ) != 0 ||
|
||||
e1data, e1len)) ||
|
||||
(ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(DQ)),
|
||||
e2data, e2len) ) != 0 ||
|
||||
e2data, e2len)) ||
|
||||
(ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(QP)),
|
||||
coeffdata, coefflen) )
|
||||
!= 0) {
|
||||
coeffdata, coefflen))) {
|
||||
ret = -1;
|
||||
}
|
||||
ret = mbedtls_rsa_check_privkey(ctx);
|
||||
@ -418,7 +417,7 @@ _libssh2_mbedtls_rsa_new_private(libssh2_rsa_ctx **rsa,
|
||||
#else
|
||||
ret = mbedtls_pk_parse_keyfile(&pkey, filename, (char *)passphrase);
|
||||
#endif
|
||||
if(ret != 0 || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) {
|
||||
if(ret || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) {
|
||||
mbedtls_pk_free(&pkey);
|
||||
mbedtls_rsa_free(*rsa);
|
||||
LIBSSH2_FREE(session, *rsa);
|
||||
@ -476,7 +475,7 @@ _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa,
|
||||
#endif
|
||||
_libssh2_mbedtls_safe_free(filedata_nullterm, filedata_len);
|
||||
|
||||
if(ret != 0 || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) {
|
||||
if(ret || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) {
|
||||
mbedtls_pk_free(&pkey);
|
||||
mbedtls_rsa_free(*rsa);
|
||||
LIBSSH2_FREE(session, *rsa);
|
||||
@ -524,7 +523,7 @@ _libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx,
|
||||
}
|
||||
ret = _libssh2_mbedtls_hash(m, m_len, md_type, hash);
|
||||
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
free(hash);
|
||||
return -1; /* failure */
|
||||
}
|
||||
@ -742,7 +741,7 @@ _libssh2_mbedtls_pub_priv_keyfile(LIBSSH2_SESSION *session,
|
||||
#else
|
||||
ret = mbedtls_pk_parse_keyfile(&pkey, privatekey, passphrase);
|
||||
#endif
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
mbedtls_strerror(ret, (char *)buf, sizeof(buf));
|
||||
mbedtls_pk_free(&pkey);
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_FILE, buf);
|
||||
@ -800,7 +799,7 @@ _libssh2_mbedtls_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
|
||||
#endif
|
||||
_libssh2_mbedtls_safe_free(privatekeydata_nullterm, privatekeydata_len);
|
||||
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
mbedtls_strerror(ret, (char *)buf, sizeof(buf));
|
||||
mbedtls_pk_free(&pkey);
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_FILE, buf);
|
||||
@ -923,7 +922,7 @@ _libssh2_mbedtls_ecdsa_create_key(LIBSSH2_SESSION *session,
|
||||
|
||||
if(mbedtls_ecdsa_genkey(*privkey, (mbedtls_ecp_group_id)curve,
|
||||
mbedtls_ctr_drbg_random,
|
||||
&_libssh2_mbedtls_ctr_drbg) != 0)
|
||||
&_libssh2_mbedtls_ctr_drbg))
|
||||
goto failed;
|
||||
|
||||
plen = 2 * mbedtls_mpi_size(&(*privkey)->MBEDTLS_PRIVATE(grp).P) + 1;
|
||||
@ -967,12 +966,12 @@ _libssh2_mbedtls_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx **ctx,
|
||||
mbedtls_ecdsa_init(*ctx);
|
||||
|
||||
if(mbedtls_ecp_group_load(&(*ctx)->MBEDTLS_PRIVATE(grp),
|
||||
(mbedtls_ecp_group_id)curve) != 0)
|
||||
(mbedtls_ecp_group_id)curve))
|
||||
goto failed;
|
||||
|
||||
if(mbedtls_ecp_point_read_binary(&(*ctx)->MBEDTLS_PRIVATE(grp),
|
||||
&(*ctx)->MBEDTLS_PRIVATE(Q),
|
||||
k, k_len) != 0)
|
||||
k, k_len))
|
||||
goto failed;
|
||||
|
||||
if(mbedtls_ecp_check_pubkey(&(*ctx)->MBEDTLS_PRIVATE(grp),
|
||||
@ -1009,7 +1008,7 @@ _libssh2_mbedtls_ecdh_gen_k(_libssh2_bn **k,
|
||||
|
||||
if(mbedtls_ecp_point_read_binary(&privkey->MBEDTLS_PRIVATE(grp),
|
||||
&pubkey,
|
||||
server_pubkey, server_pubkey_len) != 0) {
|
||||
server_pubkey, server_pubkey_len)) {
|
||||
rc = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
@ -1018,12 +1017,12 @@ _libssh2_mbedtls_ecdh_gen_k(_libssh2_bn **k,
|
||||
&pubkey,
|
||||
&privkey->MBEDTLS_PRIVATE(d),
|
||||
mbedtls_ctr_drbg_random,
|
||||
&_libssh2_mbedtls_ctr_drbg) != 0) {
|
||||
&_libssh2_mbedtls_ctr_drbg)) {
|
||||
rc = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(mbedtls_ecp_check_privkey(&privkey->MBEDTLS_PRIVATE(grp), *k) != 0)
|
||||
if(mbedtls_ecp_check_privkey(&privkey->MBEDTLS_PRIVATE(grp), *k))
|
||||
rc = -1;
|
||||
|
||||
cleanup:
|
||||
@ -1062,10 +1061,10 @@ _libssh2_mbedtls_ecdsa_verify(libssh2_ecdsa_ctx *ctx,
|
||||
mbedtls_mpi_init(&pr);
|
||||
mbedtls_mpi_init(&ps);
|
||||
|
||||
if(mbedtls_mpi_read_binary(&pr, r, r_len) != 0)
|
||||
if(mbedtls_mpi_read_binary(&pr, r, r_len))
|
||||
goto cleanup;
|
||||
|
||||
if(mbedtls_mpi_read_binary(&ps, s, s_len) != 0)
|
||||
if(mbedtls_mpi_read_binary(&ps, s, s_len))
|
||||
goto cleanup;
|
||||
|
||||
switch(_libssh2_ecdsa_get_curve_type(ctx)) {
|
||||
@ -1105,11 +1104,11 @@ _libssh2_mbedtls_parse_eckey(libssh2_ecdsa_ctx **ctx,
|
||||
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
|
||||
if(mbedtls_pk_parse_key(pkey, data, data_len, pwd, pwd_len,
|
||||
mbedtls_ctr_drbg_random,
|
||||
&_libssh2_mbedtls_ctr_drbg) != 0)
|
||||
&_libssh2_mbedtls_ctr_drbg))
|
||||
|
||||
goto failed;
|
||||
#else
|
||||
if(mbedtls_pk_parse_key(pkey, data, data_len, pwd, pwd_len) != 0)
|
||||
if(mbedtls_pk_parse_key(pkey, data, data_len, pwd, pwd_len))
|
||||
goto failed;
|
||||
#endif
|
||||
|
||||
@ -1149,23 +1148,23 @@ _libssh2_mbedtls_parse_openssh_key(libssh2_ecdsa_ctx **ctx,
|
||||
|
||||
if(_libssh2_openssh_pem_parse_memory(session, pwd,
|
||||
(const char *)data, data_len,
|
||||
&decrypted) != 0)
|
||||
&decrypted))
|
||||
goto failed;
|
||||
|
||||
if(_libssh2_get_string(decrypted, &name, NULL) != 0)
|
||||
if(_libssh2_get_string(decrypted, &name, NULL))
|
||||
goto failed;
|
||||
|
||||
if(_libssh2_mbedtls_ecdsa_curve_type_from_name((const char *)name,
|
||||
&type) != 0)
|
||||
&type))
|
||||
goto failed;
|
||||
|
||||
if(_libssh2_get_string(decrypted, &curve, &curvelen) != 0)
|
||||
if(_libssh2_get_string(decrypted, &curve, &curvelen))
|
||||
goto failed;
|
||||
|
||||
if(_libssh2_get_string(decrypted, &point_buf, &pointlen) != 0)
|
||||
if(_libssh2_get_string(decrypted, &point_buf, &pointlen))
|
||||
goto failed;
|
||||
|
||||
if(_libssh2_get_bignum_bytes(decrypted, &exponent, &exponentlen) != 0)
|
||||
if(_libssh2_get_bignum_bytes(decrypted, &exponent, &exponentlen))
|
||||
goto failed;
|
||||
|
||||
*ctx = LIBSSH2_ALLOC(session, sizeof(libssh2_ecdsa_ctx));
|
||||
@ -1176,11 +1175,11 @@ _libssh2_mbedtls_parse_openssh_key(libssh2_ecdsa_ctx **ctx,
|
||||
mbedtls_ecdsa_init(*ctx);
|
||||
|
||||
if(mbedtls_ecp_group_load(&(*ctx)->MBEDTLS_PRIVATE(grp),
|
||||
(mbedtls_ecp_group_id)type) != 0)
|
||||
(mbedtls_ecp_group_id)type))
|
||||
goto failed;
|
||||
|
||||
if(mbedtls_mpi_read_binary(&(*ctx)->MBEDTLS_PRIVATE(d),
|
||||
exponent, exponentlen) != 0)
|
||||
exponent, exponentlen))
|
||||
goto failed;
|
||||
|
||||
if(mbedtls_ecp_mul(&(*ctx)->MBEDTLS_PRIVATE(grp),
|
||||
@ -1188,7 +1187,7 @@ _libssh2_mbedtls_parse_openssh_key(libssh2_ecdsa_ctx **ctx,
|
||||
&(*ctx)->MBEDTLS_PRIVATE(d),
|
||||
&(*ctx)->MBEDTLS_PRIVATE(grp).G,
|
||||
mbedtls_ctr_drbg_random,
|
||||
&_libssh2_mbedtls_ctr_drbg) != 0)
|
||||
&_libssh2_mbedtls_ctr_drbg))
|
||||
goto failed;
|
||||
|
||||
if(mbedtls_ecp_check_privkey(&(*ctx)->MBEDTLS_PRIVATE(grp),
|
||||
@ -1225,7 +1224,7 @@ _libssh2_mbedtls_ecdsa_new_private(libssh2_ecdsa_ctx **ctx,
|
||||
unsigned char *data;
|
||||
size_t data_len;
|
||||
|
||||
if(mbedtls_pk_load_file(filename, &data, &data_len) != 0)
|
||||
if(mbedtls_pk_load_file(filename, &data, &data_len))
|
||||
goto cleanup;
|
||||
|
||||
mbedtls_pk_init(&pkey);
|
||||
@ -1341,7 +1340,7 @@ _libssh2_mbedtls_ecdsa_sign(LIBSSH2_SESSION *session,
|
||||
&ctx->MBEDTLS_PRIVATE(d),
|
||||
hash, hash_len,
|
||||
mbedtls_ctr_drbg_random,
|
||||
&_libssh2_mbedtls_ctr_drbg) != 0)
|
||||
&_libssh2_mbedtls_ctr_drbg))
|
||||
goto cleanup;
|
||||
|
||||
r_len = mbedtls_mpi_size(&pr) + 1;
|
||||
|
@ -396,7 +396,7 @@ size_t _libssh2_base64_encode(LIBSSH2_SESSION *session,
|
||||
*outptr = NULL; /* set to NULL in case of failure before we reach the
|
||||
end */
|
||||
|
||||
if(0 == insize)
|
||||
if(insize == 0)
|
||||
insize = strlen(indata);
|
||||
|
||||
base64data = output = LIBSSH2_ALLOC(session, insize * 4 / 3 + 4);
|
||||
|
@ -212,7 +212,7 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx,
|
||||
ret = -1; /* unsupported digest */
|
||||
}
|
||||
|
||||
if(ret != 0) {
|
||||
if(ret) {
|
||||
free(hash);
|
||||
return -1; /* failure */
|
||||
}
|
||||
@ -790,7 +790,7 @@ out:
|
||||
BN_clear_free(aux);
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
if(dmp1)
|
||||
BN_clear_free(dmp1);
|
||||
if(dmq1)
|
||||
@ -862,14 +862,15 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((rc = _libssh2_rsa_new(&rsa,
|
||||
rc = _libssh2_rsa_new(&rsa,
|
||||
e, (unsigned long)elen,
|
||||
n, (unsigned long)nlen,
|
||||
d, (unsigned long)dlen,
|
||||
p, (unsigned long)plen,
|
||||
q, (unsigned long)qlen,
|
||||
NULL, 0, NULL, 0,
|
||||
coeff, (unsigned long)coefflen)) != 0) {
|
||||
coeff, (unsigned long)coefflen);
|
||||
if(rc) {
|
||||
_libssh2_debug((session,
|
||||
LIBSSH2_TRACE_AUTH,
|
||||
"Could not create RSA private key"));
|
||||
@ -943,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 != 0 || buf == NULL) {
|
||||
if(rc || buf == NULL) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Public key type in decrypted key data not found");
|
||||
return -1;
|
||||
@ -1176,7 +1177,7 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session,
|
||||
g, (unsigned long)glen,
|
||||
pub_key, (unsigned long)pub_len,
|
||||
priv_key, (unsigned long)priv_len);
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
_libssh2_debug((session,
|
||||
LIBSSH2_ERROR_PROTO,
|
||||
"Could not create DSA private key"));
|
||||
@ -1247,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 != 0 || buf == NULL) {
|
||||
if(rc || buf == NULL) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Public key type in decrypted key data not found");
|
||||
return -1;
|
||||
@ -1819,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 != 0 || buf == NULL) {
|
||||
if(rc || buf == NULL) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Public key type in decrypted key data not found");
|
||||
return -1;
|
||||
@ -1891,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 != 0 || buf == NULL) {
|
||||
if(rc || buf == NULL) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Public key type in decrypted key data not found");
|
||||
return -1;
|
||||
@ -2399,7 +2400,7 @@ _libssh2_md5_init(libssh2_md5_ctx *ctx)
|
||||
defined(OPENSSL_VERSION_MAJOR) && \
|
||||
OPENSSL_VERSION_MAJOR < 3 && \
|
||||
!defined(LIBRESSL_VERSION_NUMBER)
|
||||
if(FIPS_mode() != 0)
|
||||
if(FIPS_mode())
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
@ -2603,8 +2604,10 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((rc = _libssh2_ecdsa_curve_name_with_octal_new(&ec_key, point_buf,
|
||||
pointlen, curve_type)) != 0) {
|
||||
rc = _libssh2_ecdsa_curve_name_with_octal_new(&ec_key,
|
||||
point_buf, pointlen,
|
||||
curve_type);
|
||||
if(rc) {
|
||||
rc = -1;
|
||||
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"ECDSA could not create key");
|
||||
@ -2683,8 +2686,10 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((rc = _libssh2_ecdsa_curve_name_with_octal_new(&ec_key, point_buf,
|
||||
pointlen, LIBSSH2_EC_CURVE_NISTP256)) != 0) {
|
||||
rc = _libssh2_ecdsa_curve_name_with_octal_new(&ec_key,
|
||||
point_buf, pointlen,
|
||||
LIBSSH2_EC_CURVE_NISTP256);
|
||||
if(rc) {
|
||||
rc = -1;
|
||||
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"ECDSA could not create key");
|
||||
@ -2822,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 != 0 || buf == NULL) {
|
||||
if(rc || buf == NULL) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Public key type in decrypted key data not found");
|
||||
return -1;
|
||||
@ -2884,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 != 0 || buf == NULL) {
|
||||
if(rc || buf == NULL) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Public key type in decrypted key data not found");
|
||||
return -1;
|
||||
@ -3304,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 != 0 || buf == NULL) {
|
||||
if(rc || buf == NULL) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Public key type in decrypted key data not found");
|
||||
return -1;
|
||||
@ -3358,7 +3363,7 @@ _libssh2_pub_priv_openssh_keyfile(LIBSSH2_SESSION *session,
|
||||
if(decrypted)
|
||||
_libssh2_string_buf_free(session, decrypted);
|
||||
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_FILE,
|
||||
"Unsupported OpenSSH key type");
|
||||
}
|
||||
@ -3406,7 +3411,7 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
|
||||
method_len,
|
||||
pubkeydata, pubkeydata_len,
|
||||
privatekey, passphrase);
|
||||
if(rc != 0) {
|
||||
if(rc) {
|
||||
return _libssh2_error(session,
|
||||
LIBSSH2_ERROR_FILE,
|
||||
"Unable to extract public key "
|
||||
@ -3502,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 != 0 || buf == NULL)
|
||||
if(rc || buf == NULL)
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Public key type in decrypted "
|
||||
"key data not found");
|
||||
@ -3644,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 != 0 || buf == NULL)
|
||||
if(rc || buf == NULL)
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Public key type in decrypted "
|
||||
"key data not found");
|
||||
@ -3753,7 +3758,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
|
||||
privatekeydata,
|
||||
privatekeydata_len,
|
||||
(unsigned const char *)passphrase);
|
||||
if(st != 0)
|
||||
if(st)
|
||||
return st;
|
||||
return 0;
|
||||
}
|
||||
|
@ -1211,9 +1211,9 @@ _libssh2_packet_askv(LIBSSH2_SESSION * session,
|
||||
size_t i, packet_types_len = strlen((const char *) packet_types);
|
||||
|
||||
for(i = 0; i < packet_types_len; i++) {
|
||||
if(0 == _libssh2_packet_ask(session, packet_types[i], data,
|
||||
if(_libssh2_packet_ask(session, packet_types[i], data,
|
||||
data_len, match_ofs,
|
||||
match_buf, match_len)) {
|
||||
match_buf, match_len) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -939,7 +939,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
|
||||
else if(!rc)
|
||||
/* remain in the same state */
|
||||
goto scp_send_empty_channel;
|
||||
else if(session->scpSend_response[0] != 0) {
|
||||
else if(session->scpSend_response[0]) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid ACK response from remote");
|
||||
goto scp_send_error;
|
||||
@ -994,7 +994,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
|
||||
else if(!rc)
|
||||
/* remain in the same state */
|
||||
goto scp_send_empty_channel;
|
||||
else if(session->scpSend_response[0] != 0) {
|
||||
else if(session->scpSend_response[0]) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid SCP ACK response");
|
||||
goto scp_send_error;
|
||||
@ -1064,7 +1064,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
|
||||
else if(rc == 0)
|
||||
goto scp_send_empty_channel;
|
||||
|
||||
else if(session->scpSend_response[0] != 0) {
|
||||
else if(session->scpSend_response[0]) {
|
||||
size_t err_len;
|
||||
char *err_msg;
|
||||
|
||||
|
18
src/sftp.c
18
src/sftp.c
@ -684,13 +684,13 @@ sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES *attrs, const unsigned char *p,
|
||||
buf.dataptr = buf.data;
|
||||
buf.len = data_len;
|
||||
|
||||
if(_libssh2_get_u32(&buf, &flags) != 0) {
|
||||
if(_libssh2_get_u32(&buf, &flags)) {
|
||||
return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
attrs->flags = flags;
|
||||
|
||||
if(attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) {
|
||||
if(_libssh2_get_u64(&buf, &(attrs->filesize)) != 0) {
|
||||
if(_libssh2_get_u64(&buf, &(attrs->filesize))) {
|
||||
return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
}
|
||||
@ -698,8 +698,8 @@ sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES *attrs, const unsigned char *p,
|
||||
if(attrs->flags & LIBSSH2_SFTP_ATTR_UIDGID) {
|
||||
uint32_t uid = 0;
|
||||
uint32_t gid = 0;
|
||||
if(_libssh2_get_u32(&buf, &uid) != 0 ||
|
||||
_libssh2_get_u32(&buf, &gid) != 0) {
|
||||
if(_libssh2_get_u32(&buf, &uid) ||
|
||||
_libssh2_get_u32(&buf, &gid)) {
|
||||
return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
attrs->uid = uid;
|
||||
@ -708,7 +708,7 @@ sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES *attrs, const unsigned char *p,
|
||||
|
||||
if(attrs->flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) {
|
||||
uint32_t permissions;
|
||||
if(_libssh2_get_u32(&buf, &permissions) != 0) {
|
||||
if(_libssh2_get_u32(&buf, &permissions)) {
|
||||
return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
attrs->permissions = permissions;
|
||||
@ -717,8 +717,8 @@ sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES *attrs, const unsigned char *p,
|
||||
if(attrs->flags & LIBSSH2_SFTP_ATTR_ACMODTIME) {
|
||||
uint32_t atime;
|
||||
uint32_t mtime;
|
||||
if(_libssh2_get_u32(&buf, &atime) != 0 ||
|
||||
_libssh2_get_u32(&buf, &mtime) != 0) {
|
||||
if(_libssh2_get_u32(&buf, &atime) ||
|
||||
_libssh2_get_u32(&buf, &mtime)) {
|
||||
return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
attrs->atime = atime;
|
||||
@ -920,7 +920,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
|
||||
buf.len = data_len;
|
||||
endp = &buf.data[data_len];
|
||||
|
||||
if(_libssh2_get_u32(&buf, &(sftp_handle->version)) != 0) {
|
||||
if(_libssh2_get_u32(&buf, &(sftp_handle->version))) {
|
||||
LIBSSH2_FREE(session, data);
|
||||
rc = LIBSSH2_ERROR_BUFFER_TOO_SMALL;
|
||||
goto sftp_init_error;
|
||||
@ -1599,7 +1599,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
|
||||
|
||||
rc = sftp_packet_requirev(sftp, 2, read_responses,
|
||||
chunk->request_id, &data, &data_len, 9);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN && bytes_in_buffer != 0) {
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN && bytes_in_buffer) {
|
||||
/* do not return EAGAIN if we have already
|
||||
* written data into the buffer */
|
||||
return bytes_in_buffer;
|
||||
|
Reference in New Issue
Block a user