Bug 557655 - guestfish number parsing should not use atoi, should support '0...' for octal and '0x...' for hexadecimal
guestfish number parsing should not use atoi, should support '0...' for octal...
Status: CLOSED UPSTREAM
Product: Virtualization Tools
Classification: Community
Component: libguestfs (Show other bugs)
unspecified
All Linux
low Severity medium
: ---
: ---
Assigned To: Richard W.M. Jones
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2010-01-21 23:04 EST by Benjamin Gilbert
Modified: 2010-03-16 13:26 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-01-25 07:56:03 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Benjamin Gilbert 2010-01-21 23:04:55 EST
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 03:38:59 EST
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 03:40:11 EST
Jim, it seems sensible to ask which gnulib function
I should be using here.
Comment 3 Jim Meyering 2010-01-22 03:45:00 EST
Hi Rich,

xstrtoul should do the trick.
Comment 4 Richard W.M. Jones 2010-01-22 06:26:34 EST
Patch posted upstream:

http://www.redhat.com/archives/libguestfs/2010-January/msg00020.html
Comment 5 Benjamin Gilbert 2010-01-22 14:08:51 EST
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 14:46:03 EST
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 14:54:20 EST
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 06:54:16 EST
Updated patch posted upstream:

http://www.redhat.com/archives/libguestfs/2010-January/msg00022.html
Comment 9 Richard W.M. Jones 2010-01-25 07:56:03 EST
Fixed upstream:

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

This fix will be in 1.0.82.

Note You need to log in before you can comment on or make changes to this bug.