diff options
author | Norbert Pocs <npocs@redhat.com> | 2021-08-04 09:22:08 +0200 |
---|---|---|
committer | Jakub Jelen <jjelen@redhat.com> | 2021-08-17 15:46:54 +0200 |
commit | a629f687cd070e404d9fe7d0ad0ada8cf119c5e1 (patch) | |
tree | 49f122d770551b493e526f278425f54f2c95ddce | |
parent | 2dda3514d1190ef6b6d45583641494eaaba5329e (diff) | |
download | libssh-a629f687cd070e404d9fe7d0ad0ada8cf119c5e1.tar.gz libssh-a629f687cd070e404d9fe7d0ad0ada8cf119c5e1.tar.xz libssh-a629f687cd070e404d9fe7d0ad0ada8cf119c5e1.zip |
Fix some compiler warnings
Covscan analyzer was used
Signed-off-by: Norbert Pocs <npocs@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 63f97a3d0301005568cf235eccb54610704666f6)
-rw-r--r-- | examples/libssh_scp.c | 2 | ||||
-rw-r--r-- | examples/sshd_direct-tcpip.c | 12 | ||||
-rw-r--r-- | src/getpass.c | 12 |
3 files changed, 22 insertions, 4 deletions
diff --git a/examples/libssh_scp.c b/examples/libssh_scp.c index 7a30b37f..7e086422 100644 --- a/examples/libssh_scp.c +++ b/examples/libssh_scp.c @@ -233,7 +233,7 @@ static int open_location(struct location *loc, int flag) { loc->file = fopen(loc->path, flag == READ ? "r":"w"); if (!loc->file) { if (errno == EISDIR) { - if (chdir(loc->path)) { + if (loc->path != NULL && chdir(loc->path)) { fprintf(stderr, "Error changing directory to %s: %s\n", loc->path, strerror(errno)); diff --git a/examples/sshd_direct-tcpip.c b/examples/sshd_direct-tcpip.c index 35898880..e8d5a6ce 100644 --- a/examples/sshd_direct-tcpip.c +++ b/examples/sshd_direct-tcpip.c @@ -88,7 +88,11 @@ cleanup_push(struct cleanup_node_struct** head_ref, // Allocate memory for node struct cleanup_node_struct *new_node = malloc(sizeof *new_node); - new_node->next = (*head_ref); + if (head_ref != NULL) { + new_node->next = *head_ref; + } else { + new_node->next = NULL; + } // Copy new_data new_node->data = new_data; @@ -514,6 +518,12 @@ message_callback(UNUSED_PARAM(ssh_session session), pFd = malloc(sizeof *pFd); cb_chan = malloc(sizeof *cb_chan); event_fd_data = malloc(sizeof *event_fd_data); + if (pFd == NULL || cb_chan == NULL || event_fd_data == NULL) { + SAFE_FREE(pFd); + SAFE_FREE(cb_chan); + SAFE_FREE(event_fd_data); + return 1; + } (*pFd) = socket_fd; event_fd_data->channel = channel; diff --git a/src/getpass.c b/src/getpass.c index 99627665..c00d0f54 100644 --- a/src/getpass.c +++ b/src/getpass.c @@ -255,7 +255,11 @@ int ssh_getpass(const char *prompt, /* disable nonblocking I/O */ if (fd & O_NDELAY) { - fcntl(0, F_SETFL, fd & ~O_NDELAY); + ok = fcntl(0, F_SETFL, fd & ~O_NDELAY); + if (ok < 0) { + perror("fcntl"); + return -1; + } } ok = ssh_gets(prompt, buf, len, verify); @@ -267,7 +271,11 @@ int ssh_getpass(const char *prompt, /* close fd */ if (fd & O_NDELAY) { - fcntl(0, F_SETFL, fd); + ok = fcntl(0, F_SETFL, fd); + if (ok < 0) { + perror("fcntl"); + return -1; + } } if (!ok) { |