Skip to contentSkip to conversation

crypto: x509 - Replace kmalloc() + NUL-termination with kzalloc()

PATCH Superseded Thorsten Blum 2 participants 2 messages Mar 17, 2025 – Apr 7, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: x509 - Replace kmalloc() + NUL-termination with kzalloc()

Use kzalloc() to zero out the one-element array instead of using kmalloc() followed by a manual NUL-termination.

No functional changes intended.

---
 crypto/asymmetric_keys/x509_cert_parser.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
crypto/asymmetric_keys/x509_cert_parser.c +1 -2
index ee2fdab42334..2ffe4ae90bea 100644
@@ -372,10 +372,9 @@ static int x509_fabricate_name(struct x509_parse_context *ctx, size_t hdrlen,
 
 	/* Empty name string if no material */
 	if (!ctx->cn_size && !ctx->o_size && !ctx->email_size) {
-		buffer = kmalloc(1, GFP_KERNEL);
+		buffer = kzalloc(1, GFP_KERNEL);
 		if (!buffer)
 			return -ENOMEM;
-		buffer[0] = 0;
 		goto done;
 	}
 
Signature · 1 line
2.48.1
maintainer
#1 lore raw
Quoted 9 lines · Thorsten Blum

Use kzalloc() to zero out the one-element array instead of using kmalloc() followed by a manual NUL-termination.

No functional changes intended.

---
 crypto/asymmetric_keys/x509_cert_parser.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

We have a new maintainer for crypto/asymmetric_keys, please make sure he is CCed on these patches:

ASYMMETRIC KEYS

M:      David Howells <[email protected]>
M:      Lukas Wunner <[email protected]>
M:      Ignat Korchagin <[email protected]>

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt