From 7fa60c4943c27902f32b3b0b034ce8b20615d9f7 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Tue, 5 Mar 2024 14:41:20 -0800 Subject: [PATCH] SCP File Modes 1. Add a mask for the POSIX file modes. 2. Mask out the file mode bits when setting the C or D command for SCP. --- src/wolfscp.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/wolfscp.c b/src/wolfscp.c index d51912cfc..c50be7063 100644 --- a/src/wolfscp.c +++ b/src/wolfscp.c @@ -57,6 +57,8 @@ static int ScpPushDir(void *fs, ScpSendCtx* ctx, const char* path, void* heap); static int ScpPopDir(void *fs, ScpSendCtx* ctx, void* heap); #endif +#define WOLFSSH_MODE_MASK 0777 + const char scpError[] = "scp error: %s, %d"; const char scpState[] = "scp state: %s"; @@ -315,7 +317,8 @@ static int SendScpFileHeader(WOLFSSH* ssh) #ifndef WSCPFILEHDR WMEMSET(buf, 0, sizeof(buf)); WSNPRINTF(buf, sizeof(buf), "C%04o %u %s\n", - ssh->scpFileMode, ssh->scpFileSz, ssh->scpFileName); + ssh->scpFileMode & WOLFSSH_MODE_MASK, + ssh->scpFileSz, ssh->scpFileName); filehdr = buf; #else filehdr = WSCPFILEHDR(ssh); @@ -350,8 +353,9 @@ static int SendScpEnterDirectory(WOLFSSH* ssh) WMEMSET(buf, 0, sizeof(buf)); - WSNPRINTF(buf, sizeof(buf), "D%04o 0 %s\n", ssh->scpFileMode, - ssh->scpFileName); + WSNPRINTF(buf, sizeof(buf), "D%04o 0 %s\n", + ssh->scpFileMode & WOLFSSH_MODE_MASK, + ssh->scpFileName); bufSz = (int)WSTRLEN(buf);