summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2021-01-04 14:16:32 +0100
committerJeremy Allison <jra@samba.org>2021-01-08 20:31:33 +0000
commitd0eaa1432513575264d1b08574c8dcd51dae5e6a (patch)
tree59f77c3f34ea4443f106df73904fd5694fe1d610 /source3/libsmb
parent6aa672a41c37c94afd86e4801b9c1319db0cc6f3 (diff)
downloadsamba-d0eaa1432513575264d1b08574c8dcd51dae5e6a.tar.gz
libsmb: Use hex_byte() in urldecode_talloc()
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/libsmb_path.c49
1 files changed, 15 insertions, 34 deletions
diff --git a/source3/libsmb/libsmb_path.c b/source3/libsmb/libsmb_path.c
index bcbdae325c4..73dc374d6a8 100644
--- a/source3/libsmb/libsmb_path.c
+++ b/source3/libsmb/libsmb_path.c
@@ -27,19 +27,6 @@
#include "libsmb_internal.h"
-/* Used by urldecode_talloc() */
-static int
-hex2int( unsigned int _char )
-{
- if ( _char >= 'A' && _char <='F')
- return _char - 'A' + 10;
- if ( _char >= 'a' && _char <='f')
- return _char - 'a' + 10;
- if ( _char >= '0' && _char <='9')
- return _char - '0';
- return -1;
-}
-
/*
* smbc_urldecode()
* and urldecode_talloc() (internal fn.)
@@ -70,13 +57,10 @@ urldecode_talloc(TALLOC_CTX *ctx, char **pp_dest, const char *src)
unsigned char character = src[i++];
if (character == '%') {
- int a = i+1 < old_length ? hex2int(src[i]) : -1;
- int b = i+1 < old_length ? hex2int(src[i+1]) : -1;
-
- /* Replace valid sequence */
- if (a != -1 && b != -1) {
- /* Replace valid %xx sequence with %dd */
- character = (a * 16) + b;
+ uint8_t v;
+ bool ok = hex_byte(&src[i], &v);
+ if (ok) {
+ character = v;
if (character == '\0') {
break; /* Stop at %00 */
}
@@ -98,20 +82,17 @@ urldecode_talloc(TALLOC_CTX *ctx, char **pp_dest, const char *src)
unsigned char character = src[i++];
if (character == '%') {
- int a = i+1 < old_length ? hex2int(src[i]) : -1;
- int b = i+1 < old_length ? hex2int(src[i+1]) : -1;
-
- /* Replace valid sequence */
- if (a != -1 && b != -1) {
- /* Replace valid %xx sequence with %dd */
- character = (a * 16) + b;
- if (character == '\0') {
- break; /* Stop at %00 */
- }
- i += 2;
- } else {
- err_count++;
- }
+ uint8_t v;
+ bool ok = hex_byte(&src[i], &v);
+ if (ok) {
+ character = v;
+ if (character == '\0') {
+ break; /* Stop at %00 */
+ }
+ i += 2;
+ } else {
+ err_count++;
+ }
}
*p++ = character;
}