Bug 557655

Summary: guestfish number parsing should not use atoi, should support '0...' for octal and '0x...' for hexadecimal
Product: [Community] Virtualization Tools Reporter: Benjamin Gilbert <bgilbert>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED UPSTREAM QA Contact:
Severity: medium Docs Contact:
Priority: low    
Version: unspecifiedCC: mbooth, meyering, virt-maint
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-01-25 12:56:03 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Benjamin Gilbert 2010-01-22 04:04:55 UTC
Description of problem:
guestfish interprets the mode argument of chmod in decimal rather than octal.

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

How reproducible:
Always

Steps to Reproduce:
1. Run "chmod 700 /" in guestfish.
  
Actual results:
/ gets permissions -w-rwxr-T (1274 octal = 700 decimal)

Expected results:
/ gets permissions rwx------

Additional info:
"chmod 0700 /" doesn't work correctly either.

Comment 1 Richard W.M. Jones 2010-01-22 08:38:59 UTC
Yes I agree this is a bug.

At the moment the code does:

  mode = atoi (argv[0]);

which is wrong on several levels.

Comment 2 Richard W.M. Jones 2010-01-22 08:40:11 UTC
Jim, it seems sensible to ask which gnulib function
I should be using here.

Comment 3 Jim Meyering 2010-01-22 08:45:00 UTC
Hi Rich,

xstrtoul should do the trick.

Comment 4 Richard W.M. Jones 2010-01-22 11:26:34 UTC
Patch posted upstream:

http://www.redhat.com/archives/libguestfs/2010-January/msg00020.html

Comment 5 Benjamin Gilbert 2010-01-22 19:08:51 UTC
This still violates the principle of least surprise.  The chmod command-line program doesn't require the leading 0, so users will omit it here too and will get nonsensical file modes.  Is it really useful to be able to specify file modes in decimal or hex?

Comment 6 Richard W.M. Jones 2010-01-22 19:46:03 UTC
See: http://libguestfs.org/FAQ.html#rescue

We can cover this in the documentation, but guestfish isn't like
bash, and chmod in guestfish is a wrapper around guestfs_chmod,
not the chmod program, so it behaves a bit differently (but
consistent with other guestfish commands).

Comment 7 Richard W.M. Jones 2010-01-22 19:54:20 UTC
I updated the patch to add a note to the 'chmod' command in the
guestfish manual page.

Comment 8 Richard W.M. Jones 2010-01-25 11:54:16 UTC
Updated patch posted upstream:

http://www.redhat.com/archives/libguestfs/2010-January/msg00022.html

Comment 9 Richard W.M. Jones 2010-01-25 12:56:03 UTC
Fixed upstream:

http://git.annexia.org/?p=libguestfs.git;a=commitdiff;h=58abe782bf7137526b4a5c7e6d5d2b145e3b09d2

This fix will be in 1.0.82.