mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-20 02:42:09 +03:00
checksrc: fix EQUALSNULL warnings
`s/([a-z0-9._>*-]+) == NULL/!\1/g` Closes #964
This commit is contained in:
@@ -84,7 +84,6 @@ checksrc:
|
|||||||
-ASNPRINTF \
|
-ASNPRINTF \
|
||||||
-ACOPYRIGHT \
|
-ACOPYRIGHT \
|
||||||
-AFOPENMODE \
|
-AFOPENMODE \
|
||||||
-AEQUALSNULL \
|
|
||||||
-ATYPEDEFSTRUCT \
|
-ATYPEDEFSTRUCT \
|
||||||
-Wsrc/libssh2_config.h src/*.[ch] include/*.h example/*.c \
|
-Wsrc/libssh2_config.h src/*.[ch] include/*.h example/*.c \
|
||||||
tests/*.[ch]
|
tests/*.[ch]
|
||||||
|
|||||||
@@ -9,6 +9,5 @@ perl ./ci/checksrc.pl -i4 -m79 \
|
|||||||
-ASNPRINTF \
|
-ASNPRINTF \
|
||||||
-ACOPYRIGHT \
|
-ACOPYRIGHT \
|
||||||
-AFOPENMODE \
|
-AFOPENMODE \
|
||||||
-AEQUALSNULL \
|
|
||||||
-ATYPEDEFSTRUCT \
|
-ATYPEDEFSTRUCT \
|
||||||
$WHITELIST $FILES
|
$WHITELIST $FILES
|
||||||
|
|||||||
@@ -299,12 +299,12 @@ agent_transact_pageant(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
|
|||||||
filemap = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
|
filemap = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
|
||||||
0, PAGEANT_MAX_MSGLEN, mapname);
|
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,
|
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||||
"failed setting up pageant filemap");
|
"failed setting up pageant filemap");
|
||||||
|
|
||||||
p2 = p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0);
|
p2 = p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0);
|
||||||
if(p == NULL || p2 == NULL) {
|
if(!p || !p2) {
|
||||||
CloseHandle(filemap);
|
CloseHandle(filemap);
|
||||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||||
"failed to open pageant filemap for writing");
|
"failed to open pageant filemap for writing");
|
||||||
@@ -858,7 +858,7 @@ libssh2_agent_free(LIBSSH2_AGENT *agent)
|
|||||||
libssh2_agent_disconnect(agent);
|
libssh2_agent_disconnect(agent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(agent->identity_agent_path != NULL)
|
if(agent->identity_agent_path)
|
||||||
LIBSSH2_FREE(agent->session, agent->identity_agent_path);
|
LIBSSH2_FREE(agent->session, agent->identity_agent_path);
|
||||||
|
|
||||||
agent_free_identities(agent);
|
agent_free_identities(agent);
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ agent_connect_openssh(LIBSSH2_AGENT *agent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
event = CreateEventA(NULL, TRUE, FALSE, NULL);
|
event = CreateEventA(NULL, TRUE, FALSE, NULL);
|
||||||
if(event == NULL) {
|
if(!event) {
|
||||||
ret = _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
ret = _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||||
"unable to create async I/O event");
|
"unable to create async I/O event");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@@ -197,7 +197,7 @@ agent_connect_openssh(LIBSSH2_AGENT *agent)
|
|||||||
agent->fd = 0; /* Mark as the connection has been established */
|
agent->fd = 0; /* Mark as the connection has been established */
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if(event != NULL)
|
if(event)
|
||||||
CloseHandle(event);
|
CloseHandle(event);
|
||||||
if(pipe != INVALID_HANDLE_VALUE)
|
if(pipe != INVALID_HANDLE_VALUE)
|
||||||
CloseHandle(pipe);
|
CloseHandle(pipe);
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt,
|
|||||||
keylen > sizeof(out) * sizeof(out) || saltlen > 1<<20)
|
keylen > sizeof(out) * sizeof(out) || saltlen > 1<<20)
|
||||||
return -1;
|
return -1;
|
||||||
countsalt = calloc(1, saltlen + 4);
|
countsalt = calloc(1, saltlen + 4);
|
||||||
if(countsalt == NULL)
|
if(!countsalt)
|
||||||
return -1;
|
return -1;
|
||||||
stride = (keylen + sizeof(out) - 1) / sizeof(out);
|
stride = (keylen + sizeof(out) - 1) / sizeof(out);
|
||||||
amt = (keylen + stride - 1) / stride;
|
amt = (keylen + stride - 1) / stride;
|
||||||
|
|||||||
@@ -2274,7 +2274,7 @@ _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel, int stream_id)
|
|||||||
uint32_t read_local_id;
|
uint32_t read_local_id;
|
||||||
|
|
||||||
read_packet = _libssh2_list_first(&session->packets);
|
read_packet = _libssh2_list_first(&session->packets);
|
||||||
if(read_packet == NULL)
|
if(!read_packet)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while(read_packet) {
|
while(read_packet) {
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session,
|
|||||||
out_maxlen = payload_limit;
|
out_maxlen = payload_limit;
|
||||||
|
|
||||||
/* If strm is null, then we have not yet been initialized. */
|
/* If strm is null, then we have not yet been initialized. */
|
||||||
if(strm == NULL)
|
if(!strm)
|
||||||
return _libssh2_error(session, LIBSSH2_ERROR_COMPRESS,
|
return _libssh2_error(session, LIBSSH2_ERROR_COMPRESS,
|
||||||
"decompression uninitialized");
|
"decompression uninitialized");
|
||||||
|
|
||||||
|
|||||||
@@ -722,7 +722,7 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session,
|
|||||||
libssh2_curve_type type;
|
libssh2_curve_type type;
|
||||||
struct string_buf buf;
|
struct string_buf buf;
|
||||||
|
|
||||||
if(abstract != NULL && *abstract) {
|
if(abstract && *abstract) {
|
||||||
hostkey_method_ssh_ecdsa_dtor(session, abstract);
|
hostkey_method_ssh_ecdsa_dtor(session, abstract);
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
}
|
}
|
||||||
@@ -780,7 +780,7 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session,
|
|||||||
key_len, type))
|
key_len, type))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(abstract != NULL)
|
if(abstract)
|
||||||
*abstract = ecdsactx;
|
*abstract = ecdsactx;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -800,7 +800,7 @@ hostkey_method_ssh_ecdsa_initPEM(LIBSSH2_SESSION * session,
|
|||||||
libssh2_ecdsa_ctx *ec_ctx = NULL;
|
libssh2_ecdsa_ctx *ec_ctx = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if(abstract != NULL && *abstract) {
|
if(abstract && *abstract) {
|
||||||
hostkey_method_ssh_ecdsa_dtor(session, abstract);
|
hostkey_method_ssh_ecdsa_dtor(session, abstract);
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
}
|
}
|
||||||
@@ -808,7 +808,7 @@ hostkey_method_ssh_ecdsa_initPEM(LIBSSH2_SESSION * session,
|
|||||||
ret = _libssh2_ecdsa_new_private(&ec_ctx, session,
|
ret = _libssh2_ecdsa_new_private(&ec_ctx, session,
|
||||||
privkeyfile, passphrase);
|
privkeyfile, passphrase);
|
||||||
|
|
||||||
if(abstract != NULL)
|
if(abstract)
|
||||||
*abstract = ec_ctx;
|
*abstract = ec_ctx;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -829,7 +829,7 @@ hostkey_method_ssh_ecdsa_initPEMFromMemory(LIBSSH2_SESSION * session,
|
|||||||
libssh2_ecdsa_ctx *ec_ctx = NULL;
|
libssh2_ecdsa_ctx *ec_ctx = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if(abstract != NULL && *abstract) {
|
if(abstract && *abstract) {
|
||||||
hostkey_method_ssh_ecdsa_dtor(session, abstract);
|
hostkey_method_ssh_ecdsa_dtor(session, abstract);
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
}
|
}
|
||||||
@@ -842,7 +842,7 @@ hostkey_method_ssh_ecdsa_initPEMFromMemory(LIBSSH2_SESSION * session,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(abstract != NULL)
|
if(abstract)
|
||||||
*abstract = ec_ctx;
|
*abstract = ec_ctx;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -954,7 +954,7 @@ hostkey_method_ssh_ecdsa_dtor(LIBSSH2_SESSION * session, void **abstract)
|
|||||||
libssh2_ecdsa_ctx *keyctx = (libssh2_ecdsa_ctx *) (*abstract);
|
libssh2_ecdsa_ctx *keyctx = (libssh2_ecdsa_ctx *) (*abstract);
|
||||||
(void) session;
|
(void) session;
|
||||||
|
|
||||||
if(keyctx != NULL)
|
if(keyctx)
|
||||||
_libssh2_ecdsa_free(keyctx);
|
_libssh2_ecdsa_free(keyctx);
|
||||||
|
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
@@ -1140,7 +1140,7 @@ hostkey_method_ssh_ed25519_initPEMFromMemory(LIBSSH2_SESSION * session,
|
|||||||
libssh2_ed25519_ctx *ed_ctx = NULL;
|
libssh2_ed25519_ctx *ed_ctx = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if(abstract != NULL && *abstract) {
|
if(abstract && *abstract) {
|
||||||
hostkey_method_ssh_ed25519_dtor(session, abstract);
|
hostkey_method_ssh_ed25519_dtor(session, abstract);
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
}
|
}
|
||||||
@@ -1153,7 +1153,7 @@ hostkey_method_ssh_ed25519_initPEMFromMemory(LIBSSH2_SESSION * session,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(abstract != NULL)
|
if(abstract)
|
||||||
*abstract = ed_ctx;
|
*abstract = ed_ctx;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
23
src/kex.c
23
src/kex.c
@@ -468,7 +468,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session,
|
|||||||
(const char *)
|
(const char *)
|
||||||
session->server_hostkey_sha256,
|
session->server_hostkey_sha256,
|
||||||
SHA256_DIGEST_LENGTH, &base64Fingerprint);
|
SHA256_DIGEST_LENGTH, &base64Fingerprint);
|
||||||
if(base64Fingerprint != NULL) {
|
if(base64Fingerprint) {
|
||||||
_libssh2_debug((session, LIBSSH2_TRACE_KEX,
|
_libssh2_debug((session, LIBSSH2_TRACE_KEX,
|
||||||
"Server's SHA256 Fingerprint: %s",
|
"Server's SHA256 Fingerprint: %s",
|
||||||
base64Fingerprint));
|
base64Fingerprint));
|
||||||
@@ -1675,7 +1675,7 @@ kex_session_ecdh_curve_type(const char *name, libssh2_curve_type *out_type)
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
libssh2_curve_type type;
|
libssh2_curve_type type;
|
||||||
|
|
||||||
if(name == NULL)
|
if(!name)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(strcmp(name, "ecdh-sha2-nistp256") == 0)
|
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 *)
|
(const char *)
|
||||||
session->server_hostkey_sha256,
|
session->server_hostkey_sha256,
|
||||||
SHA256_DIGEST_LENGTH, &base64Fingerprint);
|
SHA256_DIGEST_LENGTH, &base64Fingerprint);
|
||||||
if(base64Fingerprint != NULL) {
|
if(base64Fingerprint) {
|
||||||
_libssh2_debug((session, LIBSSH2_TRACE_KEX,
|
_libssh2_debug((session, LIBSSH2_TRACE_KEX,
|
||||||
"Server's SHA256 Fingerprint: %s",
|
"Server's SHA256 Fingerprint: %s",
|
||||||
base64Fingerprint));
|
base64Fingerprint));
|
||||||
@@ -2462,7 +2462,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
(const char *)
|
(const char *)
|
||||||
session->server_hostkey_sha256,
|
session->server_hostkey_sha256,
|
||||||
SHA256_DIGEST_LENGTH, &base64Fingerprint);
|
SHA256_DIGEST_LENGTH, &base64Fingerprint);
|
||||||
if(base64Fingerprint != NULL) {
|
if(base64Fingerprint) {
|
||||||
_libssh2_debug((session, LIBSSH2_TRACE_KEX,
|
_libssh2_debug((session, LIBSSH2_TRACE_KEX,
|
||||||
"Server's SHA256 Fingerprint: %s",
|
"Server's SHA256 Fingerprint: %s",
|
||||||
base64Fingerprint));
|
base64Fingerprint));
|
||||||
@@ -3306,7 +3306,7 @@ kex_agree_instr(unsigned char *haystack, size_t haystack_len,
|
|||||||
unsigned char *end_haystack;
|
unsigned char *end_haystack;
|
||||||
size_t left;
|
size_t left;
|
||||||
|
|
||||||
if(haystack == NULL || needle == NULL) {
|
if(!haystack || !needle) {
|
||||||
return NULL;
|
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,
|
/* Search until we run out of comas or we run out of haystack,
|
||||||
whichever comes first */
|
whichever comes first */
|
||||||
|
/* !checksrc! disable EQUALSNULL 1 */
|
||||||
while((s = (unsigned char *) memchr((char *) s, ',', left)) != NULL) {
|
while((s = (unsigned char *) memchr((char *) s, ',', left)) != NULL) {
|
||||||
/* Advance buffer past coma if we can */
|
/* Advance buffer past coma if we can */
|
||||||
left = end_haystack - s;
|
left = end_haystack - s;
|
||||||
@@ -4070,7 +4071,7 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
|
|||||||
const LIBSSH2_COMMON_METHOD **mlist;
|
const LIBSSH2_COMMON_METHOD **mlist;
|
||||||
|
|
||||||
/* to prevent coredumps due to dereferencing of NULL */
|
/* to prevent coredumps due to dereferencing of NULL */
|
||||||
if(NULL == algs)
|
if(!algs)
|
||||||
return _libssh2_error(session, LIBSSH2_ERROR_BAD_USE,
|
return _libssh2_error(session, LIBSSH2_ERROR_BAD_USE,
|
||||||
"algs must not be NULL");
|
"algs must not be NULL");
|
||||||
|
|
||||||
@@ -4110,7 +4111,7 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
|
|||||||
} /* switch */
|
} /* switch */
|
||||||
|
|
||||||
/* weird situation */
|
/* weird situation */
|
||||||
if(NULL == mlist)
|
if(!mlist)
|
||||||
return _libssh2_error(session, LIBSSH2_ERROR_INVAL,
|
return _libssh2_error(session, LIBSSH2_ERROR_INVAL,
|
||||||
"No algorithm found");
|
"No algorithm found");
|
||||||
|
|
||||||
@@ -4127,7 +4128,7 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* count the number of supported algorithms */
|
/* 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 */
|
/* do not count fields with NULL name */
|
||||||
if(mlist[i]->name)
|
if(mlist[i]->name)
|
||||||
ialg++;
|
ialg++;
|
||||||
@@ -4140,15 +4141,15 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
|
|||||||
|
|
||||||
/* allocate buffer */
|
/* allocate buffer */
|
||||||
*algs = (const char **) LIBSSH2_ALLOC(session, ialg*sizeof(const char *));
|
*algs = (const char **) LIBSSH2_ALLOC(session, ialg*sizeof(const char *));
|
||||||
if(NULL == *algs) {
|
if(!*algs) {
|
||||||
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
"Memory allocation failed");
|
"Memory allocation failed");
|
||||||
}
|
}
|
||||||
/* Past this point *algs must be deallocated in case of an error!! */
|
/* Past this point *algs must be deallocated in case of an error!! */
|
||||||
|
|
||||||
/* copy non-NULL pointers only */
|
/* copy non-NULL pointers only */
|
||||||
for(i = 0, j = 0; NULL != mlist[i] && j < ialg; i++) {
|
for(i = 0, j = 0; mlist[i] && j < ialg; i++) {
|
||||||
if(NULL == mlist[i]->name) {
|
if(!mlist[i]->name) {
|
||||||
/* maybe a weird situation but if it occurs, do not include NULL
|
/* maybe a weird situation but if it occurs, do not include NULL
|
||||||
pointers */
|
pointers */
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ _libssh2_mbedtls_hash_init(mbedtls_md_context_t *ctx,
|
|||||||
if(!md_info)
|
if(!md_info)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
hmac = key == NULL ? 0 : 1;
|
hmac = key ? 1 : 0;
|
||||||
|
|
||||||
mbedtls_md_init(ctx);
|
mbedtls_md_init(ctx);
|
||||||
ret = mbedtls_md_setup(ctx, md_info, hmac);
|
ret = mbedtls_md_setup(ctx, md_info, hmac);
|
||||||
@@ -336,7 +336,7 @@ _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa,
|
|||||||
libssh2_rsa_ctx *ctx;
|
libssh2_rsa_ctx *ctx;
|
||||||
|
|
||||||
ctx = (libssh2_rsa_ctx *) mbedtls_calloc(1, sizeof(libssh2_rsa_ctx));
|
ctx = (libssh2_rsa_ctx *) mbedtls_calloc(1, sizeof(libssh2_rsa_ctx));
|
||||||
if(ctx != NULL) {
|
if(ctx) {
|
||||||
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
|
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
|
||||||
mbedtls_rsa_init(ctx);
|
mbedtls_rsa_init(ctx);
|
||||||
#else
|
#else
|
||||||
@@ -400,7 +400,7 @@ _libssh2_mbedtls_rsa_new_private(libssh2_rsa_ctx **rsa,
|
|||||||
mbedtls_rsa_context *pk_rsa;
|
mbedtls_rsa_context *pk_rsa;
|
||||||
|
|
||||||
*rsa = (libssh2_rsa_ctx *) LIBSSH2_ALLOC(session, sizeof(libssh2_rsa_ctx));
|
*rsa = (libssh2_rsa_ctx *) LIBSSH2_ALLOC(session, sizeof(libssh2_rsa_ctx));
|
||||||
if(*rsa == NULL)
|
if(!*rsa)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
|
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
|
||||||
@@ -446,7 +446,7 @@ _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa,
|
|||||||
size_t pwd_len;
|
size_t pwd_len;
|
||||||
|
|
||||||
*rsa = (libssh2_rsa_ctx *) mbedtls_calloc(1, sizeof(libssh2_rsa_ctx));
|
*rsa = (libssh2_rsa_ctx *) mbedtls_calloc(1, sizeof(libssh2_rsa_ctx));
|
||||||
if(*rsa == NULL)
|
if(!*rsa)
|
||||||
return -1;
|
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
|
private-key from memory will fail if the last byte is not a null byte
|
||||||
*/
|
*/
|
||||||
filedata_nullterm = mbedtls_calloc(filedata_len + 1, 1);
|
filedata_nullterm = mbedtls_calloc(filedata_len + 1, 1);
|
||||||
if(filedata_nullterm == NULL) {
|
if(!filedata_nullterm) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(filedata_nullterm, filedata, filedata_len);
|
memcpy(filedata_nullterm, filedata, filedata_len);
|
||||||
|
|
||||||
mbedtls_pk_init(&pkey);
|
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
|
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
|
||||||
ret = mbedtls_pk_parse_key(&pkey, (unsigned char *)filedata_nullterm,
|
ret = mbedtls_pk_parse_key(&pkey, (unsigned char *)filedata_nullterm,
|
||||||
filedata_len + 1,
|
filedata_len + 1,
|
||||||
@@ -505,7 +505,7 @@ _libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
hash = malloc(hash_len);
|
hash = malloc(hash_len);
|
||||||
if(hash == NULL)
|
if(!hash)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(hash_len == SHA_DIGEST_LENGTH) {
|
if(hash_len == SHA_DIGEST_LENGTH) {
|
||||||
@@ -699,7 +699,7 @@ _libssh2_mbedtls_pub_priv_key(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
rsa = mbedtls_pk_rsa(*pkey);
|
rsa = mbedtls_pk_rsa(*pkey);
|
||||||
key = gen_publickey_from_rsa(session, rsa, &keylen);
|
key = gen_publickey_from_rsa(session, rsa, &keylen);
|
||||||
if(key == NULL) {
|
if(!key) {
|
||||||
ret = -1;
|
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
|
private-key from memory will fail if the last byte is not a null byte
|
||||||
*/
|
*/
|
||||||
privatekeydata_nullterm = mbedtls_calloc(privatekeydata_len + 1, 1);
|
privatekeydata_nullterm = mbedtls_calloc(privatekeydata_len + 1, 1);
|
||||||
if(privatekeydata_nullterm == NULL) {
|
if(!privatekeydata_nullterm) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(privatekeydata_nullterm, privatekeydata, privatekeydata_len);
|
memcpy(privatekeydata_nullterm, privatekeydata, privatekeydata_len);
|
||||||
|
|
||||||
mbedtls_pk_init(&pkey);
|
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
|
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
|
||||||
ret = mbedtls_pk_parse_key(&pkey,
|
ret = mbedtls_pk_parse_key(&pkey,
|
||||||
(unsigned char *)privatekeydata_nullterm,
|
(unsigned char *)privatekeydata_nullterm,
|
||||||
@@ -915,7 +915,7 @@ _libssh2_mbedtls_ecdsa_create_key(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
*privkey = LIBSSH2_ALLOC(session, sizeof(mbedtls_ecp_keypair));
|
*privkey = LIBSSH2_ALLOC(session, sizeof(mbedtls_ecp_keypair));
|
||||||
|
|
||||||
if(*privkey == NULL)
|
if(!*privkey)
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
mbedtls_ecdsa_init(*privkey);
|
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;
|
plen = 2 * mbedtls_mpi_size(&(*privkey)->MBEDTLS_PRIVATE(grp).P) + 1;
|
||||||
*pubkey_oct = LIBSSH2_ALLOC(session, plen);
|
*pubkey_oct = LIBSSH2_ALLOC(session, plen);
|
||||||
|
|
||||||
if(*pubkey_oct == NULL)
|
if(!*pubkey_oct)
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
if(mbedtls_ecp_point_write_binary(&(*privkey)->MBEDTLS_PRIVATE(grp),
|
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));
|
*ctx = mbedtls_calloc(1, sizeof(mbedtls_ecp_keypair));
|
||||||
|
|
||||||
if(*ctx == NULL)
|
if(!*ctx)
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
mbedtls_ecdsa_init(*ctx);
|
mbedtls_ecdsa_init(*ctx);
|
||||||
@@ -1001,7 +1001,7 @@ _libssh2_mbedtls_ecdh_gen_k(_libssh2_bn **k,
|
|||||||
mbedtls_ecp_point pubkey;
|
mbedtls_ecp_point pubkey;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if(*k == NULL)
|
if(!*k)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
mbedtls_ecp_point_init(&pubkey);
|
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));
|
*ctx = LIBSSH2_ALLOC(session, sizeof(libssh2_ecdsa_ctx));
|
||||||
|
|
||||||
if(*ctx == NULL)
|
if(!*ctx)
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
mbedtls_ecdsa_init(*ctx);
|
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));
|
*ctx = LIBSSH2_ALLOC(session, sizeof(libssh2_ecdsa_ctx));
|
||||||
|
|
||||||
if(*ctx == NULL)
|
if(!*ctx)
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
mbedtls_ecdsa_init(*ctx);
|
mbedtls_ecdsa_init(*ctx);
|
||||||
@@ -1205,7 +1205,7 @@ cleanup:
|
|||||||
_libssh2_string_buf_free(session, decrypted);
|
_libssh2_string_buf_free(session, decrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (*ctx == NULL) ? -1 : 0;
|
return *ctx ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _libssh2_ecdsa_new_private
|
/* _libssh2_ecdsa_new_private
|
||||||
@@ -1241,7 +1241,7 @@ cleanup:
|
|||||||
|
|
||||||
_libssh2_mbedtls_safe_free(data, data_len);
|
_libssh2_mbedtls_safe_free(data, data_len);
|
||||||
|
|
||||||
return (*ctx == NULL) ? -1 : 0;
|
return *ctx ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _libssh2_ecdsa_new_private
|
/* _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);
|
ntdata = LIBSSH2_ALLOC(session, data_len + 1);
|
||||||
|
|
||||||
if(ntdata == NULL)
|
if(!ntdata)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
memcpy(ntdata, data, data_len);
|
memcpy(ntdata, data, data_len);
|
||||||
@@ -1282,7 +1282,7 @@ cleanup:
|
|||||||
|
|
||||||
_libssh2_mbedtls_safe_free(ntdata, data_len);
|
_libssh2_mbedtls_safe_free(ntdata, data_len);
|
||||||
|
|
||||||
return (*ctx == NULL) ? -1 : 0;
|
return *ctx ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *
|
static unsigned char *
|
||||||
@@ -1349,7 +1349,7 @@ _libssh2_mbedtls_ecdsa_sign(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
tmp_sign = LIBSSH2_CALLOC(session, tmp_sign_len);
|
tmp_sign = LIBSSH2_CALLOC(session, tmp_sign_len);
|
||||||
|
|
||||||
if(tmp_sign == NULL)
|
if(!tmp_sign)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
sp = tmp_sign;
|
sp = tmp_sign;
|
||||||
@@ -1360,7 +1360,7 @@ _libssh2_mbedtls_ecdsa_sign(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
*sign = LIBSSH2_CALLOC(session, *sign_len);
|
*sign = LIBSSH2_CALLOC(session, *sign_len);
|
||||||
|
|
||||||
if(*sign == NULL)
|
if(!*sign)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
memcpy(*sign, tmp_sign, *sign_len);
|
memcpy(*sign, tmp_sign, *sign_len);
|
||||||
@@ -1372,7 +1372,7 @@ cleanup:
|
|||||||
|
|
||||||
_libssh2_mbedtls_safe_free(tmp_sign, tmp_sign_len);
|
_libssh2_mbedtls_safe_free(tmp_sign, tmp_sign_len);
|
||||||
|
|
||||||
return (*sign == NULL) ? -1 : 0;
|
return *sign ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _libssh2_ecdsa_get_curve_type
|
/* _libssh2_ecdsa_get_curve_type
|
||||||
@@ -1400,7 +1400,7 @@ _libssh2_mbedtls_ecdsa_curve_type_from_name(const char *name,
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
libssh2_curve_type type;
|
libssh2_curve_type type;
|
||||||
|
|
||||||
if(name == NULL || strlen(name) != 19)
|
if(!name || strlen(name) != 19)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(strcmp(name, "ecdsa-sha2-nistp256") == 0)
|
if(strcmp(name, "ecdsa-sha2-nistp256") == 0)
|
||||||
|
|||||||
14
src/misc.c
14
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,
|
int _libssh2_error_flags(LIBSSH2_SESSION* session, int errcode,
|
||||||
const char *errmsg, int errflags)
|
const char *errmsg, int errflags)
|
||||||
{
|
{
|
||||||
if(session == NULL) {
|
if(!session) {
|
||||||
if(errmsg != NULL)
|
if(errmsg)
|
||||||
fprintf(stderr, "Session is NULL, error: %s\n", errmsg);
|
fprintf(stderr, "Session is NULL, error: %s\n", errmsg);
|
||||||
return errcode;
|
return errcode;
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ int _libssh2_error_flags(LIBSSH2_SESSION* session, int errcode,
|
|||||||
session->err_code = errcode;
|
session->err_code = errcode;
|
||||||
session->err_flags = 0;
|
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);
|
size_t len = strlen(errmsg);
|
||||||
char *copy = LIBSSH2_ALLOC(session, len + 1);
|
char *copy = LIBSSH2_ALLOC(session, len + 1);
|
||||||
if(copy) {
|
if(copy) {
|
||||||
@@ -400,7 +400,7 @@ size_t _libssh2_base64_encode(LIBSSH2_SESSION *session,
|
|||||||
insize = strlen(indata);
|
insize = strlen(indata);
|
||||||
|
|
||||||
base64data = output = LIBSSH2_ALLOC(session, insize * 4 / 3 + 4);
|
base64data = output = LIBSSH2_ALLOC(session, insize * 4 / 3 + 4);
|
||||||
if(NULL == output)
|
if(!output)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while(insize > 0) {
|
while(insize > 0) {
|
||||||
@@ -756,7 +756,7 @@ struct string_buf *_libssh2_string_buf_new(LIBSSH2_SESSION *session)
|
|||||||
struct string_buf *ret;
|
struct string_buf *ret;
|
||||||
|
|
||||||
ret = _libssh2_calloc(session, sizeof(*ret));
|
ret = _libssh2_calloc(session, sizeof(*ret));
|
||||||
if(ret == NULL)
|
if(!ret)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return ret;
|
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)
|
void _libssh2_string_buf_free(LIBSSH2_SESSION *session, struct string_buf *buf)
|
||||||
{
|
{
|
||||||
if(buf == NULL)
|
if(!buf)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(buf->data != NULL)
|
if(buf->data)
|
||||||
LIBSSH2_FREE(session, buf->data);
|
LIBSSH2_FREE(session, buf->data);
|
||||||
|
|
||||||
LIBSSH2_FREE(session, buf);
|
LIBSSH2_FREE(session, buf);
|
||||||
|
|||||||
294
src/openssl.c
294
src/openssl.c
File diff suppressed because it is too large
Load Diff
@@ -649,7 +649,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
|
|||||||
_libssh2_get_string(&buf, &name, &name_len);
|
_libssh2_get_string(&buf, &name, &name_len);
|
||||||
_libssh2_get_string(&buf, &value, &value_len);
|
_libssh2_get_string(&buf, &value, &value_len);
|
||||||
|
|
||||||
if(name != NULL && value != NULL) {
|
if(name && value) {
|
||||||
_libssh2_debug((session,
|
_libssh2_debug((session,
|
||||||
LIBSSH2_TRACE_KEX,
|
LIBSSH2_TRACE_KEX,
|
||||||
"Server to Client extension %.*s: %.*s",
|
"Server to Client extension %.*s: %.*s",
|
||||||
|
|||||||
23
src/pem.c
23
src/pem.c
@@ -142,6 +142,7 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session,
|
|||||||
}
|
}
|
||||||
|
|
||||||
all_methods = libssh2_crypt_methods();
|
all_methods = libssh2_crypt_methods();
|
||||||
|
/* !checksrc! disable EQUALSNULL 1 */
|
||||||
while((cur_method = *all_methods++) != NULL) {
|
while((cur_method = *all_methods++) != NULL) {
|
||||||
if(*cur_method->pem_annotation &&
|
if(*cur_method->pem_annotation &&
|
||||||
memcmp(line, 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 */
|
/* None of the available crypt methods were able to decrypt the key */
|
||||||
if(method == NULL)
|
if(!method)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Decode IV from hex */
|
/* Decode IV from hex */
|
||||||
@@ -441,7 +442,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
|
|||||||
kdf_buf.len = kdf_len;
|
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) {
|
strcmp((const char *)ciphername, "none") != 0) {
|
||||||
/* passphrase required */
|
/* passphrase required */
|
||||||
ret = LIBSSH2_ERROR_KEYFILE_AUTH_FAILED;
|
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;
|
const LIBSSH2_CRYPT_METHOD **all_methods, *cur_method;
|
||||||
|
|
||||||
all_methods = libssh2_crypt_methods();
|
all_methods = libssh2_crypt_methods();
|
||||||
|
/* !checksrc! disable EQUALSNULL 1 */
|
||||||
while((cur_method = *all_methods++) != NULL) {
|
while((cur_method = *all_methods++) != NULL) {
|
||||||
if(*cur_method->name &&
|
if(*cur_method->name &&
|
||||||
memcmp(ciphername, 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 */
|
/* None of the available crypt methods were able to decrypt the key */
|
||||||
|
|
||||||
if(method == NULL) {
|
if(!method) {
|
||||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||||
"No supported cipher found");
|
"No supported cipher found");
|
||||||
goto out;
|
goto out;
|
||||||
@@ -518,14 +520,13 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
|
|||||||
total_len = keylen + ivlen;
|
total_len = keylen + ivlen;
|
||||||
|
|
||||||
key = LIBSSH2_CALLOC(session, total_len);
|
key = LIBSSH2_CALLOC(session, total_len);
|
||||||
if(key == NULL) {
|
if(!key) {
|
||||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||||
"Could not alloc key");
|
"Could not alloc key");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp((const char *)kdfname, "bcrypt") == 0 &&
|
if(strcmp((const char *)kdfname, "bcrypt") == 0 && passphrase) {
|
||||||
passphrase != NULL) {
|
|
||||||
if((_libssh2_get_string(&kdf_buf, &salt, &salt_len)) ||
|
if((_libssh2_get_string(&kdf_buf, &salt, &salt_len)) ||
|
||||||
(_libssh2_get_u32(&kdf_buf, &rounds) != 0) ) {
|
(_libssh2_get_u32(&kdf_buf, &rounds) != 0) ) {
|
||||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||||
@@ -555,14 +556,14 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
|
|||||||
blocksize = method->blocksize;
|
blocksize = method->blocksize;
|
||||||
|
|
||||||
key_part = LIBSSH2_CALLOC(session, keylen);
|
key_part = LIBSSH2_CALLOC(session, keylen);
|
||||||
if(key_part == NULL) {
|
if(!key_part) {
|
||||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||||
"Could not alloc key part");
|
"Could not alloc key part");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
iv_part = LIBSSH2_CALLOC(session, ivlen);
|
iv_part = LIBSSH2_CALLOC(session, ivlen);
|
||||||
if(iv_part == NULL) {
|
if(!iv_part) {
|
||||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||||
"Could not alloc iv part");
|
"Could not alloc iv part");
|
||||||
goto out;
|
goto out;
|
||||||
@@ -613,7 +614,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(decrypted_buf != NULL) {
|
if(decrypted_buf) {
|
||||||
/* copy data to out-going buffer */
|
/* copy data to out-going buffer */
|
||||||
struct string_buf *out_buf = _libssh2_string_buf_new(session);
|
struct string_buf *out_buf = _libssh2_string_buf_new(session);
|
||||||
if(!out_buf) {
|
if(!out_buf) {
|
||||||
@@ -624,7 +625,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
|
|||||||
}
|
}
|
||||||
|
|
||||||
out_buf->data = LIBSSH2_CALLOC(session, decrypted.len);
|
out_buf->data = LIBSSH2_CALLOC(session, decrypted.len);
|
||||||
if(out_buf->data == NULL) {
|
if(!out_buf->data) {
|
||||||
ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
"Unable to allocate memory for "
|
"Unable to allocate memory for "
|
||||||
"decrypted struct");
|
"decrypted struct");
|
||||||
@@ -745,7 +746,7 @@ _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION * session,
|
|||||||
size_t off = 0;
|
size_t off = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if(filedata == NULL || filedata_len <= 0)
|
if(!filedata || filedata_len <= 0)
|
||||||
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||||
"Error parsing PEM: filedata missing");
|
"Error parsing PEM: filedata missing");
|
||||||
|
|
||||||
|
|||||||
@@ -911,8 +911,8 @@ session_free(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(session->free_state == libssh2_NB_state_created) {
|
if(session->free_state == libssh2_NB_state_created) {
|
||||||
|
/* !checksrc! disable EQUALSNULL 1 */
|
||||||
while((ch = _libssh2_list_first(&session->channels)) != NULL) {
|
while((ch = _libssh2_list_first(&session->channels)) != NULL) {
|
||||||
|
|
||||||
rc = _libssh2_channel_free(ch);
|
rc = _libssh2_channel_free(ch);
|
||||||
if(rc == LIBSSH2_ERROR_EAGAIN)
|
if(rc == LIBSSH2_ERROR_EAGAIN)
|
||||||
return rc;
|
return rc;
|
||||||
@@ -922,6 +922,7 @@ session_free(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(session->free_state == libssh2_NB_state_sent) {
|
if(session->free_state == libssh2_NB_state_sent) {
|
||||||
|
/* !checksrc! disable EQUALSNULL 1 */
|
||||||
while((l = _libssh2_list_first(&session->listeners)) != NULL) {
|
while((l = _libssh2_list_first(&session->listeners)) != NULL) {
|
||||||
rc = _libssh2_channel_forward_cancel(l);
|
rc = _libssh2_channel_forward_cancel(l);
|
||||||
if(rc == LIBSSH2_ERROR_EAGAIN)
|
if(rc == LIBSSH2_ERROR_EAGAIN)
|
||||||
@@ -1108,6 +1109,7 @@ session_free(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup all remaining packets */
|
/* Cleanup all remaining packets */
|
||||||
|
/* !checksrc! disable EQUALSNULL 1 */
|
||||||
while((pkg = _libssh2_list_first(&session->packets)) != NULL) {
|
while((pkg = _libssh2_list_first(&session->packets)) != NULL) {
|
||||||
packets_left++;
|
packets_left++;
|
||||||
_libssh2_debug((session, LIBSSH2_TRACE_TRANS,
|
_libssh2_debug((session, LIBSSH2_TRACE_TRANS,
|
||||||
@@ -1901,10 +1903,10 @@ LIBSSH2_API const char *
|
|||||||
libssh2_session_banner_get(LIBSSH2_SESSION *session)
|
libssh2_session_banner_get(LIBSSH2_SESSION *session)
|
||||||
{
|
{
|
||||||
/* to avoid a coredump when session is NULL */
|
/* to avoid a coredump when session is NULL */
|
||||||
if(NULL == session)
|
if(!session)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if(NULL == session->remote.banner)
|
if(!session->remote.banner)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return (const char *) session->remote.banner;
|
return (const char *) session->remote.banner;
|
||||||
|
|||||||
@@ -508,7 +508,7 @@ sftp_packet_require(LIBSSH2_SFTP *sftp, unsigned char packet_type,
|
|||||||
LIBSSH2_SESSION *session = sftp->channel->session;
|
LIBSSH2_SESSION *session = sftp->channel->session;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if(data == NULL || data_len == NULL || required_size == 0) {
|
if(!data || !data_len || required_size == 0) {
|
||||||
return LIBSSH2_ERROR_BAD_USE;
|
return LIBSSH2_ERROR_BAD_USE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -562,7 +562,7 @@ sftp_packet_requirev(LIBSSH2_SFTP *sftp, int num_valid_responses,
|
|||||||
int i;
|
int i;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if(data == NULL || data_len == NULL || required_size == 0) {
|
if(!data || !data_len || required_size == 0) {
|
||||||
return LIBSSH2_ERROR_BAD_USE;
|
return LIBSSH2_ERROR_BAD_USE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -785,7 +785,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
|
|||||||
* including *EAGAIN).
|
* including *EAGAIN).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
assert(session->sftpInit_sftp == NULL);
|
assert(!session->sftpInit_sftp);
|
||||||
session->sftpInit_sftp = NULL;
|
session->sftpInit_sftp = NULL;
|
||||||
session->sftpInit_state = libssh2_NB_state_created;
|
session->sftpInit_state = libssh2_NB_state_created;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ )
|
|||||||
|
|
||||||
/* Check for and deal with decompression */
|
/* Check for and deal with decompression */
|
||||||
compressed =
|
compressed =
|
||||||
session->local.comp != NULL &&
|
session->local.comp &&
|
||||||
session->local.comp->compress &&
|
session->local.comp->compress &&
|
||||||
((session->state & LIBSSH2_STATE_AUTHENTICATED) ||
|
((session->state & LIBSSH2_STATE_AUTHENTICATED) ||
|
||||||
session->local.comp->use_in_auth);
|
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;
|
encrypted = (session->state & LIBSSH2_STATE_NEWKEYS) ? 1 : 0;
|
||||||
|
|
||||||
compressed =
|
compressed =
|
||||||
session->local.comp != NULL &&
|
session->local.comp &&
|
||||||
session->local.comp->compress &&
|
session->local.comp->compress &&
|
||||||
((session->state & LIBSSH2_STATE_AUTHENTICATED) ||
|
((session->state & LIBSSH2_STATE_AUTHENTICATED) ||
|
||||||
session->local.comp->use_in_auth);
|
session->local.comp->use_in_auth);
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ libssh2_userauth_list(LIBSSH2_SESSION * session, const char *user,
|
|||||||
LIBSSH2_API int
|
LIBSSH2_API int
|
||||||
libssh2_userauth_banner(LIBSSH2_SESSION *session, char **banner)
|
libssh2_userauth_banner(LIBSSH2_SESSION *session, char **banner)
|
||||||
{
|
{
|
||||||
if(NULL == session)
|
if(!session)
|
||||||
return LIBSSH2_ERROR_MISSING_USERAUTH_BANNER;
|
return LIBSSH2_ERROR_MISSING_USERAUTH_BANNER;
|
||||||
|
|
||||||
if(!session->userauth_banner) {
|
if(!session->userauth_banner) {
|
||||||
@@ -261,7 +261,7 @@ libssh2_userauth_banner(LIBSSH2_SESSION *session, char **banner)
|
|||||||
"Missing userauth banner");
|
"Missing userauth banner");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(banner != NULL)
|
if(banner)
|
||||||
*banner = session->userauth_banner;
|
*banner = session->userauth_banner;
|
||||||
|
|
||||||
return LIBSSH2_ERROR_NONE;
|
return LIBSSH2_ERROR_NONE;
|
||||||
@@ -596,7 +596,7 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
|
|||||||
}
|
}
|
||||||
|
|
||||||
sp1 = memchr(pubkey, ' ', pubkey_len);
|
sp1 = memchr(pubkey, ' ', pubkey_len);
|
||||||
if(sp1 == NULL) {
|
if(!sp1) {
|
||||||
LIBSSH2_FREE(session, pubkey);
|
LIBSSH2_FREE(session, pubkey);
|
||||||
return _libssh2_error(session, LIBSSH2_ERROR_FILE,
|
return _libssh2_error(session, LIBSSH2_ERROR_FILE,
|
||||||
"Invalid public key data");
|
"Invalid public key data");
|
||||||
@@ -605,7 +605,7 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
|
|||||||
sp1++;
|
sp1++;
|
||||||
|
|
||||||
sp2 = memchr(sp1, ' ', pubkey_len - (sp1 - pubkey));
|
sp2 = memchr(sp1, ' ', pubkey_len - (sp1 - pubkey));
|
||||||
if(sp2 == NULL) {
|
if(!sp2) {
|
||||||
/* Assume that the id string is missing, but that it's okay */
|
/* Assume that the id string is missing, but that it's okay */
|
||||||
sp2 = pubkey + pubkey_len;
|
sp2 = pubkey + pubkey_len;
|
||||||
}
|
}
|
||||||
@@ -700,7 +700,7 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
|
|||||||
}
|
}
|
||||||
|
|
||||||
sp1 = memchr(pubkey, ' ', pubkey_len);
|
sp1 = memchr(pubkey, ' ', pubkey_len);
|
||||||
if(sp1 == NULL) {
|
if(!sp1) {
|
||||||
LIBSSH2_FREE(session, pubkey);
|
LIBSSH2_FREE(session, pubkey);
|
||||||
return _libssh2_error(session, LIBSSH2_ERROR_FILE,
|
return _libssh2_error(session, LIBSSH2_ERROR_FILE,
|
||||||
"Invalid public key data");
|
"Invalid public key data");
|
||||||
@@ -710,7 +710,7 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
|
|||||||
|
|
||||||
sp_len = sp1 > pubkey ? (sp1 - pubkey) : 0;
|
sp_len = sp1 > pubkey ? (sp1 - pubkey) : 0;
|
||||||
sp2 = memchr(sp1, ' ', pubkey_len - sp_len);
|
sp2 = memchr(sp1, ' ', pubkey_len - sp_len);
|
||||||
if(sp2 == NULL) {
|
if(!sp2) {
|
||||||
/* Assume that the id string is missing, but that it's okay */
|
/* Assume that the id string is missing, but that it's okay */
|
||||||
sp2 = pubkey + pubkey_len;
|
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);
|
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);
|
LIBSSH2_FREE(session, sig_info.sig_s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1305,7 +1305,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session,
|
|||||||
*key_method,
|
*key_method,
|
||||||
*key_method_len);
|
*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 */
|
/* no upgrading key algorithm supported, do nothing */
|
||||||
return LIBSSH2_ERROR_NONE;
|
return LIBSSH2_ERROR_NONE;
|
||||||
}
|
}
|
||||||
@@ -1383,7 +1383,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session,
|
|||||||
s = p ? (p + 1) : NULL;
|
s = p ? (p + 1) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(match != NULL) {
|
if(match) {
|
||||||
if(*key_method)
|
if(*key_method)
|
||||||
LIBSSH2_FREE(session, *key_method);
|
LIBSSH2_FREE(session, *key_method);
|
||||||
|
|
||||||
@@ -1923,7 +1923,7 @@ libssh2_userauth_publickey_frommemory(LIBSSH2_SESSION *session,
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if(NULL == passphrase)
|
if(!passphrase)
|
||||||
/* if given a NULL pointer, make it point to a zero-length
|
/* if given a NULL pointer, make it point to a zero-length
|
||||||
string to save us from having to check this all over */
|
string to save us from having to check this all over */
|
||||||
passphrase = "";
|
passphrase = "";
|
||||||
@@ -1951,7 +1951,7 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if(NULL == passphrase)
|
if(!passphrase)
|
||||||
/* if given a NULL pointer, make it point to a zero-length
|
/* if given a NULL pointer, make it point to a zero-length
|
||||||
string to save us from having to check this all over */
|
string to save us from having to check this all over */
|
||||||
passphrase = "";
|
passphrase = "";
|
||||||
|
|||||||
@@ -430,7 +430,7 @@ int start_openssh_fixture(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
have_docker = (getenv("OPENSSH_NO_DOCKER") == NULL);
|
have_docker = !getenv("OPENSSH_NO_DOCKER");
|
||||||
|
|
||||||
ret = build_openssh_server_docker_image();
|
ret = build_openssh_server_docker_image();
|
||||||
if(!ret) {
|
if(!ret) {
|
||||||
|
|||||||
@@ -33,10 +33,12 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
channel = libssh2_channel_open_session(session);
|
channel = libssh2_channel_open_session(session);
|
||||||
/* if(channel == NULL) { */
|
#if 0
|
||||||
/* printf("Error opening channel\n"); */
|
if(!channel) {
|
||||||
/* return 1; */
|
printf("Error opening channel\n");
|
||||||
/* } */
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
rc = libssh2_channel_request_auth_agent(channel);
|
rc = libssh2_channel_request_auth_agent(channel);
|
||||||
if(rc) {
|
if(rc) {
|
||||||
|
|||||||
Reference in New Issue
Block a user