diff --git a/src/internal.c b/src/internal.c index 5d58d7e2b..1f96b1cf7 100644 --- a/src/internal.c +++ b/src/internal.c @@ -1031,6 +1031,7 @@ WOLFSSH* SshInit(WOLFSSH* ssh, WOLFSSH_CTX* ctx) ssh->kSz = (word32)sizeof(ssh->k); ssh->handshake = handshake; ssh->connectChannelId = WOLFSSH_SESSION_SHELL; + ssh->service = ID_NONE; ssh->algoListKex = ctx->algoListKex; ssh->algoListKey = ctx->algoListKey; ssh->algoListCipher = ctx->algoListCipher; @@ -5879,37 +5880,26 @@ static int DoDisconnect(WOLFSSH* ssh, byte* buf, word32 len, word32* idx) } -static int DoServiceRequest(WOLFSSH* ssh, - byte* buf, word32 len, word32* idx) +static int DoServiceRequest(WOLFSSH* ssh, byte* buf, word32 len, word32* idx) { - word32 begin = *idx; + const char *name = NULL; word32 nameSz; - char serviceName[WOLFSSH_MAX_NAMESZ]; - - WOLFSSH_UNUSED(len); + int ret; - ato32(buf + begin, &nameSz); - begin += LENGTH_SZ; + ret = GetStringRef(&nameSz, (const byte **)&name, buf, len, idx); + if (ret == WS_SUCCESS) { + byte serviceId; - if (begin + nameSz > len || nameSz >= WOLFSSH_MAX_NAMESZ) { - return WS_BUFFER_E; + serviceId = NameToId(name, nameSz); + WLOG(WS_LOG_DEBUG, "Requesting service: %s", IdToName(serviceId)); + ssh->clientState = CLIENT_USERAUTH_REQUEST_DONE; } - WMEMCPY(serviceName, buf + begin, nameSz); - begin += nameSz; - serviceName[nameSz] = 0; - - *idx = begin; - - WLOG(WS_LOG_DEBUG, "Requesting service: %s", serviceName); - ssh->clientState = CLIENT_USERAUTH_REQUEST_DONE; - - return WS_SUCCESS; + return ret; } -static int DoServiceAccept(WOLFSSH* ssh, - byte* buf, word32 len, word32* idx) +static int DoServiceAccept(WOLFSSH* ssh, byte* buf, word32 len, word32* idx) { word32 begin = *idx; word32 nameSz; diff --git a/wolfssh/internal.h b/wolfssh/internal.h index e617a4cf7..d52e7434e 100644 --- a/wolfssh/internal.h +++ b/wolfssh/internal.h @@ -671,6 +671,7 @@ struct WOLFSSH { const char* algoListCipher; const char* algoListMac; const char* algoListKeyAccepted; + byte service; byte acceptState; byte connectState; byte clientState;