summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-04-17 19:00:15 +0200
committerDaniel Stenberg <daniel@haxx.se>2021-04-17 19:02:03 +0200
commit7a7c2ddd9eb01d0b281e7ee77ff84440fb582576 (patch)
tree12b609bb5901ad537b75b5de5fd1190bbee9e218
parent6fc805d0c1f82363836f1c6199cebdd3c41cbc5b (diff)
downloadcurl-bagder/libssh-break.tar.gz
libssh: fix "empty expression statement has no effect" warningsbagder/libssh-break
... by fixing macros to do-while constructs and moving out the calls to "break" outside of the actual macro. It also fixes the problem where the macro was used witin a loop and the break didn't do right. Reported-by: Emil Engler Fixes #6847
-rw-r--r--lib/vssh/libssh.c102
1 files changed, 63 insertions, 39 deletions
diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c
index 4644f4cb9..55f88f19a 100644
--- a/lib/vssh/libssh.c
+++ b/lib/vssh/libssh.c
@@ -549,49 +549,48 @@ cleanup:
return rc;
}
-#define MOVE_TO_ERROR_STATE(_r) { \
- state(data, SSH_SESSION_DISCONNECT); \
- sshc->actualcode = _r; \
- rc = SSH_ERROR; \
- break; \
-}
+#define MOVE_TO_ERROR_STATE(_r) do { \
+ state(data, SSH_SESSION_DISCONNECT); \
+ sshc->actualcode = _r; \
+ rc = SSH_ERROR; \
+ } while(0)
-#define MOVE_TO_SFTP_CLOSE_STATE() { \
- state(data, SSH_SFTP_CLOSE); \
- sshc->actualcode = sftp_error_to_CURLE(sftp_get_error(sshc->sftp_session)); \
- rc = SSH_ERROR; \
- break; \
-}
+#define MOVE_TO_SFTP_CLOSE_STATE() do { \
+ state(data, SSH_SFTP_CLOSE); \
+ sshc->actualcode = \
+ sftp_error_to_CURLE(sftp_get_error(sshc->sftp_session)); \
+ rc = SSH_ERROR; \
+ } while(0)
-#define MOVE_TO_LAST_AUTH \
- if(sshc->auth_methods & SSH_AUTH_METHOD_PASSWORD) { \
- rc = SSH_OK; \
- state(data, SSH_AUTH_PASS_INIT); \
- break; \
- } \
- else { \
- MOVE_TO_ERROR_STATE(CURLE_LOGIN_DENIED); \
- }
+#define MOVE_TO_LAST_AUTH do { \
+ if(sshc->auth_methods & SSH_AUTH_METHOD_PASSWORD) { \
+ rc = SSH_OK; \
+ state(data, SSH_AUTH_PASS_INIT); \
+ } \
+ else { \
+ MOVE_TO_ERROR_STATE(CURLE_LOGIN_DENIED); \
+ } \
+ } while(0)
-#define MOVE_TO_TERTIARY_AUTH \
- if(sshc->auth_methods & SSH_AUTH_METHOD_INTERACTIVE) { \
- rc = SSH_OK; \
- state(data, SSH_AUTH_KEY_INIT); \
- break; \
- } \
- else { \
- MOVE_TO_LAST_AUTH; \
- }
+#define MOVE_TO_TERTIARY_AUTH do { \
+ if(sshc->auth_methods & SSH_AUTH_METHOD_INTERACTIVE) { \
+ rc = SSH_OK; \
+ state(data, SSH_AUTH_KEY_INIT); \
+ } \
+ else { \
+ MOVE_TO_LAST_AUTH; \
+ } \
+ } while(0)
-#define MOVE_TO_SECONDARY_AUTH \
- if(sshc->auth_methods & SSH_AUTH_METHOD_GSSAPI_MIC) { \
- rc = SSH_OK; \
- state(data, SSH_AUTH_GSSAPI); \
- break; \
- } \
- else { \
- MOVE_TO_TERTIARY_AUTH; \
- }
+#define MOVE_TO_SECONDARY_AUTH do { \
+ if(sshc->auth_methods & SSH_AUTH_METHOD_GSSAPI_MIC) { \
+ rc = SSH_OK; \
+ state(data, SSH_AUTH_GSSAPI); \
+ } \
+ else { \
+ MOVE_TO_TERTIARY_AUTH; \
+ } \
+ } while(0)
static
int myssh_auth_interactive(struct connectdata *conn)
@@ -704,6 +703,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
if(rc != SSH_OK) {
failf(data, "Failure establishing ssh session");
MOVE_TO_ERROR_STATE(CURLE_FAILED_INIT);
+ break;
}
state(data, SSH_HOSTKEY);
@@ -714,6 +714,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
rc = myssh_is_known(data);
if(rc != SSH_OK) {
MOVE_TO_ERROR_STATE(CURLE_PEER_FAILED_VERIFICATION);
+ break;
}
state(data, SSH_AUTHLIST);
@@ -735,6 +736,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
}
else if(rc == SSH_AUTH_ERROR) {
MOVE_TO_ERROR_STATE(CURLE_LOGIN_DENIED);
+ break;
}
sshc->auth_methods = ssh_userauth_list(sshc->ssh_session, NULL);
@@ -753,6 +755,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
}
else { /* unsupported authentication method */
MOVE_TO_ERROR_STATE(CURLE_LOGIN_DENIED);
+ break;
}
break;
@@ -760,6 +763,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
case SSH_AUTH_PKEY_INIT:
if(!(data->set.ssh_auth_types & CURLSSH_AUTH_PUBLICKEY)) {
MOVE_TO_SECONDARY_AUTH;
+ break;
}
/* Two choices, (1) private key was given on CMD,
@@ -775,6 +779,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
if(rc != SSH_OK) {
MOVE_TO_SECONDARY_AUTH;
+ break;
}
}
@@ -833,6 +838,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
case SSH_AUTH_GSSAPI:
if(!(data->set.ssh_auth_types & CURLSSH_AUTH_GSSAPI)) {
MOVE_TO_TERTIARY_AUTH;
+ break;
}
rc = ssh_userauth_gssapi(sshc->ssh_session);
@@ -879,6 +885,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
if(!(data->set.ssh_auth_types & CURLSSH_AUTH_PASSWORD)) {
/* Host key authentication is intentionally not implemented */
MOVE_TO_ERROR_STATE(CURLE_LOGIN_DENIED);
+ break;
}
state(data, SSH_AUTH_PASS);
/* FALLTHROUGH */
@@ -953,6 +960,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
sshc->homedir = sftp_canonicalize_path(sshc->sftp_session, ".");
if(sshc->homedir == NULL) {
MOVE_TO_ERROR_STATE(CURLE_COULDNT_CONNECT);
+ break;
}
data->state.most_recent_ftp_entrypath = sshc->homedir;
@@ -1213,6 +1221,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
if(size < 0) {
failf(data, "Bad file size (%" CURL_FORMAT_CURL_OFF_T ")", size);
MOVE_TO_ERROR_STATE(CURLE_BAD_DOWNLOAD_RESUME);
+ break;
}
data->state.resume_from = attrs->size;
@@ -1254,6 +1263,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
}
else {
MOVE_TO_SFTP_CLOSE_STATE();
+ break;
}
}
@@ -1292,8 +1302,11 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
CURL_READFUNC_ABORT return code still aborts */
failf(data, "Failed to read data");
MOVE_TO_ERROR_STATE(CURLE_FTP_COULDNT_USE_REST);
+ break;
}
} while(passed < data->state.resume_from);
+ if(rc)
+ break;
}
/* now, decrease the size of the read */
@@ -1306,6 +1319,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
rc = sftp_seek64(sshc->sftp_file, data->state.resume_from);
if(rc != 0) {
MOVE_TO_SFTP_CLOSE_STATE();
+ break;
}
}
if(data->state.infilesize > 0) {
@@ -1375,6 +1389,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
(err != SSH_FX_FAILURE) &&
(err != SSH_FX_PERMISSION_DENIED)) {
MOVE_TO_SFTP_CLOSE_STATE();
+ break;
}
rc = 0; /* clear rc and continue */
}
@@ -1398,6 +1413,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
failf(data, "Could not open directory for reading: %s",
ssh_get_error(sshc->ssh_session));
MOVE_TO_SFTP_CLOSE_STATE();
+ break;
}
state(data, SSH_SFTP_READDIR);
break;
@@ -1491,6 +1507,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
failf(data, "Could not read symlink for reading: %s",
ssh_get_error(sshc->ssh_session));
MOVE_TO_SFTP_CLOSE_STATE();
+ break;
}
if(sshc->readdir_link_attrs->name == NULL) {
@@ -1586,6 +1603,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
ssh_get_error(sshc->ssh_session));
MOVE_TO_SFTP_CLOSE_STATE();
+ break;
}
state(data, SSH_SFTP_DOWNLOAD_STAT);
@@ -1663,6 +1681,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
rc = sftp_seek64(sshc->sftp_file, from);
if(rc != 0) {
MOVE_TO_SFTP_CLOSE_STATE();
+ break;
}
}
data->req.size = size;
@@ -1701,6 +1720,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
rc = sftp_seek64(sshc->sftp_file, data->state.resume_from);
if(rc != 0) {
MOVE_TO_SFTP_CLOSE_STATE();
+ break;
}
}
}
@@ -1795,6 +1815,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
failf(data, "SCP requires a known file size for upload");
sshc->actualcode = CURLE_UPLOAD_FAILED;
MOVE_TO_ERROR_STATE(CURLE_UPLOAD_FAILED);
+ break;
}
sshc->scp_session =
@@ -1822,6 +1843,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
err_msg = ssh_get_error(sshc->ssh_session);
failf(data, "%s", err_msg);
MOVE_TO_ERROR_STATE(CURLE_UPLOAD_FAILED);
+ break;
}
rc = ssh_scp_push_file(sshc->scp_session, protop->path,
@@ -1831,6 +1853,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
err_msg = ssh_get_error(sshc->ssh_session);
failf(data, "%s", err_msg);
MOVE_TO_ERROR_STATE(CURLE_UPLOAD_FAILED);
+ break;
}
/* upload data */
@@ -1859,6 +1882,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
err_msg = ssh_get_error(sshc->ssh_session);
failf(data, "%s", err_msg);
MOVE_TO_ERROR_STATE(CURLE_COULDNT_CONNECT);
+ break;
}
state(data, SSH_SCP_DOWNLOAD);
/* FALLTHROUGH */