mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <ahmad@a3f.at>
Subject: [PATCH master 3/4] scripts: kwbimage: check return value of asprintf
Date: Thu, 25 May 2023 20:13:19 +0200	[thread overview]
Message-ID: <20230525181320.2277320-3-ahmad@a3f.at> (raw)
In-Reply-To: <20230525181320.2277320-1-ahmad@a3f.at>

Some newer toolchains defines asprintf with a must_check attribute,
leading to warnings when compiling kwbimage. Let's handle OOM gracefully
to get rid of the warnings.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 scripts/kwbimage.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index f9d052752d79..370c54c983b5 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -1006,6 +1006,7 @@ static int image_create_config_parse_oneline(char *line,
 					     char *configpath)
 {
 	char *keyword, *saveptr;
+	int ret;
 
 	keyword = strtok_r(line, " ", &saveptr);
 	if (!strcmp(keyword, "VERSION")) {
@@ -1056,10 +1057,16 @@ static int image_create_config_parse_oneline(char *line,
 		int argi = 0;
 
 		el->type = IMAGE_CFG_BINARY;
-		if (*value == '/')
+		if (*value == '/') {
 			el->binary.file = strdup(value);
-		else
-			asprintf(&el->binary.file, "%s/%s", configpath, value);
+		} else {
+			ret = asprintf(&el->binary.file, "%s/%s", configpath, value);
+			if (ret < 0) {
+				fprintf(stderr, "Cannot allocate memory\n");
+				return -1;
+			}
+		}
+
 		while (1) {
 			value = strtok_r(NULL, " ", &saveptr);
 			if (!value)
-- 
2.38.4




  parent reply	other threads:[~2023-05-25 18:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25 18:13 [PATCH master 1/4] Revert "imx-usb-loader: add commandline option for displaying version number" Ahmad Fatoum
2023-05-25 18:13 ` [PATCH master 2/4] ARM: rockchip: pine64-quartz64: add sdram-init.bin to .gitignore Ahmad Fatoum
2023-05-25 18:13 ` Ahmad Fatoum [this message]
2023-05-25 18:13 ` [PATCH master 4/4] scripts: omap3-usb-loader: fix heap overflow Ahmad Fatoum
2023-05-26  5:46 ` [PATCH master 1/4] Revert "imx-usb-loader: add commandline option for displaying version number" Johannes Zink
2023-05-26  6:20   ` Ahmad Fatoum
2023-05-26  7:12     ` Johannes Zink

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=20230525181320.2277320-3-ahmad@a3f.at \
    --to=ahmad@a3f.at \
    --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