Bug 587516 - setfattr doesn't accept 0x2 as the value [documentation bug]
setfattr doesn't accept 0x2 as the value [documentation bug]
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: attr (Show other bugs)
rawhide
All Linux
low Severity medium
: ---
: ---
Assigned To: Kamil Dudka
Fedora Extras Quality Assurance
:
Depends On:
Blocks: 651120 674870
  Show dependency treegraph
 
Reported: 2010-04-30 02:33 EDT by Tomasz Kepczynski
Modified: 2011-02-03 10:38 EST (History)
2 users (show)

See Also:
Fixed In Version: attr-2.4.44-4.fc13
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 651120 (view as bug list)
Environment:
Last Closed: 2011-01-17 15:49:39 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
proposed improvement of setfattr.1 man page (1.35 KB, patch)
2010-11-08 14:25 EST, Kamil Dudka
no flags Details | Diff
[PATCH v2] proposed improvement of setfattr.1 man page (1.35 KB, patch)
2010-11-09 03:03 EST, Kamil Dudka
no flags Details | Diff
setfattr.1: document supported encodings of values (1.36 KB, patch)
2010-11-19 06:41 EST, Kamil Dudka
no flags Details | Diff

  None (edit)
Description Tomasz Kepczynski 2010-04-30 02:33:08 EDT
Description of problem:
I was trying to set some user.DOSATTRIB values on read-only samba share with setfattr. Samba seems to require the values for that attribute to be hexadecimal, starting with C style 0x prefix. Unfortunately such a value is rejected by setfattr:

gklab-63-001:/var/tmp> setfattr -n user.DOSATTRIB -v '0x2' aqq
bad input encoding
gklab-63-001:/var/tmp> setfattr -n DOSATTRIB -v '0x2' aqq
bad input encoding
gklab-63-001:/var/tmp> getfattr -d aqq
gklab-63-001:/var/tmp> attr -s DOSATTRIB -V 0x2 aqq
Atrybut "DOSATTRIB" dla aqq ustawiono na wartość 3-bajtową:
0x2
gklab-63-001:/var/tmp> getfattr -d aqq
# file: aqq
user.DOSATTRIB="0x2"

Curiously (as seen above) attr -s seems to have no problem with such value.

Version-Release number of selected component (if applicable):
attr-2.4.44-1.fc12.x86_64

How reproducible:
Always

Actual results:
Cannot set the value 0x2 for the attribute.

Expected results:
Can set the value 0x2 for the attribute.


Additional info:
I've also seen this bug on CentOS 5.4 so you should consider cloning the bug there as well.
Comment 1 Kamil Dudka 2010-04-30 03:22:39 EDT
Thank you for filling the bug!  I'll check if it is a real bug or feature.

FWIW, here is a trace of the failure:

$ gdb -q --args setfattr -n user.DOSATTRIB -v 0x2 /tmp/x
(gdb) break decode
Breakpoint 1 at 0x401839: file setfattr.c, line 291.
(gdb) run

