diff options
author | Kamil Dudka <kdudka@redhat.com> | 2010-11-08 10:17:02 -0500 |
---|---|---|
committer | Andreas Gruenbacher <agruen@suse.de> | 2010-11-23 16:29:19 +0100 |
commit | 7fed4441e12dc794c5eb6ae1798c8338548042ac (patch) | |
tree | 96d3a74ee26ed4ad0768910ef9ae485fcb78752b | |
parent | 846ca47a2411f33c8ca0572b0e565664d851fee4 (diff) | |
download | attr-7fed4441e12dc794c5eb6ae1798c8338548042ac.tar.gz |
getfattr: encode NULs properly with --encoding=text
reported by Paul Bolle at https://bugzilla.redhat.com/650539
-rw-r--r-- | getfattr/getfattr.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/getfattr/getfattr.c b/getfattr/getfattr.c index cae9c3f..9c3de32 100644 --- a/getfattr/getfattr.c +++ b/getfattr/getfattr.c @@ -133,7 +133,7 @@ const char *encode(const char *value, size_t *size) size_t n, extra = 0; for (e=(char *)value; e < value + *size; e++) { - if (*e == '\n' || *e == '\r') + if (*e == '\0' || *e == '\n' || *e == '\r') extra += 4; else if (*e == '\\' || *e == '"') extra++; @@ -147,7 +147,9 @@ const char *encode(const char *value, size_t *size) e = encoded; *e++='"'; for (n = 0; n < *size; n++, value++) { - if (*value == '\n' || *value == '\r') { + if (*value == '\0' && n + 1 == *size) + break; + if (*value == '\0' || *value == '\n' || *value == '\r') { *e++ = '\\'; *e++ = '0' + ((unsigned char)*value >> 6); *e++ = '0' + (((unsigned char)*value & 070) >> 3); |