mirror of https://github.com/wolfSSL/wolfssh.git
commit
c050a8365a
|
@ -39,7 +39,6 @@
|
|||
<ClCompile Include="..\..\..\src\io.c" />
|
||||
<ClCompile Include="..\..\..\src\keygen.c" />
|
||||
<ClCompile Include="..\..\..\src\log.c" />
|
||||
<ClCompile Include="..\..\..\src\memory.c" />
|
||||
<ClCompile Include="..\..\..\src\port.c" />
|
||||
<ClCompile Include="..\..\..\src\ssh.c" />
|
||||
<ClCompile Include="..\..\..\src\wolfsftp.c" />
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
lib_LTLIBRARIES += src/libwolfssh.la
|
||||
src_libwolfssh_la_SOURCES = src/ssh.c \
|
||||
src/internal.c \
|
||||
src/memory.c \
|
||||
src/log.c \
|
||||
src/io.c \
|
||||
src/port.c
|
||||
|
|
|
@ -544,7 +544,7 @@ void SshResourceFree(WOLFSSH* ssh, void* heap)
|
|||
}
|
||||
if (ssh->scpFileBuffer) {
|
||||
ForceZero(ssh->scpFileBuffer, ssh->scpFileBufferSz);
|
||||
WFREE(ssh->scpFileBuffer, ssh->ctx->heap, DYNTYPE_BUFFFER);
|
||||
WFREE(ssh->scpFileBuffer, ssh->ctx->heap, DYNTYPE_BUFFER);
|
||||
ssh->scpFileBuffer = NULL;
|
||||
ssh->scpFileBufferSz = 0;
|
||||
}
|
||||
|
|
109
src/memory.c
109
src/memory.c
|
@ -1,109 +0,0 @@
|
|||
/* memory.c
|
||||
*
|
||||
* Copyright (C) 2014-2016 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSH.
|
||||
*
|
||||
* wolfSSH is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSH is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* The memory module contains the interface to the custom memory handling hooks.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <wolfssh/settings.h>
|
||||
|
||||
|
||||
#ifdef USE_WOLFSSH_MEMORY
|
||||
|
||||
#include <wolfssh/memory.h>
|
||||
#include <wolfssh/error.h>
|
||||
|
||||
/* Set these to default values initially. */
|
||||
static wolfSSH_Malloc_cb malloc_function = NULL;
|
||||
static wolfSSH_Free_cb free_function = NULL;
|
||||
static wolfSSH_Realloc_cb realloc_function = NULL;
|
||||
|
||||
|
||||
/* set wolfSSH allocator callbacks, 0 on success */
|
||||
int wolfSSH_SetAllocators(wolfSSH_Malloc_cb mf,
|
||||
wolfSSH_Free_cb ff,
|
||||
wolfSSH_Realloc_cb rf)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
if (mf)
|
||||
malloc_function = mf;
|
||||
else
|
||||
res = WS_BAD_ARGUMENT;
|
||||
|
||||
if (ff)
|
||||
free_function = ff;
|
||||
else
|
||||
res = WS_BAD_ARGUMENT;
|
||||
|
||||
if (rf)
|
||||
realloc_function = rf;
|
||||
else
|
||||
res = WS_BAD_ARGUMENT;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/* our malloc handler */
|
||||
void* wolfSSH_Malloc(size_t size)
|
||||
{
|
||||
void* res = 0;
|
||||
|
||||
if (malloc_function)
|
||||
res = malloc_function(size);
|
||||
else
|
||||
res = malloc(size);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/* our free handler */
|
||||
void wolfSSH_Free(void *ptr)
|
||||
{
|
||||
if (free_function)
|
||||
free_function(ptr);
|
||||
else
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
|
||||
/* our realloc handler */
|
||||
void* wolfSSH_Realloc(void *ptr, size_t size)
|
||||
{
|
||||
void* res = 0;
|
||||
|
||||
if (realloc_function)
|
||||
res = realloc_function(ptr, size);
|
||||
else
|
||||
res = realloc(ptr, size);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif /* USE_WOLFSSH_MEMORY */
|
||||
|
|
@ -1092,7 +1092,7 @@ int wolfSSH_SetUsername(WOLFSSH* ssh, const char* username)
|
|||
if (ret == WS_SUCCESS) {
|
||||
WSTRNCPY(value, username, valueSz + 1);
|
||||
if (ssh->userName != NULL) {
|
||||
WFREE(ssh->userName, heap, DYNTYPE_STRING);
|
||||
WFREE(ssh->userName, ssh->ctx->heap, DYNTYPE_STRING);
|
||||
ssh->userName = NULL;
|
||||
}
|
||||
ssh->userName = value;
|
||||
|
|
|
@ -171,7 +171,7 @@ int DoScpSink(WOLFSSH* ssh)
|
|||
ssh->scpFileOffset += ssh->scpFileBufferSz;
|
||||
|
||||
/* shrink and reset recv buffer */
|
||||
WFREE(ssh->scpFileBuffer, ssh->ctx->heap, DYNTYPE_BUFFFER);
|
||||
WFREE(ssh->scpFileBuffer, ssh->ctx->heap, DYNTYPE_BUFFER);
|
||||
ssh->scpFileBuffer = NULL;
|
||||
ssh->scpFileBufferSz = 0;
|
||||
|
||||
|
|
|
@ -1368,7 +1368,7 @@ int wolfSSH_SFTP_RecvRMDIR(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
|
|||
|
||||
if (wolfSSH_SFTP_CreateStatus(ssh, type, reqId, res, "English", out,
|
||||
&outSz) != WS_SUCCESS) {
|
||||
WFREE(out, ssh->ctx->heap, DYNTPE_BUFFER);
|
||||
WFREE(out, ssh->ctx->heap, DYNTYPE_BUFFER);
|
||||
return WS_FATAL_ERROR;
|
||||
}
|
||||
wolfSSH_SFTP_RecvSetSend(ssh, out, outSz);
|
||||
|
@ -5392,7 +5392,7 @@ int wolfSSH_SFTP_SetSTAT(WOLFSSH* ssh, char* dir, WS_SFTP_FILEATRB* atr)
|
|||
ret = WS_FATAL_ERROR;
|
||||
break;
|
||||
}
|
||||
XFREE(state->data, ssh->ctx->heap, DYNTYPE_BUFER);
|
||||
XFREE(state->data, ssh->ctx->heap, DYNTYPE_BUFFER);
|
||||
state->data = (byte*)WMALLOC(maxSz, ssh->ctx->heap, DYNTYPE_BUFFER);
|
||||
if (state->data == NULL) {
|
||||
ret = WS_MEMORY_E;
|
||||
|
|
|
@ -407,7 +407,7 @@ static int test_Errors(void)
|
|||
/* Check that all errors have a string and it's the same through the two
|
||||
* APIs. Check that the values that are not errors map to the unknown
|
||||
* string. */
|
||||
for (i = WS_SUCCESS; i >= WS_LAST_E; i--) {
|
||||
for (i = WS_FATAL_ERROR; i >= WS_LAST_E; i--) {
|
||||
errStr = wolfSSH_ErrorToName(i);
|
||||
|
||||
if (j < missingSz && i == missing[j]) {
|
||||
|
|
138
wolfssh/error.h
138
wolfssh/error.h
|
@ -37,76 +37,76 @@ extern "C" {
|
|||
|
||||
/* main public return values */
|
||||
enum WS_ErrorCodes {
|
||||
WS_SUCCESS = 0, /* function success */
|
||||
WS_FATAL_ERROR = -1, /* general function failure */
|
||||
WS_BAD_ARGUMENT = -2, /* bad function argument */
|
||||
WS_MEMORY_E = -3, /* memory allocation failure */
|
||||
WS_BUFFER_E = -4, /* input/output buffer size error */
|
||||
WS_PARSE_E = -5, /* general parsing error */
|
||||
WS_NOT_COMPILED = -6, /* feature not compiled in */
|
||||
WS_OVERFLOW_E = -7, /* would overflow if continued */
|
||||
WS_BAD_USAGE = -8, /* bad example usage */
|
||||
WS_SOCKET_ERROR_E = -9,
|
||||
WS_WANT_READ = -10,
|
||||
WS_WANT_WRITE = -11,
|
||||
WS_RECV_OVERFLOW_E = -12,
|
||||
WS_VERSION_E = -13, /* Peer using wrong version of SSH */
|
||||
WS_SEND_OOB_READ_E = -14,
|
||||
WS_INPUT_CASE_E = -15,
|
||||
WS_BAD_FILETYPE_E = -16,
|
||||
WS_UNIMPLEMENTED_E = -17,
|
||||
WS_RSA_E = -18,
|
||||
WS_BAD_FILE_E = -19,
|
||||
WS_INVALID_ALGO_ID = -20,
|
||||
WS_DECRYPT_E = -21,
|
||||
WS_ENCRYPT_E = -22,
|
||||
WS_VERIFY_MAC_E = -23,
|
||||
WS_CREATE_MAC_E = -24,
|
||||
WS_RESOURCE_E = -25, /* insufficient resources for new channel */
|
||||
WS_INVALID_CHANTYPE = -26, /* invalid channel type */
|
||||
WS_INVALID_CHANID = -27,
|
||||
WS_INVALID_USERNAME = -28,
|
||||
WS_CRYPTO_FAILED = -29, /* crypto action failed */
|
||||
WS_INVALID_STATE_E = -30,
|
||||
WS_EOF = -31,
|
||||
WS_INVALID_PRIME_CURVE = -32,
|
||||
WS_ECC_E = -33,
|
||||
WS_CHANOPEN_FAILED = -34,
|
||||
WS_REKEYING = -35, /* Status: rekey in progress */
|
||||
WS_CHANNEL_CLOSED = -36, /* Status: channel closed */
|
||||
WS_INVALID_PATH_E = -37,
|
||||
WS_SCP_CMD_E = -38,
|
||||
WS_SCP_BAD_MSG_E = -39,
|
||||
WS_SCP_PATH_LEN_E = -40,
|
||||
WS_SCP_TIMESTAMP_E = -41,
|
||||
WS_SCP_DIR_STACK_EMPTY_E = -42,
|
||||
WS_SCP_CONTINUE = -43,
|
||||
WS_SCP_ABORT = -44,
|
||||
WS_SCP_ENTER_DIR = -45,
|
||||
WS_SCP_EXIT_DIR = -46,
|
||||
WS_SCP_EXIT_DIR_FINAL = -47,
|
||||
WS_SCP_COMPLETE = -48, /* SCP transfer complete */
|
||||
WS_SCP_INIT = -49, /* SCP transfer verified */
|
||||
WS_MATCH_KEX_ALGO_E = -50, /* cannot match KEX algo with peer */
|
||||
WS_MATCH_KEY_ALGO_E = -51, /* cannot match key algo with peer */
|
||||
WS_MATCH_ENC_ALGO_E = -52, /* cannot match encrypt algo with peer */
|
||||
WS_MATCH_MAC_ALGO_E = -53, /* cannot match MAC algo with peer */
|
||||
WS_PERMISSIONS = -54,
|
||||
WS_SFTP_COMPLETE = -55, /* SFTP connection established */
|
||||
WS_NEXT_ERROR = -56, /* Getting next value/state results in error */
|
||||
WS_CHAN_RXD = -57, /* Status that channel data received. */
|
||||
WS_INVALID_EXTDATA = -58, /* invalid Channel Extended Data Type */
|
||||
WS_CHAN_PENDING = -59, /* peer hasn't confirmed channel open */
|
||||
WS_SFTP_BAD_REQ_ID = -60, /* SFTP Bad request ID */
|
||||
WS_SFTP_BAD_REQ_TYPE = -61, /* SFTP Bad request ID */
|
||||
WS_SFTP_STATUS_NOT_OK = -62, /* SFTP Status not OK */
|
||||
WS_SFTP_FILE_DNE = -63, /* SFTP File Does Not Exist */
|
||||
WS_SIZE_ONLY = -64, /* Only getting the size of buffer needed */
|
||||
WS_CLOSE_FILE_E = -65, /* Unable to close local file */
|
||||
WS_PUBKEY_REJECTED_E = -66, /* Server public key rejected */
|
||||
WS_EXTDATA = -67, /* Extended Data available to be read */
|
||||
WS_SUCCESS = 0, /* function success */
|
||||
WS_FATAL_ERROR = -1001, /* general function failure */
|
||||
WS_BAD_ARGUMENT = -1002, /* bad function argument */
|
||||
WS_MEMORY_E = -1003, /* memory allocation failure */
|
||||
WS_BUFFER_E = -1004, /* input/output buffer size error */
|
||||
WS_PARSE_E = -1005, /* general parsing error */
|
||||
WS_NOT_COMPILED = -1006, /* feature not compiled in */
|
||||
WS_OVERFLOW_E = -1007, /* would overflow if continued */
|
||||
WS_BAD_USAGE = -1008, /* bad example usage */
|
||||
WS_SOCKET_ERROR_E = -1009,
|
||||
WS_WANT_READ = -1010,
|
||||
WS_WANT_WRITE = -1011,
|
||||
WS_RECV_OVERFLOW_E = -1012,
|
||||
WS_VERSION_E = -1013, /* Peer using wrong version of SSH */
|
||||
WS_SEND_OOB_READ_E = -1014,
|
||||
WS_INPUT_CASE_E = -1015,
|
||||
WS_BAD_FILETYPE_E = -1016,
|
||||
WS_UNIMPLEMENTED_E = -1017,
|
||||
WS_RSA_E = -1018,
|
||||
WS_BAD_FILE_E = -1019,
|
||||
WS_INVALID_ALGO_ID = -1020,
|
||||
WS_DECRYPT_E = -1021,
|
||||
WS_ENCRYPT_E = -1022,
|
||||
WS_VERIFY_MAC_E = -1023,
|
||||
WS_CREATE_MAC_E = -1024,
|
||||
WS_RESOURCE_E = -1025, /* not enough resources for new channel */
|
||||
WS_INVALID_CHANTYPE = -1026, /* invalid channel type */
|
||||
WS_INVALID_CHANID = -1027,
|
||||
WS_INVALID_USERNAME = -1028,
|
||||
WS_CRYPTO_FAILED = -1029, /* crypto action failed */
|
||||
WS_INVALID_STATE_E = -1030,
|
||||
WS_EOF = -1031,
|
||||
WS_INVALID_PRIME_CURVE = -1032,
|
||||
WS_ECC_E = -1033,
|
||||
WS_CHANOPEN_FAILED = -1034,
|
||||
WS_REKEYING = -1035, /* Status: rekey in progress */
|
||||
WS_CHANNEL_CLOSED = -1036, /* Status: channel closed */
|
||||
WS_INVALID_PATH_E = -1037,
|
||||
WS_SCP_CMD_E = -1038,
|
||||
WS_SCP_BAD_MSG_E = -1039,
|
||||
WS_SCP_PATH_LEN_E = -1040,
|
||||
WS_SCP_TIMESTAMP_E = -1041,
|
||||
WS_SCP_DIR_STACK_EMPTY_E = -1042,
|
||||
WS_SCP_CONTINUE = -1043,
|
||||
WS_SCP_ABORT = -1044,
|
||||
WS_SCP_ENTER_DIR = -1045,
|
||||
WS_SCP_EXIT_DIR = -1046,
|
||||
WS_SCP_EXIT_DIR_FINAL = -1047,
|
||||
WS_SCP_COMPLETE = -1048, /* SCP transfer complete */
|
||||
WS_SCP_INIT = -1049, /* SCP transfer verified */
|
||||
WS_MATCH_KEX_ALGO_E = -1050, /* cannot match KEX algo with peer */
|
||||
WS_MATCH_KEY_ALGO_E = -1051, /* cannot match key algo with peer */
|
||||
WS_MATCH_ENC_ALGO_E = -1052, /* cannot match encrypt algo with peer */
|
||||
WS_MATCH_MAC_ALGO_E = -1053, /* cannot match MAC algo with peer */
|
||||
WS_PERMISSIONS = -1054,
|
||||
WS_SFTP_COMPLETE = -1055, /* SFTP connection established */
|
||||
WS_NEXT_ERROR = -1056, /* Getting next value/state is error */
|
||||
WS_CHAN_RXD = -1057, /* Status that channel data received. */
|
||||
WS_INVALID_EXTDATA = -1058, /* invalid Channel Extended Data Type */
|
||||
WS_CHAN_PENDING = -1059, /* peer hasn't confirmed channel open */
|
||||
WS_SFTP_BAD_REQ_ID = -1060, /* SFTP Bad request ID */
|
||||
WS_SFTP_BAD_REQ_TYPE = -1061, /* SFTP Bad request ID */
|
||||
WS_SFTP_STATUS_NOT_OK = -1062, /* SFTP Status not OK */
|
||||
WS_SFTP_FILE_DNE = -1063, /* SFTP File Does Not Exist */
|
||||
WS_SIZE_ONLY = -1064, /* Only getting size of buffer needed */
|
||||
WS_CLOSE_FILE_E = -1065, /* Unable to close local file */
|
||||
WS_PUBKEY_REJECTED_E = -1066, /* Server public key rejected */
|
||||
WS_EXTDATA = -1067, /* Extended Data available to be read */
|
||||
|
||||
WS_LAST_E = -67 /* Update this to indicate last error */
|
||||
WS_LAST_E = -1067 /* Update this to indicate last error */
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ nobase_include_HEADERS+= \
|
|||
wolfssh/ssh.h \
|
||||
wolfssh/keygen.h \
|
||||
wolfssh/port.h \
|
||||
wolfssh/memory.h \
|
||||
wolfssh/settings.h \
|
||||
wolfssh/error.h \
|
||||
wolfssh/visibility.h \
|
||||
|
|
|
@ -658,6 +658,7 @@ enum WS_MessageIds {
|
|||
|
||||
/* dynamic memory types */
|
||||
enum WS_DynamicTypes {
|
||||
DYNTYPE_STRING = 500,
|
||||
DYNTYPE_CTX,
|
||||
DYNTYPE_SSH,
|
||||
DYNTYPE_CHANNEL,
|
||||
|
@ -670,7 +671,6 @@ enum WS_DynamicTypes {
|
|||
DYNTYPE_PUBKEY,
|
||||
DYNTYPE_DH,
|
||||
DYNTYPE_RNG,
|
||||
DYNTYPE_STRING,
|
||||
DYNTYPE_MPINT,
|
||||
DYNTYPE_SCPCTX,
|
||||
DYNTYPE_SCPDIR,
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
/* memory.h
|
||||
*
|
||||
* Copyright (C) 2014-2016 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSH.
|
||||
*
|
||||
* wolfSSH is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSH is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* The memory module contains the interface to the custom memory handling hooks.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wolfssh/settings.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef void *(*wolfSSH_Malloc_cb)(size_t size);
|
||||
typedef void (*wolfSSH_Free_cb)(void *ptr);
|
||||
typedef void *(*wolfSSH_Realloc_cb)(void *ptr, size_t size);
|
||||
|
||||
|
||||
/* Public set function */
|
||||
WOLFSSH_API int wolfSSH_SetAllocators(wolfSSH_Malloc_cb malloc_function,
|
||||
wolfSSH_Free_cb free_function,
|
||||
wolfSSH_Realloc_cb realloc_function);
|
||||
|
||||
/* Public in case user app wants to use WMALLOC/WFREE */
|
||||
WOLFSSH_API void* wolfSSH_Malloc(size_t size);
|
||||
WOLFSSH_API void wolfSSH_Free(void *ptr);
|
||||
WOLFSSH_API void* wolfSSH_Realloc(void *ptr, size_t size);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -35,17 +35,16 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PORT_DYNTYPE_STRING 12
|
||||
#define PORT_DYNTYPE_STRING 500
|
||||
/* This value needs to stay in sync with the actual value of DYNTYPE_STRING
|
||||
* from internal.h. */
|
||||
|
||||
/* setup memory handling */
|
||||
#ifndef WMALLOC_USER
|
||||
#include <wolfssh/memory.h>
|
||||
|
||||
#define WMALLOC(s, h, t) ((void)h, (void)t, wolfSSH_Malloc((s)))
|
||||
#define WFREE(p, h, t) {void* xp = (p); if ((xp)) wolfSSH_Free((xp));}
|
||||
#define WREALLOC(p, n, h, t) wolfSSH_Realloc((p), (n))
|
||||
#define WMALLOC(s, h, t) XMALLOC(s, h, t)
|
||||
#define WFREE(p, h, t) XFREE(p, h, t)
|
||||
#define WREALLOC(p, n, h, t) XREALLOC(p, n, h, t)
|
||||
#define wolfSSH_SetAllocators wolfSSL_SetAllocators
|
||||
#endif /* WMALLOC_USER */
|
||||
|
||||
#ifndef WFGETS
|
||||
|
|
Loading…
Reference in New Issue