Add upper bound check in check_peer_pubkey() (#323)

Daemon tested, TLS works, crypto folder works
This commit is contained in:
Levi Neely 2026-03-03 15:51:54 +01:00 committed by GitHub
parent c9bb7685b7
commit a5b09c73c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 2 deletions

View File

@ -304,8 +304,9 @@ static int check_peer_pubkey(ssl_connection_t *conn) {
}
i = mbedtls_pk_write_pubkey_der((mbedtls_pk_context *)&cert->pk, buff,
sizeof(buff));
if (i <= 0) {
pdbg_logf(D_WARNING, "pk_write_pubkey_der returned error %d", i);
if (i <= 0 || i > (int)sizeof(buff)) {
pdbg_logf(D_WARNING, "pk_write_pubkey_der returned %d (buffer size %zu)",
i, sizeof(buff));
return -1;
}
mbedtls_sha256(buff + sizeof(buff) - i, i, sigbin, 0);