Skip to content

Fix s_client Sieve STARTTLS response parsing - #31468

Closed
idrassi wants to merge 1 commit into
openssl:masterfrom
amcrypto-jp:fix-31443-sclient-sieve
Closed

idrassi wants to merge 1 commit into
openssl:masterfrom
amcrypto-jp:fix-31443-sclient-sieve

Conversation

@idrassi

@idrassi idrassi commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #31443

openssl s_client -starttls sieve copied the first two bytes of the Sieve STARTTLS response into sbuf with strncpy(sbuf, mbuf, 2) and then passed sbuf to make_uppercase. For an exact two-byte response such as ok, the copied buffer was not NUL terminated, so make_uppercase could walk past the intended response code, reading and potentially writing until a NUL byte was found.

Replace this with a direct case-insensitive comparison of the first two response bytes using OPENSSL_strncasecmp(mbuf, "OK", 2). The code already verifies that at least two bytes were read before this check.

A regression test is added for s_client -starttls sieve with a local Sieve stub returning an exact lowercase ok response.

Checklist
  • tests are added or updated


BAIL_OUT("failed to fork Sieve listener: $!") unless defined $server_pid;

if ($server_pid == 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So we seem to create a server, listen out for a command (which we assume will be STARTTLS), respond with "ok" - and then abort without doing TLS. This will cause s_client to fail the handshake (but hopefully not crash).

This is all fine, but it may not be immediately obvious to someone coming at this test cold what the point of the test is. Perhaps some comment somewhere explaining the objective of the test.

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.

Indeed. The test stops after the plaintext Sieve STARTTLS exchange because the regression is in the pre-TLS response parser: the later TLS handshake failure is expected. I’ll add a comment explaining that, and I’ll also add an explicit sanitizer output check so an ASan report isn't hidden by the expected nonzero s_client exit.

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.

I implemented the changes and force pushed the commit. I also rebased the commit on current master.

@idrassi
idrassi force-pushed the fix-31443-sclient-sieve branch from 7dbc2b5 to 471e2e2 Compare June 12, 2026 11:53
@openssl-machine openssl-machine added the approval: review pending This pull request needs review by a committer label Jun 12, 2026
@idrassi
idrassi force-pushed the fix-31443-sclient-sieve branch from 471e2e2 to fe9a607 Compare June 12, 2026 11:56
@mattcaswell mattcaswell added branch: master Applies to master branch branch: 3.0 Applies to openssl-3.0 branch (EOL) branch: 3.4 Applies to openssl-3.4 branch: 3.5 Applies to openssl-3.5 branch: 3.6 Applies to openssl-3.6 branch: 4.0 Applies to openssl-4.0 tests: present The PR has suitable tests present labels Jun 12, 2026
@mattcaswell mattcaswell reopened this Jun 12, 2026
@mattcaswell mattcaswell removed the branch: 3.0 Applies to openssl-3.0 branch (EOL) label Jun 12, 2026
@mattcaswell

Copy link
Copy Markdown
Member

Look like there is a conflict backporting this to 3.0, so we'll need a different PR for that branch.

@idrassi

idrassi commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

I will open a new PR dedicated to 3.0 branch.

For the CI macOS readonly-source failure, it is not related to this PR. The only failing test is 70-test_quic_radix.t / quic_radix_test, while this PR only touches apps/s_client.c and test/recipes/20-test_app_s_client.t.

@idrassi

idrassi commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

I opened #31483 for the 3.0 backport.

@openssl-machine openssl-machine added approval: done This pull request has the required number of approvals approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: review pending This pull request needs review by a committer approval: done This pull request has the required number of approvals labels Jun 15, 2026
@openssl-machine

Copy link
Copy Markdown
Collaborator

This pull request is ready to merge

@t8m t8m added the triaged: bug The issue/pr is/fixes a bug label Jun 17, 2026
openssl-machine pushed a commit that referenced this pull request Jun 17, 2026
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Nikola Pajkovsky <[email protected]>
MergeDate: Wed Jun 17 16:22:20 2026
(Merged from #31468)
openssl-machine pushed a commit that referenced this pull request Jun 17, 2026
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Nikola Pajkovsky <[email protected]>
MergeDate: Wed Jun 17 16:22:20 2026
(Merged from #31468)

(cherry picked from commit 6ecdedb)
openssl-machine pushed a commit that referenced this pull request Jun 17, 2026
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Nikola Pajkovsky <[email protected]>
MergeDate: Wed Jun 17 16:22:20 2026
(Merged from #31468)

(cherry picked from commit 6ecdedb)
openssl-machine pushed a commit that referenced this pull request Jun 17, 2026
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Nikola Pajkovsky <[email protected]>
MergeDate: Wed Jun 17 16:22:20 2026
(Merged from #31468)

(cherry picked from commit 6ecdedb)
openssl-machine pushed a commit that referenced this pull request Jun 17, 2026
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Nikola Pajkovsky <[email protected]>
MergeDate: Wed Jun 17 16:22:20 2026
(Merged from #31468)

(cherry picked from commit 6ecdedb)
@t8m

t8m commented Jun 17, 2026

Copy link
Copy Markdown
Member

Merged to the master, 4.0, 3.6, 3.5 and 3.4 branches. Thank you for your contribution.

@t8m t8m closed this Jun 17, 2026
n13l pushed a commit to n13l/openssl that referenced this pull request Jul 25, 2026
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Nikola Pajkovsky <[email protected]>
MergeDate: Wed Jun 17 16:22:20 2026
(Merged from openssl#31468)
rickyringler pushed a commit to rickyringler/openssl that referenced this pull request Aug 21, 2026
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Nikola Pajkovsky <[email protected]>
MergeDate: Wed Jun 17 16:22:20 2026
(Merged from openssl#31468)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch branch: 3.4 Applies to openssl-3.4 branch: 3.5 Applies to openssl-3.5 branch: 3.6 Applies to openssl-3.6 branch: 4.0 Applies to openssl-4.0 tests: present The PR has suitable tests present triaged: bug The issue/pr is/fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remote heap out-of-bounds read/write in openssl s_client -starttls sieve STARTTLS response parsing

5 participants