Skip to content

Fix SSL sessions returning uninitialized memory - #124

Merged
SeanTAllen merged 1 commit into
mainfrom
issue-123-read-buf-size
Aug 1, 2026
Merged

Fix SSL sessions returning uninitialized memory#124
SeanTAllen merged 1 commit into
mainfrom
issue-123-read-buf-size

Conversation

@SeanTAllen

@SeanTAllen SeanTAllen commented Aug 1, 2026

Copy link
Copy Markdown
Member

SSL.read sized its buffer from the length it was about to request, then returned that size as the number of bytes decrypted. On two of its exits those numbers did not match, and the caller got uninitialized heap back as application data. SSL.send had the same defect against BIO_read and gets the same fix.

read also had two SSL_read call sites, one that truncated the buffer on some exits and one that truncated on none. It has one call site and one truncate now, so a path that skips the truncate can't be written.

SSL_get_error results were matched as bare integers in read and receive; they are named values on a _SSLErrorCode primitive now. The dead max binding #117 names was part of the sizing logic being rewritten, so it comes out here too.

The if pending > 0 clamp is an allocation bound now, not a correctness guard. Shrinking len to SSL_pending's count used to be what kept the returned size right. The size comes off SSL_read's return on every path now, so the clamp only bounds the allocation. Delete the whole block and every test still passes with every returned byte correct.

Reaching the two new lines in send takes two gibibytes or more of queued ciphertext, the case #121 narrows to. Both lines can be deleted with the full suite green.

The missing else on the SSL_get_error match, #120, is now reachable from a path that could not reach it before. Previously only the SSL_pending == 0 path reached it.

Five open issues cite ssl/net/ssl.pony line numbers we move here: #118, #119, #120, #121, #122. Renumbering isn't enough for #121. It describes read as having two SSL_read call sites and says send returns uninitialized heap to the peer, and neither holds after this.

Closes #123
Closes #117

@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Aug 1, 2026
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Aug 1, 2026
@SeanTAllen
SeanTAllen force-pushed the issue-123-read-buf-size branch from ae31dde to c369b1e Compare August 1, 2026 16:29
@SeanTAllen SeanTAllen changed the title Fix SSL sessions returning bytes OpenSSL never wrote Fix SSL sessions returning uninitialized memory Aug 1, 2026
@SeanTAllen
SeanTAllen force-pushed the issue-123-read-buf-size branch from c369b1e to ce4f8cd Compare August 1, 2026 16:33
`read` sized `_read_buf` before the decrypt and then treated its size as the
count of bytes decrypted. Two of its exits left those apart, so a caller got
uninitialized heap as application data. It had two `SSL_read` call sites and
nothing made them agree: one truncated on some exits, the other on none.
Collapsing them to one call site is what makes a path that skips the
reconciliation impossible to write, rather than adding a second truncate a
later edit can miss again.

`send` is the same defect against `BIO_read`. Nothing says why it would be
allowed to return bytes OpenSSL did not write while `read` is not, so it is
fixed here too. Its narrowed length is #121's and is untouched.

Matching `SSL_get_error` results on bare integers needed a comment to be
readable, so the results are named instead. That covers `receive` as well as
`read`.

The dead `max` binding sat inside the rewritten sizing logic, so it goes with
it.

Closes #123
Closes #117
@SeanTAllen
SeanTAllen force-pushed the issue-123-read-buf-size branch from ce4f8cd to d8e7a2b Compare August 1, 2026 16:37
@SeanTAllen
SeanTAllen merged commit ec20bec into main Aug 1, 2026
15 checks passed
@SeanTAllen
SeanTAllen deleted the issue-123-read-buf-size branch August 1, 2026 17:07
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Aug 1, 2026
github-actions Bot pushed a commit that referenced this pull request Aug 1, 2026
github-actions Bot pushed a commit that referenced this pull request Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSL.read returns _read_buf at a size SSL_read did not fill SSL.read computes max and never uses it

2 participants