Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use signed variable for length calculation in SendTls13Certificate #7880

Merged
merged 3 commits into from
Aug 29, 2024

Conversation

ColtonWilley
Copy link
Contributor

Description

Use signed variable for length calculation in SendTls13Certificate. Current code uses unsigned len which only works when decremented exactly to zero. Any mistakes in the length handling will underflow and keep looping, allocating memory until the system runs out.

Additional fix brought up by ZD 18267

@SparkiDev
Copy link
Contributor

Prefer to keep length as unsigned if possible as all assignments I've seen are calculated with unsigned.
Windows is complaining about signed/unsigned mismatch and needs to be fixed.

@ColtonWilley
Copy link
Contributor Author

So I mean we can keep it unsigned but I feel it is still far riskier. The hang two customers saw would have been prevented with this change, and in general any mistakes in length handling will result in a hang. Any mistakes in further modifications of that code could also result in a hang. Would strongly prefer we not do unsigned len > 0 loop, especially when allocating inside that loop.

@ColtonWilley
Copy link
Contributor Author

Retest this please.

Copy link
Contributor

@douzzer douzzer left a comment

Choose a reason for hiding this comment

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

Changing length to be signed here does seem like the right idea -- just inherently more fault-tolerant.

Found something else to gripe about -- see comment.

@@ -8510,7 +8511,7 @@ static int SendTls13Certificate(WOLFSSL* ssl)
listSz = 0;
}
else {
if (!ssl->buffers.certificate) {
if (!ssl->buffers.certificate || !ssl->buffers.certificate->buffer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ssl->buffers.certificate->buffer is only dereferenced if certSz > 0. I can imagine there's code somewhere relying on null buffer being tolerated when ssl->buffers.certificate->length is zero, so this nullness check should only be done when ssl->buffers.certificate->length > 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree its a bit redundant, but is consistent with the rest of the code. Search for !ssl->buffers.certificate and you will see every single check in internal.c, ssl.c and tls13.c use if (!ssl->buffers.certificate || !ssl->buffers.certificate->buffer)

If we want to address that redundancy check separately I am on board, but I think at least for this PR its best to have the checks be consistent.

@douzzer douzzer merged commit fab5c9f into wolfSSL:master Aug 29, 2024
127 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants