SSH-AGENT

1. Replace strsep() with strtok_r() for portability with Win32.
2. Check return code from fopen as well as the provided fd.
3. Remove a redundant null check when using the agent to sign.
pull/269/head
John Safranek 2020-07-19 17:17:09 -07:00
parent 365d1fd8ea
commit c552af214e
No known key found for this signature in database
GPG Key ID: 8CE817DE0D3CCB4A
3 changed files with 14 additions and 13 deletions

View File

@ -1669,11 +1669,6 @@ int wolfSSH_AGENT_SignRequest(WOLFSSH* ssh,
ret = WS_BAD_ARGUMENT;
}
if (ret == WS_SUCCESS) {
if (agent == NULL)
ret = WS_AGENT_NULL_E;
}
if (ret == WS_SUCCESS) {
agent = ssh->agent;
if (ssh->ctx->agentCb)

View File

@ -1366,8 +1366,6 @@ char* wolfSSH_GetUsername(WOLFSSH* ssh)
#include <wolfssl/wolfcrypt/asn_public.h>
#include <wolfssl/wolfcrypt/coding.h>
#define WSTRDUP(x,y) strdup((x))
#define WSTRSEP(x,y) strsep((x),(y))
int wolfSSH_ReadKey_buffer(const byte* in, word32 inSz, int format,
byte** out, word32* outSz, const byte** outType, word32* outTypeSz,
void* heap)
@ -1381,8 +1379,8 @@ int wolfSSH_ReadKey_buffer(const byte* in, word32 inSz, int format,
return WS_BAD_ARGUMENT;
if (format == WOLFSSH_FORMAT_SSH) {
char* dup;
char* c;
char* last;
char* type;
char* key;
@ -1390,9 +1388,9 @@ int wolfSSH_ReadKey_buffer(const byte* in, word32 inSz, int format,
SSH format is:
type AAAABASE64ENCODEDKEYDATA comment
*/
c = dup = WSTRDUP((const char*)in, heap);
type = WSTRSEP(&c, " \n");
key = WSTRSEP(&c, " \n");
c = WSTRDUP((const char*)in, heap);
type = WSTRTOK(c, " \n", &last);
key = WSTRTOK(NULL, " \n", &last);
if (type != NULL && key != NULL) {
const char* name;
@ -1423,7 +1421,7 @@ int wolfSSH_ReadKey_buffer(const byte* in, word32 inSz, int format,
if (ret != 0)
ret = WS_ERROR;
WFREE(dup, heap, DYNTYPE_STRING);
WFREE(c, heap, DYNTYPE_STRING);
}
else if (format == WOLFSSH_FORMAT_ASN1) {
byte* newKey;
@ -1505,7 +1503,7 @@ int wolfSSH_ReadKey_file(const char* name,
return WS_BAD_ARGUMENT;
ret = WFOPEN(&file, name, "rb");
if (file == WBADFILE) return WS_BAD_FILE_E;
if (ret != 0 || file == WBADFILE) return WS_BAD_FILE_E;
if (WFSEEK(file, 0, WSEEK_END) != 0) {
WFCLOSE(file);
return WS_BAD_FILE_E;

View File

@ -307,18 +307,24 @@ extern "C" {
#define WSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
#define WSNPRINTF(s,n,f,...) _snprintf_s((s),(n),(n),(f),##__VA_ARGS__)
#define WVSNPRINTF(s,n,f,...) _vsnprintf_s((s),(n),(n),(f),##__VA_ARGS__)
#define WSTRTOK(s1,s2,s3) strtok_s((s1),(s2),(s3))
#define WSTRDUP(s,h) _strdup((s))
#elif defined(MICROCHIP_MPLAB_HARMONY) || defined(MICROCHIP_PIC32)
#include <stdio.h>
#define WSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
#define WSTRNCASECMP(s1, s2, n) strncmp((s1), (s2), (n))
#define WSNPRINTF(s,n,f,...) snprintf((s),(n),(f),##__VA_ARGS__)
#define WVSNPRINTF(s,n,f,...) vsnprintf((s),(n),(f),##__VA_ARGS__)
#define WSTRTOK(s1,s2,s3) strtok_r((s1),(s2),(s3))
#define WSTRDUP(s,h) strdup((s))
#elif defined(RENESAS_CSPLUS)
#include <stdio.h>
#define WSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
#define WSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
#define WSNPRINTF(s,n,f,...) snprintf((s),(n),(f),__VA_ARGS__)
#define WVSNPRINTF(s,n,f,...) vsnprintf((s),(n),(f),__VA_ARGS__)
#define WSTRTOK(s1,s2,s3) strtok_r((s1),(s2),(s3))
#define WSTRDUP(s,h) strdup((s))
#else
#ifndef FREESCALE_MQX
#include <stdio.h>
@ -327,6 +333,8 @@ extern "C" {
#define WSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
#define WSNPRINTF(s,n,f,...) snprintf((s),(n),(f),##__VA_ARGS__)
#define WVSNPRINTF(s,n,f,...) vsnprintf((s),(n),(f),##__VA_ARGS__)
#define WSTRTOK(s1,s2,s3) strtok_r((s1),(s2),(s3))
#define WSTRDUP(s,h) strdup((s))
#endif
#endif /* WSTRING_USER */