Breakpoint 1, decode (value=0x7fffffffe6cb "0x2", size=0x7fffffffe250) at setfattr.c:291
291             if (value[0] == '0' && (value[1] == 'x' || value[1] == 'X')) {
(gdb) next
292                     const char *v = value+2, *end = value + *size;
(gdb)
296                                          *size / 2)) {
(gdb)
295                     if (high_water_alloc((void **)&decoded, &decoded_size,
(gdb)
302                     d = decoded;
(gdb)
303                     while (v < end) {
(gdb)
306                             while (v < end && isspace(*v))
(gdb)
308                             if (v == end)
(gdb)
310                             d1 = hex_digit(*v++);
(gdb)
311                             while (v < end && isspace(*v))
(gdb)
313                             if (v == end) {
(gdb)
315                                     fprintf(stderr, "bad input encoding\n");
(gdb) info locals
d1 = 2
d0 = 32767
v = 0x7fffffffe6ce ""
end = 0x7fffffffe6ce ""
d = 0x605000 ""
decoded = 0x605000 ""
decoded_size = 256
Comment 2 Kamil Dudka 2010-05-11 07:13:55 EDT
That's not a bug.  setfattr(1) takes also values in either hexadecimal or base64 format, given the 0[xX] respectively 0[sS] prefix.  You should be able to pass 0x2 as string by surrounding it to quotes.  Please confirm.

I agree there is a dearth of documentation for this feature.  If you had some suggestion what to add to man page or whatever, it would be also appreciated.
Comment 3 Tomasz Kepczynski 2010-05-11 13:57:58 EDT
I would say: it works weirdly:

vesemir:/var/tmp> setfattr -n user.DOSATTRIB -v '0x2' rpm-tmp.P2sHiq
bad input encoding
vesemir:/var/tmp> setfattr -n user.DOSATTRIB -v "0x2" rpm-tmp.P2sHiq
bad input encoding
vesemir:/var/tmp> setfattr -n user.DOSATTRIB -v '"0x2"' rpm-tmp.P2sHiq
vesemir:/var/tmp> getfa
getfacl  getfattr 
vesemir:/var/tmp> getfattr -d rpm-tmp.P2sHiq
# file: rpm-tmp.P2sHiq
user.DOSATTRIB="0x2"

So, to make it work - you need single quotes in doubles quotes, the other way around or plenty of backslashes....

I love hearing: it is not a bug, it is a feature ;).
Comment 4 Kamil Dudka 2010-05-11 14:20:11 EDT
Sure, that's a feature of the _shell_ you're using ;-)  It drops the outer single or double quotes.  You need to either double quote, or escape the quotes to disable their special meaning:

$ setfattr -n user.DOSATTRIB -v \"0x2\"

You will observe basically the same with e.g. echo(1):

$ echo "0x2"
0x2

$ echo \"0x2\"
"0x2"
Comment 5 Tomasz Kepczynski 2010-05-11 16:28:00 EDT
That doesn't explain why I have to put quotes around 0x2 which is hexadecimal number and not when passing straight string like zzz:

vesemir:/var/tmp> setfattr -n user.DOSATTRIB -v '"0x2"' kdecache-tomek
vesemir:/var/tmp> getfattr -d kdecache-tomek
# file: kdecache-tomek
user.DOSATTRIB="0x2"

vesemir:/var/tmp> setfattr -n user.DOSATTRIB -v zzz kdecache-tomek
vesemir:/var/tmp> getfattr -d kdecache-tomek
# file: kdecache-tomek
user.DOSATTRIB="zzz"

My understanding is that all attributes are just strings and I consider the requirement to quote hexadecimal number in this case unreasonable.

But that's another story, I think you can close the bug (unless you agree with me and want to fix it ;) ).
Comment 6 Kamil Dudka 2010-05-11 17:17:30 EDT
Well, my mistake.  I should have explained this properly.

The mentioned feature is obstruction from your point of view since you pass only text values through.  Nevertheless there should be a way to pass some binary values as well.  That's why the hexadecimal and base64 format has been introduced, at least from my understanding of that.

Each enhancement has its cost.  In this case, it means that all strings starting with '0x', '0X', '0s', or '0S' are treated specially.  To get the old behavior back, just surround your value by double quotes.  It will work well for "0x2", as well as "zzz".

If you have any idea how to implement the feature in a better way (without breaking the stuff), patches are welcome.  I left the bug open because I hadn't found the feature mentioned in documentation.  If the information is indeed missing, we should perhaps a paragraph there about the feature.

FWIW, I've CC'd the upstream maintainer of attr.
Comment 7 Kamil Dudka 2010-11-08 14:25:06 EST
Created attachment 458858 [details]
proposed improvement of setfattr.1 man page
Comment 8 Kamil Dudka 2010-11-09 03:03:35 EST
Created attachment 459025 [details]
[PATCH v2] proposed improvement of setfattr.1 man page

just fixed two typos...
Comment 9 Kamil Dudka 2010-11-19 06:41:52 EST
Created attachment 461527 [details]
setfattr.1: document supported encodings of values

after review by David O'Brien
Comment 10 Kamil Dudka 2010-11-19 08:18:40 EST
proposed upstream:

http://lists.gnu.org/archive/html/acl-devel/2010-11/msg00000.html
Comment 11 Kamil Dudka 2010-11-23 12:12:16 EST
pushed upstream:

http://git.savannah.gnu.org/cgit/attr.git/commit/?id=846ca47
Comment 12 Kamil Dudka 2010-12-22 09:49:07 EST
fixed in attr-2.4.44-6.fc15
Comment 13 Fedora Update System 2011-01-05 13:58:07 EST
attr-2.4.44-6.fc14 has been submitted as an update for Fedora 14.
https://admin.fedoraproject.org/updates/attr-2.4.44-6.fc14
Comment 14 Fedora Update System 2011-01-05 13:58:33 EST
attr-2.4.44-4.fc13 has been submitted as an update for Fedora 13.
https://admin.fedoraproject.org/updates/attr-2.4.44-4.fc13
Comment 15 Fedora Update System 2011-01-06 14:26:36 EST
attr-2.4.44-4.fc13 has been pushed to the Fedora 13 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update attr'.  You can provide feedback for this update here: https://admin.fedoraproject.org/updates/attr-2.4.44-4.fc13
Comment 16 Fedora Update System 2011-01-17 15:49:18 EST
attr-2.4.44-6.fc14 has been pushed to the Fedora 14 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 17 Fedora Update System 2011-01-23 15:25:03 EST
attr-2.4.44-4.fc13 has been pushed to the Fedora 13 stable repository.  If problems still persist, please make note of it in this bug report.

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