diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-11-19 20:14:14 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-11-21 15:25:53 +0100 |
commit | 40ccc8ce7c2008892d6ac1c12816438fd71b90cb (patch) | |
tree | 462dd17bc59abefa6cf9547ccfa8f963426f8351 /bin/gensquashfs/filemap_xattr.c | |
parent | 7bf4cc03d379bdd71c61982abde2355c578e4ef2 (diff) |
filemap xattr: use sqfs_u8 data type for xattr value blobs
The xattr values are not strings, they are arbitrary byte blobs.
To be on the safe side tough, we should still allocate the space for
the extra null byte and propperly initialize the buffer.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/gensquashfs/filemap_xattr.c')
-rw-r--r-- | bin/gensquashfs/filemap_xattr.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/bin/gensquashfs/filemap_xattr.c b/bin/gensquashfs/filemap_xattr.c index e5a16be..a6919b6 100644 --- a/bin/gensquashfs/filemap_xattr.c +++ b/bin/gensquashfs/filemap_xattr.c @@ -11,16 +11,17 @@ #define NEW_FILE_START "# file: " // Taken from attr-2.5.1/tools/setfattr.c -static char * -decode(const char *value, size_t *size) { - char *decoded = NULL; +static sqfs_u8 *decode(const char *value, size_t *size) +{ + sqfs_u8 *decoded = NULL; if (*size == 0) - return strdup(""); + return (sqfs_u8 *)strdup(""); + if (value[0] == '0' && (value[1] == 'x' || value[1] == 'X')) { *size = ((*size) - 2) / 2; - decoded = realloc(decoded, *size); + decoded = calloc(1, (*size) + 1); if (decoded == NULL) { return NULL; } @@ -35,7 +36,7 @@ decode(const char *value, size_t *size) { *size = (input_len / 4) * 3; - decoded = realloc(decoded, *size); + decoded = calloc(1, (*size) + 1); if (decoded == NULL) { return NULL; } @@ -47,17 +48,18 @@ decode(const char *value, size_t *size) { } } else { const char *v = value, *end = value + *size; - char *d; + sqfs_u8 *d; if (end > v + 1 && *v == '"' && *(end - 1) == '"') { v++; end--; } - decoded = realloc(decoded, *size); + decoded = calloc(1, (*size) + 1); if (decoded == NULL) { return NULL; } + d = decoded; while (v < end) { |