mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Bastian Krause <bst@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Bastian Krause <bst@pengutronix.de>
Subject: [PATCH] keytoc: check for memory allocation failures in print_bignum()
Date: Mon,  6 Jan 2025 12:49:53 +0100	[thread overview]
Message-ID: <20250106114953.1278352-1-bst@pengutronix.de> (raw)

These failures are already detected in print_bignum(), so we should pass
them on as well for good measure.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
 scripts/keytoc.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/scripts/keytoc.c b/scripts/keytoc.c
index c60df8a5f01..cde7f48df03 100644
--- a/scripts/keytoc.c
+++ b/scripts/keytoc.c
@@ -484,11 +484,17 @@ static int gen_key_ecdsa(EVP_PKEY *key, const char *key_name, const char *key_na
 		return -EOPNOTSUPP;
 	} else {
 		fprintf(outfilep, "\nstatic uint64_t %s_x[] = {", key_name_c);
-		print_bignum(key_x, bits, 64);
+		ret = print_bignum(key_x, bits, 64);
+		if (ret)
+			return ret;
+
 		fprintf(outfilep, "\n};\n\n");
 
 		fprintf(outfilep, "static uint64_t %s_y[] = {", key_name_c);
-		print_bignum(key_y, bits, 64);
+		ret = print_bignum(key_y, bits, 64);
+		if (ret)
+			return ret;
+
 		fprintf(outfilep, "\n};\n\n");
 
 		fprintf(outfilep, "static struct ecdsa_public_key %s = {\n", key_name_c);
@@ -526,10 +532,16 @@ static int gen_key_rsa(EVP_PKEY *key, const char *key_name, const char *key_name
 	if (dts) {
 		fprintf(outfilep, "\t\tkey-%s {\n", key_name_c);
 		fprintf(outfilep, "\t\t\trsa,r-squared = <");
-		print_bignum(r_squared, bits, 32);
+		ret = print_bignum(r_squared, bits, 32);
+		if (ret)
+			return ret;
+
 		fprintf(outfilep, ">;\n");
 		fprintf(outfilep, "\t\t\trsa,modulus= <");
-		print_bignum(modulus, bits, 32);
+		ret = print_bignum(modulus, bits, 32);
+		if (ret)
+			return ret;
+
 		fprintf(outfilep, ">;\n");
 		fprintf(outfilep, "\t\t\trsa,exponent = <0x%0lx 0x%lx>;\n",
 			(exponent >> 32) & 0xffffffff,
@@ -540,11 +552,17 @@ static int gen_key_rsa(EVP_PKEY *key, const char *key_name, const char *key_name
 		fprintf(outfilep, "\t\t};\n");
 	} else {
 		fprintf(outfilep, "\nstatic uint32_t %s_modulus[] = {", key_name_c);
-		print_bignum(modulus, bits, 32);
+		ret = print_bignum(modulus, bits, 32);
+		if (ret)
+			return ret;
+
 		fprintf(outfilep, "\n};\n\n");
 
 		fprintf(outfilep, "static uint32_t %s_rr[] = {", key_name_c);
-		print_bignum(r_squared, bits, 32);
+		ret = print_bignum(r_squared, bits, 32);
+		if (ret)
+			return ret;
+
 		fprintf(outfilep, "\n};\n\n");
 
 		if (standalone) {
-- 
2.39.5




             reply	other threads:[~2025-01-06 11:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-06 11:49 Bastian Krause [this message]
2025-01-06 13:36 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250106114953.1278352-1-bst@pengutronix.de \
    --to=bst@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox