mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/4] ratp: getenv: Do not crash on non-existing variables
Date: Tue,  6 Sep 2022 12:20:48 +0200	[thread overview]
Message-ID: <20220906102049.1364561-4-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20220906102049.1364561-1-s.hauer@pengutronix.de>

getenv() returns NULL on non-existing variables. Replace result with
empty string to avoid doing strlen() on a NULL pointer.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/ratp/getenv.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/common/ratp/getenv.c b/common/ratp/getenv.c
index 7b38d2e363..9617ab1b43 100644
--- a/common/ratp/getenv.c
+++ b/common/ratp/getenv.c
@@ -32,6 +32,9 @@ static int ratp_cmd_getenv(const struct ratp_bb *req, int req_len,
 	value = getenv(varname);
 	free(varname);
 
+	if (!value)
+		value = "";
+
 	dlen = strlen(value);
 
 	*rsp_len = sizeof(struct ratp_bb) + dlen;
-- 
2.30.2




  parent reply	other threads:[~2022-09-06 10:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-06 10:20 [PATCH 0/4] RATP updates Sascha Hauer
2022-09-06 10:20 ` [PATCH 1/4] remove local pyserial Sascha Hauer
2022-09-06 10:20 ` [PATCH 2/4] bbremote: Convert to python3 Sascha Hauer
2022-09-06 13:02   ` Jan Lübbe
2022-09-08  8:16     ` Sascha Hauer
2022-09-06 10:20 ` Sascha Hauer [this message]
2022-09-06 10:20 ` [PATCH 4/4] ratp: i2c: Do not return error 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=20220906102049.1364561-4-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH 3/4] ratp: getenv: Do not crash on non-existing variables' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox