@@ -3599,7 +3599,8 @@ int GetString(char* s, word32* sSz, const byte* buf, word32 len, word32 *idx)
35993599
36003600/* Gets the size of a string, allocates memory to hold it plus a NULL, then
36013601 * copies it into the allocated buffer, and terminates it with a NULL. */
3602- int GetStringAlloc(void* heap, char** s, const byte* buf, word32 len, word32 *idx)
3602+ int GetStringAlloc(void* heap, char** s, word32* sSz,
3603+ const byte* buf, word32 len, word32 *idx)
36033604{
36043605 int result;
36053606 const byte *str;
@@ -3617,9 +3618,14 @@ int GetStringAlloc(void* heap, char** s, const byte* buf, word32 len, word32 *id
36173618 WMEMCPY(newStr, str, strSz);
36183619 newStr[strSz] = 0;
36193620
3620- if (*s != NULL)
3621- WFREE(*s, heap, DYNTYPE_STRING);
3622- *s = newStr;
3621+ if (s != NULL) {
3622+ if (*s != NULL)
3623+ WFREE(*s, heap, DYNTYPE_STRING);
3624+ *s = newStr;
3625+ if (sSz != NULL) {
3626+ *sSz = strSz;
3627+ }
3628+ }
36233629 }
36243630
36253631 return result;
@@ -8184,14 +8190,15 @@ static int DoUserAuthInfoRequest(WOLFSSH* ssh, byte* buf, word32 len,
81848190
81858191 if (ret == WS_SUCCESS) {
81868192 begin = *idx;
8187- ret = GetStringAlloc(heap, (char**)&authName, buf, len, &begin);
8193+ ret = GetStringAlloc(heap, (char**)&authName, NULL, buf, len, &begin);
81888194 }
81898195
81908196 if (ret == WS_SUCCESS)
8191- ret = GetStringAlloc(heap, (char**)&authInstruction, buf, len, &begin);
8197+ ret = GetStringAlloc(heap, (char**)&authInstruction, NULL,
8198+ buf, len, &begin);
81928199
81938200 if (ret == WS_SUCCESS)
8194- ret = GetStringAlloc(heap, (char**)&language, buf, len, &begin);
8201+ ret = GetStringAlloc(heap, (char**)&language, NULL, buf, len, &begin);
81958202
81968203 if (ret == WS_SUCCESS)
81978204 ret = GetUint32(&promptSz, buf, len, &begin);
@@ -8218,7 +8225,7 @@ static int DoUserAuthInfoRequest(WOLFSSH* ssh, byte* buf, word32 len,
82188225 } else {
82198226 WMEMSET(echo, 0, sizeof(byte) * promptSz);
82208227 for (entry = 0; entry < promptSz; entry++) {
8221- ret = GetStringAlloc(heap, (char**)&prompts[entry],
8228+ ret = GetStringAlloc(heap, (char**)&prompts[entry], NULL,
82228229 buf, len, &begin);
82238230 if (ret != WS_SUCCESS)
82248231 break;
@@ -8283,7 +8290,7 @@ static int DoGlobalRequestFwd(WOLFSSH* ssh,
82838290 if (ret == WS_SUCCESS) {
82848291 begin = *idx;
82858292 WLOG(WS_LOG_INFO, "wantReply = %d, isCancel = %d", wantReply, isCancel);
8286- ret = GetStringAlloc(ssh->ctx->heap, &bindAddr, buf, len, &begin);
8293+ ret = GetStringAlloc(ssh->ctx->heap, &bindAddr, NULL, buf, len, &begin);
82878294 }
82888295
82898296 if (ret == WS_SUCCESS) {
@@ -8398,14 +8405,14 @@ static int DoChannelOpenForward(WOLFSSH* ssh,
83988405
83998406 if (ret == WS_SUCCESS) {
84008407 begin = *idx;
8401- ret = GetStringAlloc(ssh->ctx->heap, host, buf, len, &begin);
8408+ ret = GetStringAlloc(ssh->ctx->heap, host, NULL, buf, len, &begin);
84028409 }
84038410
84048411 if (ret == WS_SUCCESS)
84058412 ret = GetUint32(hostPort, buf, len, &begin);
84068413
84078414 if (ret == WS_SUCCESS)
8408- ret = GetStringAlloc(ssh->ctx->heap, origin, buf, len, &begin);
8415+ ret = GetStringAlloc(ssh->ctx->heap, origin, NULL, buf, len, &begin);
84098416
84108417 if (ret == WS_SUCCESS)
84118418 ret = GetUint32(originPort, buf, len, &begin);
@@ -9113,7 +9120,7 @@ static int DoChannelRequest(WOLFSSH* ssh,
91139120 ssh->clientState = CLIENT_DONE;
91149121 }
91159122 else if (WSTRNCMP(type, "exec", typeSz) == 0) {
9116- ret = GetStringAlloc(ssh->ctx->heap, &channel->command,
9123+ ret = GetStringAlloc(ssh->ctx->heap, &channel->command, NULL,
91179124 buf, len, &begin);
91189125 channel->sessionType = WOLFSSH_SESSION_EXEC;
91199126 if (ssh->ctx->channelReqExecCb) {
@@ -9124,7 +9131,7 @@ static int DoChannelRequest(WOLFSSH* ssh,
91249131 WLOG(WS_LOG_DEBUG, " command = %s", channel->command);
91259132 }
91269133 else if (WSTRNCMP(type, "subsystem", typeSz) == 0) {
9127- ret = GetStringAlloc(ssh->ctx->heap, &channel->command,
9134+ ret = GetStringAlloc(ssh->ctx->heap, &channel->command, NULL,
91289135 buf, len, &begin);
91299136 channel->sessionType = WOLFSSH_SESSION_SUBSYSTEM;
91309137 if (ssh->ctx->channelReqSubsysCb) {
@@ -9137,39 +9144,34 @@ static int DoChannelRequest(WOLFSSH* ssh,
91379144 #ifdef WOLFSSH_TERM
91389145 else if (WSTRNCMP(type, "pty-req", typeSz) == 0) {
91399146 char term[32];
9140- char* modes = NULL;
9141- word32 termSz, modesSz = 0;
9142- word32 widthChar, heightRows, widthPixels, heightPixels;
9147+ word32 termSz;
91439148
91449149 channel->ptyReq = 1; /* recieved a pty request */
91459150 termSz = (word32)sizeof(term);
91469151 ret = GetString(term, &termSz, buf, len, &begin);
91479152 if (ret == WS_SUCCESS)
9148- ret = GetUint32(&widthChar, buf, len, &begin);
9153+ ret = GetUint32(&ssh-> widthChar, buf, len, &begin);
91499154 if (ret == WS_SUCCESS)
9150- ret = GetUint32(&heightRows, buf, len, &begin);
9155+ ret = GetUint32(&ssh-> heightRows, buf, len, &begin);
91519156 if (ret == WS_SUCCESS)
9152- ret = GetUint32(&widthPixels, buf, len, &begin);
9157+ ret = GetUint32(&ssh-> widthPixels, buf, len, &begin);
91539158 if (ret == WS_SUCCESS)
9154- ret = GetUint32(&heightPixels, buf, len, &begin);
9159+ ret = GetUint32(&ssh-> heightPixels, buf, len, &begin);
91559160 if (ret == WS_SUCCESS)
9156- ret = GetStringAlloc(&modesSz, &modes, buf, len, &begin);
9161+ ret = GetStringAlloc(ssh->ctx->heap,
9162+ (char**)&ssh->modes, &ssh->modesSz,
9163+ buf, len, &begin);
91579164 if (ret == WS_SUCCESS) {
91589165 WLOG(WS_LOG_DEBUG, " term = %s", term);
9159- WLOG(WS_LOG_DEBUG, " widthChar = %u", widthChar);
9160- WLOG(WS_LOG_DEBUG, " heightRows = %u", heightRows);
9161- WLOG(WS_LOG_DEBUG, " widthPixels = %u", widthPixels);
9162- WLOG(WS_LOG_DEBUG, " heightPixels = %u", heightPixels);
9163- WLOG(WS_LOG_DEBUG, " modesSz = %u", modesSz);
9164- ssh->widthChar = widthChar;
9165- ssh->heightRows = heightRows;
9166- ssh->widthPixels = widthPixels;
9167- ssh->heightPixels = heightPixels;
9168- ssh->modes = (byte*)modes;
9169- ssh->modesSz = modesSz;
9166+ WLOG(WS_LOG_DEBUG, " widthChar = %u", ssh->widthChar);
9167+ WLOG(WS_LOG_DEBUG, " heightRows = %u", ssh->heightRows);
9168+ WLOG(WS_LOG_DEBUG, " widthPixels = %u", ssh->widthPixels);
9169+ WLOG(WS_LOG_DEBUG, " heightPixels = %u", ssh->heightPixels);
9170+ WLOG(WS_LOG_DEBUG, " modesSz = %u", ssh->modesSz);
91709171 if (ssh->termResizeCb) {
9171- if (ssh->termResizeCb(ssh, widthChar, heightRows,
9172- widthPixels, heightPixels,
9172+ if (ssh->termResizeCb(ssh,
9173+ ssh->widthChar, ssh->heightRows,
9174+ ssh->widthPixels, ssh->heightPixels,
91739175 ssh->termCtx) != WS_SUCCESS) {
91749176 ret = WS_FATAL_ERROR;
91759177 }
0 commit comments