diff --git a/apache2/msc_util.c b/apache2/msc_util.c index 5bfe9c5e..427eebf2 100644 --- a/apache2/msc_util.c +++ b/apache2/msc_util.c @@ -419,15 +419,20 @@ char *file_dirname(apr_pool_t *p, const char *filename) { /** * */ -int hex2bytes_inplace(unsigned char *data, int len) { +int sql_hex2bytes_inplace(unsigned char *data, int len) { unsigned char *d = data; - char print = 0; + char print = 0, found = 0; int i, count = 0; if ((data == NULL)||(len == 0)) return 0; for(i = 0; i <= len - 1; i++) { - if(VALID_HEX(data[i]) && VALID_HEX(data[i+1])) { + if(data[i] == 0x30 && data[i+1] == 0x78) { + found = 1; + i++; continue; + } + + if(VALID_HEX(data[i]) && VALID_HEX(data[i+1]) && found) { print = data[i]; if(print > 0x31 && print < 0x38) { *d++ = x2c(&data[i]); @@ -441,6 +446,26 @@ int hex2bytes_inplace(unsigned char *data, int len) { } else { *d++ = data[i]; } + + count++; + } + *d = '\0'; + + return count; +} + +/** + * + * + */ +int hex2bytes_inplace(unsigned char *data, int len) { + unsigned char *d = data; + int i, count = 0; + + if ((data == NULL)||(len == 0)) return 0; + + for(i = 0; i <= len - 2; i += 2) { + *d++ = x2c(&data[i]); count++; } *d = '\0'; diff --git a/apache2/msc_util.h b/apache2/msc_util.h index 8617478c..cde36e94 100644 --- a/apache2/msc_util.h +++ b/apache2/msc_util.h @@ -43,6 +43,8 @@ char DSOLOCAL *file_dirname(apr_pool_t *p, const char *filename); char DSOLOCAL *file_basename(apr_pool_t *p, const char *filename); +int DSOLOCAL sql_hex2bytes_inplace(unsigned char *data, int len); + int DSOLOCAL hex2bytes_inplace(unsigned char *data, int len); char DSOLOCAL *bytes2hex(apr_pool_t *pool, unsigned char *data, int len); diff --git a/tests/tfn/hexDecode.t b/tests/tfn/hexDecode.t index b130d765..ac6b4236 100644 --- a/tests/tfn/hexDecode.t +++ b/tests/tfn/hexDecode.t @@ -21,7 +21,7 @@ type => "tfn", name => "hexDecode", input => "546573740043617365", - output => "Test00Case", + output => "Test\0Case", ret => 1, }, @@ -31,20 +31,20 @@ type => "tfn", name => "hexDecode", input => "01234567890a0z01234567890a", - output => "01#Eg890a0z01#Eg890a", + output => "\x01#Eg\x89\x0a#\x01#Eg\x89\x0a", ret => 1, }, { type => "tfn", name => "hexDecode", input => "01234567890az", - output => "01#Eg890az", + output => "\x01#Eg\x89\x0a", ret => 1, }, { type => "tfn", name => "hexDecode", input => "01234567890a0", - output => "01#Eg890a0", + output => "\x01#Eg\x89\x0a", ret => 1, },