about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2024-10-25 15:06:36 +0300
committerNakidai <nakidai@disroot.org>2024-10-25 15:11:34 +0300
commitf5d44483e1be84679cc529704c73fcfdfc32fab2 (patch)
treec6ecf89171985f55e53b2ddd746f09ad4ff4ca93
parent95493a89a2f82e8f13576e912dc99d3451521c21 (diff)
downloadthrougha-f5d44483e1be84679cc529704c73fcfdfc32fab2.tar.gz
througha-f5d44483e1be84679cc529704c73fcfdfc32fab2.zip
Add NULL checking for `get_envname` HEAD v1.0.2 master
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.
-rw-r--r--througha.c4
1 files changed, 4 insertions, 0 deletions
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;
 }