#37899 [Opn->Asn]: php_char_to _OLECHAR copies junk bytes

From: Date: Mon, 03 Jul 2006 07:32:11 +0000
Subject: #37899 [Opn->Asn]: php_char_to _OLECHAR copies junk bytes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-99060@lists.php.net to get a copy of this message
ID: 37899 Updated by: tony2001@php.net Reported By: okumurya at hotmail dot com -Status: Open +Status: Assigned Bug Type: COM related Operating System: Windows 2000 Professional PHP Version: 4.4.2 -Assigned To: +Assigned To: wez Previous Comments: ------------------------------------------------------------------------ [2006-07-03 07:31:00] okumurya at hotmail dot com I misunderstand. Revised patch is following. --- ext\com\conversion.c.orig 2006-01-01 22:46:50.000000000 +0900 +++ ext\com\conversion.c 2006-06-23 14:01:42.838476800 +0900 @@ -247,8 +247,9 @@ case VT_BSTR: convert_to_string_ex(&pval_arg); + unicode_str = php_char_to_OLECHAR(Z_STRVAL_P(pval_arg), Z_STRLEN_P(pval_arg), codepage TSRMLS_CC); - V_BSTR(var_arg) = SysAllocStringByteLen((char *) unicode_str, Z_STRLEN_P(pval_arg) * sizeof(OLECHAR)); + V_BSTR(var_arg) = SysAllocString(unicode_str); efree(unicode_str); break; @@ -787,20 +788,15 @@ { BOOL error = FALSE; OLECHAR *unicode_str; + uint unicode_strlen; - if (strlen == -1) { - /* request needed buffersize */ - strlen = MultiByteToWideChar(codepage, (codepage == CP_UTF8 ? 0 : MB_PRECOMPOSED | MB_ERR_INVALID_CHARS), C_str, -1, NULL, 0); - } else { - /* \0 terminator */ - strlen++; - } + unicode_strlen = MultiByteToWideChar(codepage, (codepage == CP_UTF8 ? 0 : MB_PRECOMPOSED | MB_ERR_INVALID_CHARS), C_str, -1, NULL, 0); - if (strlen >= 0) { - unicode_str = (OLECHAR *) emalloc(sizeof(OLECHAR) * strlen); + if (unicode_strlen > 0) { + unicode_str = (OLECHAR *) emalloc(sizeof(OLECHAR) * unicode_strlen); /* convert string */ - error = !MultiByteToWideChar(codepage, (codepage == CP_UTF8 ? 0 : MB_PRECOMPOSED | MB_ERR_INVALID_CHARS), C_str, strlen, unicode_str, strlen); + error = !MultiByteToWideChar(codepage, (codepage == CP_UTF8 ? 0 : MB_PRECOMPOSED | MB_ERR_INVALID_CHARS), C_str, -1, unicode_str, unicode_strlen); } else { /* return a zero-length string */ unicode_str = (OLECHAR *) emalloc(sizeof(OLECHAR)); ------------------------------------------------------------------------ [2006-07-03 07:23:27] okumurya at hotmail dot com change summary ------------------------------------------------------------------------ [2006-06-23 05:09:36] okumurya at hotmail dot com Description: ------------ In UTF-8, 'Z_STRLEN_P(pval_arg) * sizeof(OLECHAR)' is longer than Widechar. So SysAllocStringByteLen copies junk datas. following is a patch. --- conversion.c.orig 2006-06-23 11:28:06.496027200 +0900 +++ conversion.c 2006-06-23 14:01:42.838476800 +0900 @@ -247,8 +247,9 @@ case VT_BSTR: convert_to_string_ex(&pval_arg); + unicode_str = php_char_to_OLECHAR(Z_STRVAL_P(pval_arg), Z_STRLEN_P(pval_arg), codepage TSRMLS_CC); - V_BSTR(var_arg) = SysAllocStringByteLen((char *) unicode_str, Z_STRLEN_P(pval_arg) * sizeof(OLECHAR)); + V_BSTR(var_arg) = SysAllocString(unicode_str); efree(unicode_str); break; ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=37899&edit=1

« previous php.bugs (#99060) next »