@@ -787,17 +787,17 @@ static int CheckPasswordWIN(const char* usr, const byte* pw, word32 pwSz, WOLFSS
787787
788788 ret = WSSHD_AUTH_SUCCESS ;
789789
790- usrWSz = WSTRLEN (usr ) * sizeof ( WCHAR ) ;
790+ usrWSz = WSTRLEN (usr );
791791
792- usrW = (WCHAR * )WMALLOC ((usrWSz * sizeof ( WCHAR )) + sizeof (WCHAR ), authCtx -> heap , DYNTYPE_SSHD );
792+ usrW = (WCHAR * )WMALLOC ((usrWSz + 1 ) * sizeof (WCHAR ), authCtx -> heap , DYNTYPE_SSHD );
793793 if (usrW == NULL ) {
794794 wolfSSH_Log (WS_LOG_ERROR , "[SSHD] Ran out of memory" );
795795 ret = WSSHD_AUTH_FAILURE ;
796796 }
797797
798798 if (ret == WSSHD_AUTH_SUCCESS ) {
799799 size_t wr = 0 ;
800- if (mbstowcs_s (& wr , usrW , usrWSz , usr , usrWSz - 1 ) != 0 ) {
800+ if (mbstowcs_s (& wr , usrW , usrWSz + 1 , usr , usrWSz ) != 0 ) {
801801 ret = WSSHD_AUTH_FAILURE ;
802802 }
803803 }
@@ -946,7 +946,7 @@ static int SetupUserTokenWin(const char* usr,
946946
947947 /* write domain name after the user name in buffer */
948948 l -> DomainName .Length = (USHORT )(wcslen (dmW ) * sizeof (wchar_t ));
949- l -> DomainName .MaximumLength = l -> UserPrincipalName .Length ;
949+ l -> DomainName .MaximumLength = l -> DomainName .Length ;
950950 l -> DomainName .Buffer = (WCHAR * )((byte * )(l -> UserPrincipalName .Buffer ) + l -> UserPrincipalName .Length );
951951 memcpy_s (l -> DomainName .Buffer , l -> DomainName .Length , dmW , l -> DomainName .Length );
952952 }
0 commit comments