Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -3283,6 +3283,10 @@ static int GetIntPositive(mp_int* mpi, const byte* input, word32* inOutIdx,
if (ret != 0)
return ret;

if (idx < 1 || idx >= maxIdx) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't check for 1 as the starting index may not be zero.
GetASNInt ensures that a header (2 bytes) is read.
The length may be 0 though. and this is a problem.

The index won't be greater than maxIdx but the idx + length is not checked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you suggest a change please?

Copy link
Copy Markdown
Contributor

@SparkiDev SparkiDev Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the code again and GetASNInt calls GetASNHeader and that will check that the length corresponds to bytes in the buffer. So no need to check: idx + length > maxIdx.

if (length > 0) {
   /* Check that the preceding byte is zero when top bit set. */
   if (((input[idx] & 0x80) == 0x80) && (input[idx - 1] != 0x00))
         return MP_INIT_E;
}

Note that when the first byte of data has the top bit set, the preceding byte is the length and must be > 0.

return BUFFER_E;
}

if (((input[idx] & 0x80) == 0x80) && (input[idx - 1] != 0x00))
return MP_INIT_E;

Expand Down