DASH Shell discussions
 help / color / mirror / Atom feed
* [PATCH] var.c: check for valid variable name before printing in "export -p"
@ 2012-02-14 10:48 harald
  2012-02-25  7:36 ` Herbert Xu
  0 siblings, 1 reply; 7+ messages in thread
From: harald @ 2012-02-14 10:48 UTC (permalink / raw)
  To: dash; +Cc: Harald Hoyer

From: Harald Hoyer <harald@redhat.com>

"export -p" prints all environment variables, without checking if the
environment variable is a valid dash variable name.

IMHO, the only valid usecase for "export -p" is to eval the output.

$ eval $(export -p); echo OK
OK

Without this patch the following test does error out with:

test.py:
import os
os.environ["test-test"]="test"
os.environ["test_test"]="test"
os.execv("./dash", [ './dash', '-c', 'eval $(export -p); echo OK' ])

$ python test.py
./dash: 1: export: test-test: bad variable name

Of course the results can be more evil, if the environment variable
name is crafted, that it injects valid shell code.
---
 src/var.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/var.c b/src/var.c
index 027beff..06771d3 100644
--- a/src/var.c
+++ b/src/var.c
@@ -409,12 +409,15 @@ showvars(const char *prefix, int on, int off)
 	for (; ep < epend; ep++) {
 		const char *p;
 		const char *q;
-
+		const char *r;
+		r = endofname(*ep);
 		p = strchrnul(*ep, '=');
 		q = nullstr;
-		if (*p)
+		if (*p) {
+			if (p != r)
+				continue;
 			q = single_quote(++p);

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-02-25 15:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-14 10:48 [PATCH] var.c: check for valid variable name before printing in "export -p" harald
2012-02-25  7:36 ` Herbert Xu
2012-02-25 14:30   ` Jilles Tjoelker
2012-02-25 14:31     ` Herbert Xu
2012-02-25 14:53       ` Eric Blake
2012-02-25 14:54         ` Herbert Xu
2012-02-25 15:09       ` Jilles Tjoelker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox