4141#include "wolfhsm/wh_client.h"
4242#include "wolfhsm/wh_auth.h"
4343
44+ static int _wh_Client_AuthUserNameSanityCheck (const char * username )
45+ {
46+ size_t len ;
47+
48+ if (username == NULL ) {
49+ return 0 ;
50+ }
51+
52+ len = strnlen (username , WH_MESSAGE_AUTH_MAX_USERNAME_LEN );
53+ return (len < WH_MESSAGE_AUTH_MAX_USERNAME_LEN );
54+ }
55+
4456/** Authenticate */
4557int wh_Client_AuthLoginRequest (whClientContext * c ,
4658 whAuthMethod method , const char * username , const void * auth_data ,
@@ -55,6 +67,10 @@ int wh_Client_AuthLoginRequest(whClientContext* c,
5567 return WH_ERROR_BADARGS ;
5668 }
5769
70+ if (!_wh_Client_AuthUserNameSanityCheck (username )) {
71+ return WH_ERROR_BADARGS ;
72+ }
73+
5874 if (auth_data_len > WH_MESSAGE_AUTH_MAX_CREDENTIALS_LEN ) {
5975 return WH_ERROR_BADARGS ;
6076 }
@@ -224,6 +240,10 @@ int wh_Client_AuthUserAddRequest(whClientContext* c, const char* username,
224240 return WH_ERROR_BADARGS ;
225241 }
226242
243+ if (!_wh_Client_AuthUserNameSanityCheck (username )) {
244+ return WH_ERROR_BADARGS ;
245+ }
246+
227247 strncpy (msg -> username , username , sizeof (msg -> username ));
228248
229249 if (wh_MessageAuth_FlattenPermissions (& permissions , msg -> permissions ,
@@ -392,6 +412,10 @@ int wh_Client_AuthUserGetRequest(whClientContext* c, const char* username)
392412 return WH_ERROR_BADARGS ;
393413 }
394414
415+ if (!_wh_Client_AuthUserNameSanityCheck (username )) {
416+ return WH_ERROR_BADARGS ;
417+ }
418+
395419 strncpy (msg .username , username , sizeof (msg .username ));
396420 return wh_Client_SendRequest (c ,
397421 WH_MESSAGE_GROUP_AUTH , WH_MESSAGE_AUTH_ACTION_USER_GET ,
0 commit comments