aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-10-15 11:40:12 +0300
committerArnold D. Robbins <arnold@skeeve.com>2014-10-15 11:40:12 +0300
commit74ee0dcab17240a1626b77ed998b07f0f6560a48 (patch)
tree4cb604dbf593ca99fd0956880b9155b9ef3a9933 /main.c
parentcb9faa8c276efc4e2b24378bdb941d007523fc22 (diff)
downloadegawk-74ee0dcab17240a1626b77ed998b07f0f6560a48.tar.gz
egawk-74ee0dcab17240a1626b77ed998b07f0f6560a48.tar.bz2
egawk-74ee0dcab17240a1626b77ed998b07f0f6560a48.zip
Sanitize handling of AWKPATH / AWKLIBPATH.
Diffstat (limited to 'main.c')
-rw-r--r--main.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/main.c b/main.c
index 03decbb8..3bee0488 100644
--- a/main.c
+++ b/main.c
@@ -1078,18 +1078,23 @@ path_environ(const char *pname, const char *dflt)
NODE *tmp;
tmp = make_string(pname, strlen(pname));
- if (! in_array(ENVIRON_node, tmp)) {
- /*
- * On VMS, environ[] only holds a subset of what getenv() can
- * find, so look AWKPATH up before resorting to default path.
- */
- val = getenv(pname);
- if (val == NULL)
- val = dflt;
- aptr = assoc_lookup(ENVIRON_node, tmp);
+ /*
+ * On VMS, environ[] only holds a subset of what getenv() can
+ * find, so look AWKPATH up before resorting to default path.
+ */
+ val = getenv(pname);
+ if (val == NULL || *val == '\0')
+ val = dflt;
+ aptr = assoc_lookup(ENVIRON_node, tmp);
+ /*
+ * If original value was the empty string, set it to
+ * the default value.
+ */
+ if ((*aptr)->stlen == 0) {
unref(*aptr);
*aptr = make_string(val, strlen(val));
}
+
unref(tmp);
}
@@ -1136,6 +1141,11 @@ load_environ()
/*
* Put AWKPATH and AWKLIBPATH into ENVIRON if not already there.
* This allows querying it from within awk programs.
+ *
+ * October 2014:
+ * If their values are "", override with the default values;
+ * since 2.10 AWKPATH used default value if environment's
+ * value was "".
*/
path_environ("AWKPATH", defpath);
path_environ("AWKLIBPATH", deflibpath);