Enhance code safety and readability in SSL_get_shared_ciphers()
authorSumitra Sharma <sumitraartsy@gmail.com>
Tue, 12 Sep 2023 06:30:21 +0000 (12:00 +0530)
committerTomas Mraz <tomas@openssl.org>
Mon, 18 Sep 2023 12:12:09 +0000 (14:12 +0200)
commit36f1b6eada1a5a8e6f9665ec85c86db37733742a
treee0c725c40a76df25ab0cc9cc939607b2beafb782
parent3558a8c6c41270a1d451d1431a278680667f61e6
Enhance code safety and readability in SSL_get_shared_ciphers()

This commit introduces two key improvements:

1. Improve code safety by replacing the conditional statement with
`if (n >= size)` and using OPENSSL_strnlen() instead of strlen().
This change ensures proper buffer size handling and adheres to
secure coding practices.

2. Enhance code readability by substituting `strcpy(p, c->name)` with
`memcpy(p, c->name, n)`. This adjustment prioritizes code clarity and
maintenance, even while mitigating a minimal buffer overflow risk.

These enhancements bolster the code's robustness and comprehensibility,
aligning with secure coding principles and best practices.

Fixes #19837

Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21934)

(cherry picked from commit 2743594d73e65c38375c619e89ec62579e2c24a9)
ssl/ssl_lib.c