Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch for bug #61660 #40

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <[email protected]> |
| Stig S�ther Bakken <[email protected]> |
| Stig Sæther Bakken <[email protected]> |
| Zeev Suraski <[email protected]> |
+----------------------------------------------------------------------+
*/
Expand Down Expand Up @@ -153,15 +153,21 @@ static char *php_hex2bin(const unsigned char *old, const size_t oldlen, size_t *
size_t target_length = oldlen >> 1;
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++) {
/* if we have an odd length, point to the end of the string to distinguish the special case */
j = oldlen & 1 == 0 ? 0 : oldlen + 1;
for (i = 0; i < target_length; i++) {
char c = old[j++];
if (c >= '0' && c <= '9') {
str[i] = (c - '0') << 4;
} else if (c >= 'a' && c <= 'f') {
str[i] = (c - 'a' + 10) << 4;
} else if (c >= 'A' && c <= 'F') {
str[i] = (c - 'A' + 10) << 4;
} else {
} else if(c == '\0') {
/* odd length, put the first 4 bits to 0 and restart at the beginning of the string */
str[i] = 0;
j = 0;
} else {
efree(str);
return NULL;
}
Expand Down