Skip to content

Commit

Permalink
lib: fix various compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bagder committed Mar 17, 2019
1 parent 0a140b7 commit bd5a620
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 80 deletions.
6 changes: 3 additions & 3 deletions src/channel.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (c) 2004-2007 Sara Golemon <[email protected]>
* Copyright (c) 2005 Mikhail Gusarov <[email protected]>
* Copyright (c) 2008-2014 by Daniel Stenberg
* Copyright (c) 2008-2019 by Daniel Stenberg
*
* All rights reserved.
*
Expand Down Expand Up @@ -1180,7 +1180,7 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,

_libssh2_random(buffer, LIBSSH2_X11_RANDOM_COOKIE_LEN / 2);
for(i = 0; i < (LIBSSH2_X11_RANDOM_COOKIE_LEN / 2); i++) {
snprintf((char *)&s[i*2], 3, "%02X%c", buffer[i], '\0');
snprintf((char *)&s[i*2], 3, "%02X", buffer[i]);
}
}
s += cookie_len;
Expand Down Expand Up @@ -1439,7 +1439,7 @@ _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid)
&& ((packet->data_len >= 5)
&& (_libssh2_ntohu32(packet->data + 1) == channel->local.id))) {
/* It's our channel at least */
unsigned int packet_stream_id;
int packet_stream_id;

if(packet_type == SSH_MSG_CHANNEL_DATA) {
packet_stream_id = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/crypto.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (C) 2009, 2010 Simon Josefsson
* Copyright (C) 2006, 2007 The Written Word, Inc. All rights reserved.
* Copyright (C) 2010 Daniel Stenberg
* Copyright (C) 2010-2019 Daniel Stenberg
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
Expand Down Expand Up @@ -233,4 +233,4 @@ int _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
size_t privatekeydata_len,
const char *passphrase);

#endif
#endif
48 changes: 26 additions & 22 deletions src/hostkey.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2004-2006, Sara Golemon <[email protected]>
* Copyright (c) 2009-2014 by Daniel Stenberg
* Copyright (c) 2009-2019 by Daniel Stenberg
* All rights reserved.
*
* Redistribution and use in source and binary forms,
Expand Down Expand Up @@ -66,7 +66,7 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session,
libssh2_rsa_ctx *rsactx;
unsigned char *e, *n;
int e_len, n_len;
struct string_buf buf = { .len = 0, .offset = 0 };
struct string_buf buf;

if(*abstract) {
hostkey_method_ssh_rsa_dtor(session, abstract);
Expand All @@ -79,6 +79,7 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session,
return -1;
}

buf.offset = 0;
buf.data = (unsigned char*)hostkey_data;
buf.dataptr = buf.data;
buf.len = hostkey_data_len;
Expand All @@ -88,7 +89,7 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session,

if((e_len = _libssh2_get_c_string(&buf, &e)) <= 0)
return -1;

if((n_len = _libssh2_get_c_string(&buf, &n)) <= 0)
return -1;

Expand Down Expand Up @@ -284,8 +285,8 @@ hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session,
libssh2_dsa_ctx *dsactx;
unsigned char *p, *q, *g, *y;
int p_len, q_len, g_len, y_len;
struct string_buf buf = { .len = 0, .offset = 0 };
struct string_buf buf;

if(*abstract) {
hostkey_method_ssh_dss_dtor(session, abstract);
*abstract = NULL;
Expand All @@ -296,23 +297,24 @@ hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session,
"host key length too short");
return -1;
}


buf.offset = 0;
buf.data = (unsigned char*)hostkey_data;
buf.dataptr = buf.data;
buf.len = hostkey_data_len;

if(_libssh2_match_string(&buf, "ssh-dss") != 0)
return -1;

if((p_len = _libssh2_get_c_string(&buf, &p)) < 0)
return -1;

if((q_len = _libssh2_get_c_string(&buf, &q)) < 0)
return -1;

if((g_len = _libssh2_get_c_string(&buf, &g)) < 0)
return -1;

if((y_len = _libssh2_get_c_string(&buf, &y)) < 0)
return -1;

Expand Down Expand Up @@ -409,7 +411,7 @@ hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION * session,

sig += 15;
sig_len -= 15;

return _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len);
}

Expand Down Expand Up @@ -508,7 +510,7 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session,
unsigned char *type_str, *domain, *public_key;
int key_len;
libssh2_curve_type type;
struct string_buf buf = { .len = 0, .offset = 0 };
struct string_buf buf;

if(abstract != NULL && *abstract) {
hostkey_method_ssh_ecdsa_dtor(session, abstract);
Expand All @@ -521,13 +523,14 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session,
return -1;
}

buf.offset = 0;
buf.data = (unsigned char*)hostkey_data;
buf.dataptr = buf.data;
buf.len = hostkey_data_len;

if(_libssh2_get_c_string(&buf, &type_str) != 19)
return -1;

if (strncmp((char*) type_str, "ecdsa-sha2-nistp256", 19) == 0 ){
type = LIBSSH2_EC_CURVE_NISTP256;
}else if(strncmp((char*) type_str, "ecdsa-sha2-nistp384", 19) == 0 ){
Expand All @@ -537,18 +540,18 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session,
}else{
return -1;
}

if(_libssh2_get_c_string(&buf, &domain) != 8)
return -1;

if ( type == LIBSSH2_EC_CURVE_NISTP256 && strncmp((char*)domain, "nistp256", 8) != 0){
return -1;
}else if ( type == LIBSSH2_EC_CURVE_NISTP384 && strncmp((char*)domain, "nistp384", 8) != 0){
return -1;
}else if ( type == LIBSSH2_EC_CURVE_NISTP521 && strncmp((char*)domain, "nistp521", 8) != 0){
return -1;
}

/* public key */
if((key_len = _libssh2_get_c_string(&buf, &public_key)) <= 0)
return -1;
Expand Down Expand Up @@ -636,7 +639,7 @@ hostkey_method_ssh_ecdsa_sig_verify(LIBSSH2_SESSION * session,
{
unsigned char *r, *s, *name;
unsigned int r_len, s_len, len;
struct string_buf buf = { .len = 0, .offset = 0 };
struct string_buf buf;
libssh2_ecdsa_ctx *ctx = (libssh2_ecdsa_ctx *) (*abstract);

(void) session;
Expand All @@ -645,19 +648,20 @@ hostkey_method_ssh_ecdsa_sig_verify(LIBSSH2_SESSION * session,
return -1;

/* keyname_len(4) + keyname(19){"ecdsa-sha2-nistp256"} + signature_len(4) */
buf.offset = 0;
buf.data = (unsigned char*)sig;
buf.dataptr = buf.data;
buf.len = sig_len;

if(_libssh2_get_c_string(&buf, &name) != 19)
return -1;

if(_libssh2_get_u32(&buf, &len) != 0 || len < 8)
return -1;

if((r_len = _libssh2_get_c_string(&buf, &r)) <= 0)
return -1;

if((s_len = _libssh2_get_c_string(&buf, &s)) <= 0)
return -1;

Expand Down Expand Up @@ -815,7 +819,7 @@ hostkey_method_ssh_ed25519_init(LIBSSH2_SESSION * session,

s += 11;

//public key
/* public key */
key_len = _libssh2_ntohu32(s);
s += 4;

Expand Down
Loading

0 comments on commit bd5a620

Please sign in to comment.