Commit 59508f6cee for openssl.org
commit 59508f6cee789caf703cb495de1fefcb38e58083
Author: Bob Beck <beck@openssl.org>
Date: Wed Jun 17 19:27:55 2026 -0600
Convert PEM_dek_info() to snprintf()
Add the correct snprintf() guards to each advance.
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Andrew Dinh <andrewd@openssl.org>
MergeDate: Wed Aug 26 16:20:16 2026
(Merged from https://github.com/openssl/openssl/pull/31640)
diff --git a/crypto/pem/pem_lib.c b/crypto/pem/pem_lib.c
index b2a84fdab6..6c6df85198 100644
--- a/crypto/pem/pem_lib.c
+++ b/crypto/pem/pem_lib.c
@@ -91,13 +91,13 @@ void PEM_dek_info(char *buf, const char *type, int len, const char *str)
char *p = buf + strlen(buf);
int j = PEM_BUFSIZE - (int)(p - buf), n;
- n = BIO_snprintf(p, j, "DEK-Info: %s,", type);
- if (n > 0) {
+ n = snprintf(p, j, "DEK-Info: %s,", type);
+ if (n > 0 && n < j) {
j -= n;
p += n;
for (i = 0; i < len; i++) {
- n = BIO_snprintf(p, j, "%02X", 0xff & str[i]);
- if (n <= 0)
+ n = snprintf(p, j, "%02X", 0xff & str[i]);
+ if (n <= 0 || n >= j)
return;
j -= n;
p += n;