diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2022-09-08 11:30:03 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-09-12 09:20:25 +0200 |
commit | 032362ebcc9ddbd5585de621165fe7988a8b30e1 (patch) | |
tree | afa7931d40732224d292fa365f668b0a0d0f7f85 /common/ratp | |
parent | 268adcf7effae7d07ff52830095f4ccc8c7855b5 (diff) | |
download | barebox-032362ebcc9ddbd5585de621165fe7988a8b30e1.tar.gz barebox-032362ebcc9ddbd5585de621165fe7988a8b30e1.tar.xz |
ratp: getenv: Do not crash on non-existing variables
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>
Link: https://lore.barebox.org/20220908093005.3035259-4-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/ratp')
-rw-r--r-- | common/ratp/getenv.c | 3 |
1 files changed, 3 insertions, 0 deletions
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; |