summaryrefslogtreecommitdiffstats
path: root/usr.bin/make/var.c
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2003-10-06 17:37:20 +0000
committerru <ru@FreeBSD.org>2003-10-06 17:37:20 +0000
commitf90e2695439b61d39a146edcd755e51e627028e6 (patch)
tree24b450a93b3f8f4540bed58688a2b5405e39caa3 /usr.bin/make/var.c
parent4d503277754a88a5c54eb9c159e9ad2db2be52eb (diff)
downloadFreeBSD-src-f90e2695439b61d39a146edcd755e51e627028e6.zip
FreeBSD-src-f90e2695439b61d39a146edcd755e51e627028e6.tar.gz
Fix a bug in variable parsing code that could cause a segfault.
PR: bin/46203 Submitted by: Stefan Farfeleder <stefan@fafoe.dyndns.org>
Diffstat (limited to 'usr.bin/make/var.c')
-rw-r--r--usr.bin/make/var.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c
index dd39ce6..bbc8270 100644
--- a/usr.bin/make/var.c
+++ b/usr.bin/make/var.c
@@ -843,7 +843,8 @@ VarREError(int err, regex_t *pat, const char *str)
* The (possibly-modified) value of the variable or var_Error if the
* specification is invalid. The length of the specification is
* placed in *lengthPtr (for invalid specifications, this is just
- * 2...?).
+ * 2 to skip the '$' and the following letter, or 1 if '$' was the
+ * last character in the string).
* A Boolean in *freePtr telling whether the returned string should
* be freed by the caller.
*
@@ -892,7 +893,10 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr)
v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD);
if (v == (Var *)NULL) {
- *lengthPtr = 2;
+ if (str[1] != '\0')
+ *lengthPtr = 2;
+ else
+ *lengthPtr = 1;
if ((ctxt == VAR_CMD) || (ctxt == VAR_GLOBAL)) {
/*
OpenPOWER on IntegriCloud