From f5d44483e1be84679cc529704c73fcfdfc32fab2 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Fri, 25 Oct 2024 15:06:36 +0300 Subject: Add NULL checking for `get_envname` Since third part of for loop is executed before the second one, `get_envname` function was trying to copy from NULL at the end of env vector every run. --- througha.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/througha.c b/througha.c index 1d0c3d5..d5cf71c 100644 --- a/througha.c +++ b/througha.c @@ -21,8 +21,12 @@ void usage(const char *name, const char *message) size_t get_envname(char *dest, const char *var) { size_t i = 0; + + if (dest == NULL || var == NULL) return 0; + while ((dest[i] = tolower(var[i])) != '=') ++i; dest[i] = '\0'; + return i; } -- cgit 1.4.1