Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 265907

Summary: sys-apps/sandbox does not quote arguments before passing them to bash
Product: Portage Development Reporter: Harald van Dijk (RETIRED) <truedfx>
Component: SandboxAssignee: Sandbox Maintainers <sandbox>
Status: RESOLVED WONTFIX    
Severity: normal    
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: sandbox-args.patch
portage-2.2-sandbox.patch

Description Harald van Dijk (RETIRED) gentoo-dev 2009-04-12 21:58:55 UTC
$ sandbox sh -c 'echo wtf'

$

This happens because sandbox runs bash -c "sh -c echo wtf", and bash can no longer see that "echo wtf" was supposed to be a single argument. I'm testing a patch, if it works I'll attach it, if not I'll let you know.
Comment 1 Harald van Dijk (RETIRED) gentoo-dev 2009-04-12 22:05:54 UTC
Created attachment 188156 [details, diff]
sandbox-args.patch

$ sandbox sh -c 'echo wtf'
wtf
$ 

Or you could make run_str an array if you prefer.
Comment 2 Harald van Dijk (RETIRED) gentoo-dev 2009-04-12 22:08:52 UTC
Oi... portage is relying on the current behaviour. Is that intentional?
Comment 3 Harald van Dijk (RETIRED) gentoo-dev 2009-04-12 22:20:36 UTC
Created attachment 188159 [details, diff]
portage-2.2-sandbox.patch

Not that modifying portage (the quick-and-dirty way) is that hard, but I suppose if you fix this, you'll have a very hard time making sure there's a clean upgrade path. Any thoughts?
Comment 4 SpanKY gentoo-dev 2009-04-12 22:27:07 UTC
sandbox sh -c '"echo wtf"'
Comment 5 Larry the Git Cow gentoo-dev 2021-10-29 05:37:45 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=9a026d957ffc18ab4f4f7d069f4373ddf190eca9

commit 9a026d957ffc18ab4f4f7d069f4373ddf190eca9
Author:     Mike Frysinger <vapier@gentoo.org>
AuthorDate: 2021-10-29 03:50:00 +0000
Commit:     Mike Frysinger <vapier@gentoo.org>
CommitDate: 2021-10-29 03:50:00 +0000

    sandbox: change interface to make it easier to pass thru
    
    The sandbox command line is passed to a shell for execution.  This can
    be a bit awkward to quote right if you weren't expecting it, and even
    if you were.  Change the default behavior to be more like `env` where
    the arguments, as they are, get passed through and run.  If people want
    the old shell behavior, they can use the -c option akin to `bash -c`.
    
    Bug: https://bugs.gentoo.org/265907
    Signed-off-by: Mike Frysinger <vapier@gentoo.org>

 src/options.c         |  8 +++++++-
 src/sandbox.c         | 46 +++++++++++++++++++++++++++-------------------
 src/sandbox.h         |  1 +
 tests/git-bisector.sh | 15 +++++++++++++--
 tests/local.at        |  2 +-
 5 files changed, 49 insertions(+), 23 deletions(-)
Comment 6 Larry the Git Cow gentoo-dev 2021-11-02 04:28:17 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=116ca8fd5af908edad85095916585576aa19ec5f

commit 116ca8fd5af908edad85095916585576aa19ec5f
Author:     Mike Frysinger <vapier@gentoo.org>
AuthorDate: 2021-11-02 04:13:53 +0000
Commit:     Mike Frysinger <vapier@gentoo.org>
CommitDate: 2021-11-02 04:13:53 +0000

    sandbox: add backwards compat interface hack
    
    Portage runs commands through sandbox like:
      $ sandbox "/usr/lib/portage/python3.9/ebuild.sh unpack"
    
    That means we can't break the CLI without breaking portage and forcing
    everyone to upgrade together.  That'll be pretty disruptive for people,
    so add a hack to detect this situation: if a single argument is passed
    on the CLI, and it doesn't appear to be a file, then fallback to running
    it through the shell.  This keeps portage working while allowing the new
    interface style to launch.  If/when we can update portage to always use
    the -c option, maybe we can drop this in the future.  Or not ... it's
    not exactly the worst hack for users.
    
    Bug: https://bugs.gentoo.org/265907
    Signed-off-by: Mike Frysinger <vapier@gentoo.org>

 src/sandbox.c | 9 +++++++++
 1 file changed, 9 insertions(+)