From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH v2 3/5] ratp: getenv: Do not crash on non-existing variables
Date: Thu, 8 Sep 2022 11:30:03 +0200 [thread overview]
Message-ID: <20220908093005.3035259-4-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20220908093005.3035259-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
next prev parent reply other threads:[~2022-09-08 9:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-08 9:30 [PATCH v2 0/5] bbremote: Convert to python3 Sascha Hauer
2022-09-08 9:30 ` [PATCH v2 1/5] remove local pyserial Sascha Hauer
2022-09-08 9:30 ` [PATCH v2 2/5] bbremote: Convert to python3 Sascha Hauer
2022-09-08 9:30 ` Sascha Hauer [this message]
2022-09-08 9:30 ` [PATCH v2 4/5] ratp: i2c: Do not return error Sascha Hauer
2022-09-08 9:30 ` [PATCH v2 5/5] bbremote: Print usage when no command is given 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=20220908093005.3035259-4-s.hauer@pengutronix.de \
--to=s.hauer@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