Skip to content

Commit

Permalink
Fix input length checking in SPNEGO DER decoding
Browse files Browse the repository at this point in the history
In get_mech_set(), check the length before reading the first byte, and
decrease the length by the tag byte when reading and verifying the
sequence length.

In get_req_flags(), check the length before reading the first byte,
and check the context tag length after decoding it.

(cherry picked from commit 64f4b75)

ticket: 8933
version_fixed: 1.17.2
  • Loading branch information
greghudson committed Nov 3, 2020
1 parent 75ae743 commit 9e65436
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/lib/gssapi/spnego/spnego_mech.c
Original file line number Diff line number Diff line change
Expand Up @@ -3381,14 +3381,14 @@ get_mech_set(OM_uint32 *minor_status, unsigned char **buff_in,
unsigned char *start;
int i;

if (**buff_in != SEQUENCE_OF)
if (buff_length < 1 || **buff_in != SEQUENCE_OF)
return (NULL);

start = *buff_in;
(*buff_in)++;

length = gssint_get_der_length(buff_in, buff_length, &bytes);
if (length < 0 || buff_length - bytes < (unsigned int)length)
length = gssint_get_der_length(buff_in, buff_length - 1, &bytes);
if (length < 0 || buff_length - 1 - bytes < (unsigned int)length)
return NULL;

major_status = gss_create_empty_oid_set(minor_status,
Expand Down Expand Up @@ -3468,11 +3468,11 @@ get_req_flags(unsigned char **buff_in, OM_uint32 bodysize,
{
unsigned int len;

if (**buff_in != (CONTEXT | 0x01))
if (bodysize < 1 || **buff_in != (CONTEXT | 0x01))
return (0);

if (g_get_tag_and_length(buff_in, (CONTEXT | 0x01),
bodysize, &len) < 0)
bodysize, &len) < 0 || len != 4)
return GSS_S_DEFECTIVE_TOKEN;

if (*(*buff_in)++ != BIT_STRING)
Expand Down

0 comments on commit 9e65436

Please sign in to comment.