From d8220ddbfff365b03da338fafdd86878ae218395 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Wed, 22 Feb 2023 14:35:49 -0800 Subject: [PATCH] Fix a couple of warnings of errors in MSVC builds Two warnings (in tests & examples) in particular would cause problems: bad format causing invalid data output or a bad chdir due to out of scope buffer use. --- example/scp_nonblock.c | 1 - example/scp_write.c | 4 ++-- example/sftpdir.c | 2 +- example/sftpdir_nonblock.c | 2 +- example/ssh2_agent_forwarding.c | 1 - example/ssh2_echo.c | 2 +- example/ssh2_exec.c | 1 - src/bcrypt_pbkdf.c | 2 +- src/packet.c | 6 +++--- tests/session_fixture.c | 10 +++++----- 10 files changed, 14 insertions(+), 17 deletions(-) diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index bc5bdb3d..b8317a27 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -231,7 +231,6 @@ int main(int argc, char *argv[]) while(got < fileinfo.st_size) { char mem[1024*24]; - int rc; do { int amount = sizeof(mem); diff --git a/example/scp_write.c b/example/scp_write.c index 030232ec..150c5e47 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -48,10 +48,10 @@ int main(int argc, char *argv[]) size_t nread; char *ptr; struct stat fileinfo; + int err; #ifdef WIN32 WSADATA wsadata; - int err; err = WSAStartup(MAKEWORD(2, 0), &wsadata); if(err != 0) { @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) if(!channel) { char *errmsg; int errlen; - int err = libssh2_session_last_error(session, &errmsg, &errlen, 0); + err = libssh2_session_last_error(session, &errmsg, &errlen, 0); fprintf(stderr, "Unable to open a session: (%d) %s\n", err, errmsg); goto shutdown; } diff --git a/example/sftpdir.c b/example/sftpdir.c index 8fb16b1e..4b6af886 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -37,7 +37,7 @@ #include #ifdef WIN32 -#define __FILESIZE "I64" +#define __FILESIZE "I64u" #else #define __FILESIZE "llu" #endif diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index e9498d97..abc4ff48 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -37,7 +37,7 @@ #include #ifdef WIN32 -#define __FILESIZE "I64" +#define __FILESIZE "I64u" #else #define __FILESIZE "llu" #endif diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index b99fc95f..f86079d8 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -225,7 +225,6 @@ int main(int argc, char *argv[]) } for(;;) { /* loop until we block */ - int rc; do { char buffer[0x4000]; rc = libssh2_channel_read(channel, buffer, sizeof(buffer) ); diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index eae41656..937c438c 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -250,8 +250,8 @@ int main(int argc, char *argv[]) fds[0].events = LIBSSH2_POLLFD_POLLIN | LIBSSH2_POLLFD_POLLOUT; do { - int rc = (libssh2_poll(fds, 1, 10)); int act = 0; + rc = (libssh2_poll(fds, 1, 10)); if(rc < 1) continue; diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index d33c6d9a..1c11849e 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -254,7 +254,6 @@ int main(int argc, char *argv[]) } for(;;) { /* loop until we block */ - int rc; do { char buffer[0x4000]; rc = libssh2_channel_read(channel, buffer, sizeof(buffer) ); diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index 50d54209..822d1176 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -65,7 +65,7 @@ bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out) uint32_t cdata[BCRYPT_BLOCKS]; int i; uint16_t j; - size_t shalen = SHA512_DIGEST_LENGTH; + uint16_t shalen = SHA512_DIGEST_LENGTH; /* key expansion */ Blowfish_initstate(&state); diff --git a/src/packet.c b/src/packet.c index c3756a8e..40bd64c0 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1392,9 +1392,9 @@ _libssh2_packet_requirev(LIBSSH2_SESSION *session, if(strchr((char *) packet_types, ret)) { /* Be lazy, let packet_ask pull it out of the brigade */ - int ret = _libssh2_packet_askv(session, packet_types, data, - data_len, match_ofs, match_buf, - match_len); + ret = _libssh2_packet_askv(session, packet_types, data, + data_len, match_ofs, match_buf, + match_len); state->start = 0; return ret; } diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 82682d13..2d347007 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -81,6 +81,11 @@ static int connect_to_server(void) static void setup_fixture_workdir(void) { +#ifdef WIN32 + char wd_buf[_MAX_PATH]; +#else + char wd_buf[MAXPATHLEN]; +#endif char *wd = getenv("FIXTURE_WORKDIR"); #ifdef FIXTURE_WORKDIR if(!wd) { @@ -88,11 +93,6 @@ static void setup_fixture_workdir(void) } #endif if(!wd) { -#ifdef WIN32 - char wd_buf[_MAX_PATH]; -#else - char wd_buf[MAXPATHLEN]; -#endif getcwd(wd_buf, sizeof(wd_buf)); wd = wd_buf; }