From: harald@redhat.com
To: dash@vger.kernel.org
Cc: Harald Hoyer <harald@redhat.com>
Subject: [PATCH] var.c: check for valid variable name before printing in "export -p"
Date: Tue, 14 Feb 2012 11:48:48 +0100 [thread overview]
Message-ID: <1329216528-8462-1-git-send-email-harald@redhat.com> (raw)
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);
next reply other threads:[~2012-02-14 10:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-14 10:48 harald [this message]
2012-02-25 7:36 ` [PATCH] var.c: check for valid variable name before printing in "export -p" 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1329216528-8462-1-git-send-email-harald@redhat.com \
--to=harald@redhat.com \
--cc=dash@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox