diff options
| author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-11-16 15:41:57 +0100 | 
|---|---|---|
| committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-11-18 00:58:07 +0100 | 
| commit | da6eadc840716eb29b0175f39b2790bba166db4a (patch) | |
| tree | 2da0a94126432e7af409ed809ea3476a1e44597c /bin | |
| parent | 0f68ca18f491b4e53cec788b327a752cbeb43377 (diff) | |
Add a single, central hex blob decoder
Since we need it twice (once for tar, once for the filemap xattr
parser), add a single, central implementation to libutil, add a
unit test for that implementation and then use it in both libtar
and gensquashfs.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/gensquashfs/filemap_xattr.c | 43 | 
1 files changed, 6 insertions, 37 deletions
| diff --git a/bin/gensquashfs/filemap_xattr.c b/bin/gensquashfs/filemap_xattr.c index 44ed9de..059ce81 100644 --- a/bin/gensquashfs/filemap_xattr.c +++ b/bin/gensquashfs/filemap_xattr.c @@ -12,19 +12,6 @@  // Taken from attr-2.5.1/tools/setfattr.c  static int -hex_digit(char c) { -	if (c >= '0' && c <= '9') -		return c - '0'; -	else if (c >= 'A' && c <= 'F') -		return c - 'A' + 10; -	else if (c >= 'a' && c <= 'f') -		return c - 'a' + 10; -	else -		return -1; -} - -// Taken from attr-2.5.1/tools/setfattr.c -static int  base64_digit(char c) {  	if (c >= 'A' && c <= 'Z')  		return c - 'A'; @@ -50,36 +37,18 @@ decode(const char *value, size_t *size) {  	if (*size == 0)  		return strdup("");  	if (value[0] == '0' && (value[1] == 'x' || value[1] == 'X')) { -		const char *v = value + 2, *end = value + *size; -		char *d; +		*size = ((*size) - 2) / 2; -		decoded = realloc(decoded, *size / 2); +		decoded = realloc(decoded, *size);  		if (decoded == NULL) {  			return NULL;  		} -		d = decoded; -		while (v < end) { -			int d1, d0; -			while (v < end && isspace(*v)) -				v++; -			if (v == end) -				break; -			d1 = hex_digit(*v++); -			while (v < end && isspace(*v)) -				v++; -			if (v == end) { -			bad_hex_encoding: -				fprintf(stderr, "bad input encoding\n"); -				free(decoded); -				return NULL; -			} -			d0 = hex_digit(*v++); -			if (d1 < 0 || d0 < 0) -				goto bad_hex_encoding; -			*d++ = ((d1 << 4) | d0); +		if (hex_decode(value + 2, (*size) * 2, decoded, *size)) { +			fprintf(stderr, "bad input encoding\n"); +			free(decoded); +			return NULL;  		} -		*size = d - decoded;  	} else if (value[0] == '0' && (value[1] == 's' || value[1] == 'S')) {  		const char *v = value + 2, *end = value + *size;  		int d0, d1, d2, d3; | 
