Fix for negative return value from `SSL_CTX_sess_accept()`
authoranupamam13 <anuavnd@gmail.com>
Mon, 2 Nov 2020 12:20:11 +0000 (17:50 +0530)
committerNicola Tuveri <nic.tuv@gmail.com>
Fri, 8 Jan 2021 22:55:02 +0000 (00:55 +0200)
commit42141197a107ef9cd297a7755fece569b84016b8
tree6ed92b967fa6e32702e3644a393d7fbade01bb4f
parent732e24bb14ea9c4f68b8c9cd2bf605e0bd6b498e
Fix for negative return value from `SSL_CTX_sess_accept()`

Fixes #13183

From the original issue report, before this commit, on master and on
1.1.1, the issue can be detected with the following steps:

- Start with a default SSL_CTX, initiate a TLS 1.3 connection with SNI,
  "Accept" count of default context gets incremented
- After servername lookup, "Accept" count of default context gets
  decremented and that of SNI context is incremented
- Server sends a "Hello Retry Request"
- Client sends the second "Client Hello", now again "Accept" count of
  default context is decremented. Hence giving a negative value.

This commit fixes it by adding a check on `s->hello_retry_request` in
addition to `SSL_IS_FIRST_HANDSHAKE(s)`, to ensure the counter is moved
only on the first ClientHello.

CLA: trivial

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13297)
ssl/statem/extensions.c