aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiang Xiao <xiaoxiang@xiaomi.com>2021-05-09 23:53:28 +0800
committerAndreas Schneider <asn@cryptomilk.org>2021-05-27 13:45:47 +0200
commitd2182bb7af28894245fe877b4bef7340c8b0a009 (patch)
treebf8689cdfdbff9f762423b23439f5b81a7d3265c
parentae44d846b86d495e4e8d68a33bcc2532365e6ac5 (diff)
downloadlibssh-d2182bb7af28894245fe877b4bef7340c8b0a009.tar.gz
libssh-d2182bb7af28894245fe877b4bef7340c8b0a009.tar.xz
libssh-d2182bb7af28894245fe877b4bef7340c8b0a009.zip
Replace the hardcode max path length with PATH_MAX
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Change-Id: Icb1d36b48a759ec11dbaa4c09a39037a80ab0f85
-rw-r--r--examples/ssh_client.c3
-rw-r--r--include/libssh/priv.h5
-rw-r--r--src/auth.c2
-rw-r--r--src/scp.c8
-rw-r--r--tests/torture.c4
5 files changed, 12 insertions, 10 deletions
diff --git a/examples/ssh_client.c b/examples/ssh_client.c
index ec137436..aaf0cb5b 100644
--- a/examples/ssh_client.c
+++ b/examples/ssh_client.c
@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include <sys/select.h>
#include <sys/time.h>
@@ -297,7 +298,7 @@ static void shell(ssh_session session)
static void batch_shell(ssh_session session)
{
ssh_channel channel;
- char buffer[1024];
+ char buffer[PATH_MAX];
size_t i;
int s = 0;
diff --git a/include/libssh/priv.h b/include/libssh/priv.h
index b18ece4c..3e549b79 100644
--- a/include/libssh/priv.h
+++ b/include/libssh/priv.h
@@ -29,6 +29,7 @@
#ifndef _LIBSSH_PRIV_H
#define _LIBSSH_PRIV_H
+#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -167,6 +168,10 @@ int gettimeofday(struct timeval *__p, void *__t);
#include "libssh/callbacks.h"
/* some constants */
+#ifndef PATH_MAX
+# define PATH_MAX 4096
+#endif
+
#ifndef MAX_PACKET_LEN
#define MAX_PACKET_LEN 262144
#endif
diff --git a/src/auth.c b/src/auth.c
index fcf39b7a..001368ee 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -1103,7 +1103,7 @@ int ssh_userauth_publickey_auto(ssh_session session,
while (state->it != NULL) {
const char *privkey_file = state->it->data;
- char pubkey_file[1024] = {0};
+ char pubkey_file[PATH_MAX] = {0};
if (state->state == SSH_AUTH_AUTO_STATE_PUBKEY) {
SSH_LOG(SSH_LOG_DEBUG,
diff --git a/src/scp.c b/src/scp.c
index 85d670a4..946966ea 100644
--- a/src/scp.c
+++ b/src/scp.c
@@ -119,7 +119,7 @@ error:
int ssh_scp_init(ssh_scp scp)
{
int rc;
- char execbuffer[1024] = {0};
+ char execbuffer[PATH_MAX] = {0};
char *quoted_location = NULL;
size_t quoted_location_len = 0;
size_t scp_location_len;
@@ -319,7 +319,7 @@ void ssh_scp_free(ssh_scp scp)
*/
int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode)
{
- char buffer[1024] = {0};
+ char buffer[PATH_MAX] = {0};
int rc;
char *dir = NULL;
char *perms = NULL;
@@ -456,7 +456,7 @@ int ssh_scp_leave_directory(ssh_scp scp)
int ssh_scp_push_file64(ssh_scp scp, const char *filename, uint64_t size,
int mode)
{
- char buffer[1024] = {0};
+ char buffer[PATH_MAX] = {0};
int rc;
char *file = NULL;
char *perms = NULL;
@@ -769,7 +769,7 @@ int ssh_scp_read_string(ssh_scp scp, char *buffer, size_t len)
*/
int ssh_scp_pull_request(ssh_scp scp)
{
- char buffer[MAX_BUF_SIZE] = {0};
+ char buffer[PATH_MAX] = {0};
char *mode = NULL;
char *p, *tmp;
uint64_t size;
diff --git a/tests/torture.c b/tests/torture.c
index 61209185..3d9eb40d 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -63,10 +63,6 @@
#define TORTURE_SSHD_CONFIG "sshd/sshd_config"
#define TORTURE_PCAP_FILE "socket_trace.pcap"
-#ifndef PATH_MAX
-# define PATH_MAX 4096
-#endif
-
static const char torture_rsa_certauth_pub[]=
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCnA2n5vHzZbs/GvRkGloJNV1CXHI"
"S5Xnrm05HusUJSWyPq3I1iCMHdYA7oezHa9GCFYbIenaYPy+G6USQRjYQz8SvAZo06"