mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-10-28 18:07:34 +08:00
Merge 9a455081014f6afdf107d27366bb1ac79a677e72 into 03e1438089654fb884ac48e0f3cd0049cfe2c102
This commit is contained in:
commit
aa07165bc0
6
ChangeLog.d/fix-sample-program-memory-errors.txt
Normal file
6
ChangeLog.d/fix-sample-program-memory-errors.txt
Normal file
@ -0,0 +1,6 @@
|
||||
Bugfix
|
||||
* Fix potential buffer overreads on malformed inputs in sample programs:
|
||||
ssl_server2 could read past the end of a session ticket shorter than
|
||||
4 bytes when the dummy_ticket option is enabled, and ssl_context_info
|
||||
could call strlen() on non-null-terminated ALPN data from the input
|
||||
file, reading past the end of the decoded buffer. Fixes #10803.
|
||||
@ -882,8 +882,13 @@ static void print_deserialized_ssl_context(const uint8_t *ssl, size_t len)
|
||||
printf("\tALPN negotiation : ");
|
||||
CHECK_SSL_END(alpn_len);
|
||||
if (alpn_len > 0) {
|
||||
if (strlen((const char *) ssl) == alpn_len) {
|
||||
printf("%s\n", ssl);
|
||||
/* The ALPN protocol name in the serialized data is not
|
||||
* null-terminated, so do not use strlen() on it: with a
|
||||
* malformed input file it could read past the end of the
|
||||
* decoded buffer. Read exactly alpn_len bytes instead, and
|
||||
* treat an embedded null byte as incorrect data. */
|
||||
if (memchr(ssl, '\0', alpn_len) == NULL) {
|
||||
printf("%.*s\n", (int) alpn_len, ssl);
|
||||
} else {
|
||||
printf("\n");
|
||||
printf_err("\tALPN negotiation is incorrect\n");
|
||||
|
||||
@ -1385,6 +1385,14 @@ static int dummy_ticket_parse(void *p_ticket, mbedtls_ssl_session *session,
|
||||
int ret;
|
||||
((void) p_ticket);
|
||||
|
||||
/* Tickets are written by dummy_ticket_write() and start with a 4-byte
|
||||
* lifetime header. Reject shorter tickets (which a misbehaving client
|
||||
* could send) to avoid an underflow of len - 4 below resulting in a
|
||||
* read past the end of the ticket buffer. */
|
||||
if (len < 4) {
|
||||
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_ssl_session_load(session, buf + 4, len - 4)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user