Bug 957796

Summary: tar-out and base64-out quoting error
Product: Red Hat Enterprise Linux 7 Reporter: Richard W.M. Jones <rjones>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED CURRENTRELEASE QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.0CC: acathrow, bfan, leiwang, mbooth, wshi
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libguestfs-1.22.4-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 957772 Environment:
Last Closed: 2014-06-13 09:29:34 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 957772    
Bug Blocks:    

Description Richard W.M. Jones 2013-04-29 14:33:15 UTC
+++ This bug was initially created as a clone of Bug #957772 +++

Description of problem:

(Found by infernix on IRC)

The 'tar-out' command does not quote the directory name properly,
meaning that if it contains spaces (or worse, shell meta-characters)
those are not handled properly.

Reproducer:

guestfish -v -N fs -m /dev/sda1 <<EOF
mkdir "/foo bar"
tar-out "/foo bar" /tmp/test.tar
EOF

The command will fail, and in the verbose messages you will see:

  .....
  tar -C /sysroot/foo bar -cf - .
  tar: /sysroot/foo: Cannot chdir: No such file or directory
  tar: Error is not recoverable: exiting now
  pclose: /foo bar: Success
  guestfsd: mainlibguestfs: error: file receive cancelled by daemon
  libguestfs: error: /tmp/test.tar: error in chunked encoding
  .....

Notice that the tar -C option is not properly quoted, so it is
passed as two parameters to tar.

Version-Release number of selected component (if applicable):

1.16 - not able to test, but based on code inspection: no
1.18 - no
1.20 - YES
1.21 - YES

--- Additional comment from Richard W.M. Jones on 2013-04-29 09:51:32 EDT ---

The commit which introduced this error was:

https://github.com/libguestfs/libguestfs/commit/c78ec7e085e99bfddd0509dece72bf6a8d0188ce

which was also backported to the stable-1.20 branch:

https://github.com/libguestfs/libguestfs/commit/1bd81388e02be2e46c24f700217be32786d3ae1a

The error was introduced as part of the fix for RHBZ#908322.

--- Additional comment from Richard W.M. Jones on 2013-04-29 09:54:27 EDT ---

The fix for bug 908322 also broke the base64-out command
in the same way:

guestfish -v -N fs -m /dev/sda1 <<EOF
touch "/foo bar"
base64-out "/foo bar" /tmp/test.b64
EOF

In the verbose output for this command you will see:

  .....
  base64 /sysroot/foo bar
  base64: extra operand '/sysroot/foo'
  Try 'base64 --help' for more information.
  pclose: /foo bar: Success
  guestfsd: main_loop: proc 243 (base64_out) took 0.00 seconds
  libguestfs: error: file receive cancelled by daemon
  libguestfs: error: /tmp/test.b64: error in chunked encoding
  .....

which is the same kind of problem as for tar.

--- Additional comment from Richard W.M. Jones on 2013-04-29 10:31:58 EDT ---

Fixed upstream:
https://github.com/libguestfs/libguestfs/commit/c5f356a60351dd51cbd3a9aabcac2cd40562f36a (fix)
https://github.com/libguestfs/libguestfs/commit/cc93840d31e440e64e27ee13df3afd134ef2e68f (regression test)

Comment 3 Can Zhang 2013-11-07 07:59:01 UTC
I reproduced the bug using libguestfs-1.20.2-1.el7 and verified it with libguestfs-1.22.6-15.el7.

In the buggy version, I catched

...
tar -C /sysroot/foo bar -cf - .
libguestfs: recv_from_daemon: 40 bytes: 20 00 f5 f5 | 00 00 00 04 | 00 00 00 46 | 00 00 00 01 | 00 12 34 04 | ...
tar: /sysroot/foo: Cannot chdir: No such file or directory
tar: Error is not recoverable: exiting now
pclose: /foo bar: Success
...


and in the latest version, it works well.

Comment 4 Ludek Smid 2014-06-13 09:29:34 UTC
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.