Bug 209039

Summary: getextattr(8) -x garbles non-ASCII bytes
Product: Base System Reporter: Alan Somers <asomers>
Component: binAssignee: Alan Somers <asomers>
Status: Closed FIXED    
Severity: Affects Many People    
Priority: ---    
Version: CURRENT   
Hardware: Any   
OS: Any   

Description Alan Somers freebsd_committer freebsd_triage 2016-04-25 16:52:46 UTC
getextattr is used to print the value of an extended attribute on a file.  The -x option prints the output in hex instead of ASCII.  It prints one byte at a time, with spaces between bytes.  However, when printing bytes with the high bit set, getextattr erroneously interprets the single byte as a signed 32-bit number.

$ getextattr user umlauts foofoo     aeiou äëïöü
$ getextattr -x user umlauts foofoo     61 65 69 6f 75 20 ffffffc3 ffffffa4 ffffffc3 ffffffab ffffffc3 ffffffaf ffffffc3 ffffffb6 ffffffc3 ffffffbc
Comment 1 commit-hook freebsd_committer freebsd_triage 2016-05-04 21:08:02 UTC
A commit references this bug:

Author: asomers
Date: Wed May  4 21:07:30 UTC 2016
New revision: 299087
URL: https://svnweb.freebsd.org/changeset/base/299087

Log:
  Fix "getextattr -x" with non-ascii attribute values

  extattr/rmextattr.c
  	When printing hex output, treat all attribute values as unsigned
  	char arrays instead of sign extending them to 32 bit values.

  extattr/tests/extattr_test.sh
  	Add a regression test

  PR:		209039
  MFC after:	4 weeks
  Sponsored by:	Spectra Logic Corp

Changes:
  head/usr.sbin/extattr/rmextattr.c
  head/usr.sbin/extattr/tests/extattr_test.sh