Re: [PATCH v2] Allow git-shell to be used as a ssh forced-command
- From
- Eygene Ryabinkin <rea-git@codelabs.ru>
- Date
- Apr 21, 2009, 09:46 UTC
- Message-ID
- <2pQA2nR7mckXWlZ1caYVRbSAd+A@7qgLKkvX/1U6eu9avhKQpU/1pEI>
- In-Reply-To
- <20090421080559.GI25059@dpotapov.dyndns.org>
Dmitry, *, good day.
Tue, Apr 21, 2009 at 12:05:59PM +0400, Dmitry Potapov wrote:
Show 29 quoted lines
> On Tue, Apr 21, 2009 at 07:43:06AM +0200, Mike Hommey wrote:
> > When using a forced-command, OpenSSH sets the SSH_ORIGINAL_COMMAND
> > variable to what would otherwise be passed to $SHELL -c. When this
> > variable is set and git-shell was given no argument, we use it.
> >
> > Signed-off-by: Mike Hommey <mh@glandium.org>
> > ---
> > shell.c | 9 +++++++--
> > 1 files changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/shell.c b/shell.c
> > index b968be7..86c9273 100644
> > --- a/shell.c
> > +++ b/shell.c
> > @@ -72,11 +72,16 @@ int main(int argc, char **argv)
> > /*
> > * We do not accept anything but "-c" followed by "cmd arg",
> > * where "cmd" is a very limited subset of git commands.
> > + * If no argument is given at all, see whether we were run from
> > + * a ssh forced-command and use the original command if so.
> > */
> > else if (argc != 3 || strcmp(argv[1], "-c"))
> > - die("What do you think I am? A shell?");
> > + if (argc != 1 || !(prog = getenv("SSH_ORIGINAL_COMMAND")))
> > + die("What do you think I am? A shell?");
> > +
> > + if (!prog)
>
> It appears to me that 'prog' may be used unitialized here.True. The proper patch would be ----- From 898e5ae3891d294ee5cb28a430093aced7cb26bd Mon Sep 17 00:00:00 2001 From: Mike Hommey <mh@glandium.org> Date: Tue, 21 Apr 2009 07:43:06 +0200 Subject: [PATCH] Allow git-shell to be used as a ssh forced-command
When using a forced-command, OpenSSH sets the SSH_ORIGINAL_COMMAND variable to what would otherwise be passed to $SHELL -c. When this variable is set and git-shell was given no argument, we use it.
Signed-off-by: Mike Hommey <mh@glandium.org> Patch-problem-spotted-by: Dmitry Potapov <dpotapov@gmail.com> Signed-off-by: Eygene Ryabinkin <rea-git@codelabs.ru> --- shell.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/shell.c b/shell.c index b968be7..93aeded 100644 --- a/shell.c +++ b/shell.c @@ -47,7 +47,7 @@ static struct commands { int main(int argc, char **argv) { - char *prog; + char *prog = NULL; struct commands *cmd; int devnull_fd; @@ -72,11 +72,16 @@ int main(int argc, char **argv) /* * We do not accept anything but "-c" followed by "cmd arg", * where "cmd" is a very limited subset of git commands. + * If no argument is given at all, see whether we were run from + * a ssh forced-command and use the original command if so. */ else if (argc != 3 || strcmp(argv[1], "-c")) - die("What do you think I am? A shell?"); + if (argc != 1 || !(prog = getenv("SSH_ORIGINAL_COMMAND"))) + die("What do you think I am? A shell?"); + + if (!prog) + prog = argv[2]; - prog = argv[2]; if (!strncmp(prog, "git", 3) && isspace(prog[3])) /* Accept "git foo" as if the caller said "git-foo". */ prog[3] = '-';
-- 1.6.1.3 ----- -- Eygene