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

Thorsten Blum posted 1 patch 9 months ago
There is a newer version of this series
crypto/asymmetric_keys/x509_cert_parser.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH] crypto: x509 - Replace kmalloc() + NUL-termination with kzalloc()
Posted by Thorsten Blum 9 months ago
Use kzalloc() to zero out the one-element array instead of using
kmalloc() followed by a manual NUL-termination.

No functional changes intended.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 crypto/asymmetric_keys/x509_cert_parser.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/crypto/asymmetric_keys/x509_cert_parser.c b/crypto/asymmetric_keys/x509_cert_parser.c
index ee2fdab42334..2ffe4ae90bea 100644
--- a/crypto/asymmetric_keys/x509_cert_parser.c
+++ b/crypto/asymmetric_keys/x509_cert_parser.c
@@ -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;
 	}
 
-- 
2.48.1
Re: [PATCH] crypto: x509 - Replace kmalloc() + NUL-termination with kzalloc()
Posted by Herbert Xu 8 months, 2 weeks ago
On Mon, Mar 17, 2025 at 11:48:41AM +0100, Thorsten Blum wrote:
> Use kzalloc() to zero out the one-element array instead of using
> kmalloc() followed by a manual NUL-termination.
> 
> No functional changes intended.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  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 <dhowells@redhat.com>
M:      Lukas Wunner <lukas@wunner.de>
M:      Ignat Korchagin <ignat@cloudflare.com>

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt