diff options
Diffstat (limited to 'lib/session_pack.c')
-rw-r--r-- | lib/session_pack.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/session_pack.c b/lib/session_pack.c index e5c21f24b5..a6d11c4cfc 100644 --- a/lib/session_pack.c +++ b/lib/session_pack.c @@ -776,7 +776,7 @@ pack_psk_auth_info(gnutls_session_t session, gnutls_buffer_st * ps) if (info == NULL) return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR); - username_len = strlen(info->username) + 1; /* include the terminating null */ + username_len = info->username_len; hint_len = strlen(info->hint) + 1; /* include the terminating null */ size_offset = ps->length; @@ -824,7 +824,7 @@ unpack_psk_auth_info(gnutls_session_t session, gnutls_buffer_st * ps) return GNUTLS_E_INVALID_REQUEST; BUFFER_POP_NUM(ps, username_size); - if (username_size > sizeof(info->username)) { + if (username_size > (sizeof(info->username) - 1)) { gnutls_assert(); return GNUTLS_E_INTERNAL_ERROR; } @@ -833,6 +833,10 @@ unpack_psk_auth_info(gnutls_session_t session, gnutls_buffer_st * ps) if (username_size == 0) info->username[0] = 0; + /* append a null terminator and set length */ + info->username[username_size] = 0; + info->username_len = username_size; + BUFFER_POP_NUM(ps, hint_size); if (hint_size > sizeof(info->hint)) { gnutls_assert(); |