From ebac2da962bfaae01388195a36954718b3b5b146 Mon Sep 17 00:00:00 2001 From: "theanomaly.is@gmail.com" Date: Sun, 8 Apr 2012 07:34:26 -0400 Subject: [PATCH 1/4] fix for bug 61660 (hex2bin will now always return an even length string 0 padded) --- ext/standard/string.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index 0aade780856b9..174f587e3d18a 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -151,10 +151,20 @@ static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t * static char *php_hex2bin(const unsigned char *old, const size_t oldlen, size_t *newlen) { size_t target_length = oldlen >> 1; + int e; + e = oldlen & 1; + if (e) { + target_length++; + } register unsigned char *str = (unsigned char *)safe_emalloc(target_length, sizeof(char), 1); size_t i, j; for (i = j = 0; i < target_length; i++) { - char c = old[j++]; + char c = '0'; + if (j == 0 && e) { + c = '0'; + } else { + c = old[j++]; + } if (c >= '0' && c <= '9') { str[i] = (c - '0') << 4; } else if (c >= 'a' && c <= 'f') { From 6fd75d644dcf3a82aa83fe43f7e8e8f6cb189504 Mon Sep 17 00:00:00 2001 From: "theanomaly.is@gmail.com" Date: Sun, 8 Apr 2012 07:44:14 -0400 Subject: [PATCH 2/4] Bug fix test for bug #61660 --- ext/standard/tests/strings/61660.phpt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 ext/standard/tests/strings/61660.phpt diff --git a/ext/standard/tests/strings/61660.phpt b/ext/standard/tests/strings/61660.phpt new file mode 100644 index 0000000000000..5316b50a9b90b --- /dev/null +++ b/ext/standard/tests/strings/61660.phpt @@ -0,0 +1,9 @@ +--TEST-- +hex2bin() function +--FILE-- + +--EXPECT-- +012345 From 5857270ad1c774e2b85a6d0412028a9cc5a664a7 Mon Sep 17 00:00:00 2001 From: "theanomaly.is@gmail.com" Date: Sun, 8 Apr 2012 07:54:30 -0400 Subject: [PATCH 3/4] ammended bugfix 61660 --- ext/standard/string.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index 174f587e3d18a..f301f74fe9694 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -151,8 +151,7 @@ static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t * static char *php_hex2bin(const unsigned char *old, const size_t oldlen, size_t *newlen) { size_t target_length = oldlen >> 1; - int e; - e = oldlen & 1; + int e = oldlen & 1; if (e) { target_length++; } From 886e770dfb16a1ea52d90c2a456f8ac219bd1f7f Mon Sep 17 00:00:00 2001 From: "theanomaly.is@gmail.com" Date: Sun, 8 Apr 2012 08:01:03 -0400 Subject: [PATCH 4/4] ammending bugid #61660 (removed initialized char c value) --- ext/standard/string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index f301f74fe9694..bf8e5640344eb 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -158,7 +158,7 @@ static char *php_hex2bin(const unsigned char *old, const size_t oldlen, size_t * register unsigned char *str = (unsigned char *)safe_emalloc(target_length, sizeof(char), 1); size_t i, j; for (i = j = 0; i < target_length; i++) { - char c = '0'; + char c; if (j == 0 && e) { c = '0'; } else {