Commit d8780c75 authored by Robert Shearman's avatar Robert Shearman Committed by Alexandre Julliard

Fix confusion between number of characters and number of bytes in

unmarshaling BSTRs. Convert it all to characters for consistency with the BSTR_User* routines.
parent c0d7a25a
......@@ -565,14 +565,17 @@ serialize_param(
if (writeit) {
/* ptr to ptr to magic widestring, basically */
BSTR *bstr = (BSTR *) *arg;
DWORD len;
if (!*bstr) {
/* -1 means "null string" which is equivalent to empty string */
DWORD fakelen = -1;
xbuf_add(buf, (LPBYTE)&fakelen,4);
len = -1;
hres = xbuf_add(buf, (LPBYTE)&len,sizeof(DWORD));
if (hres) return hres;
} else {
/* BSTRs store the length behind the first character */
DWORD *len = ((DWORD *)(*bstr))-1;
hres = xbuf_add(buf, (LPBYTE) len, *len + 4);
len = *((DWORD*)*bstr-1)/sizeof(WCHAR);
hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
if (hres) return hres;
hres = xbuf_add(buf,(LPBYTE)*bstr,len * sizeof(WCHAR));
if (hres) return hres;
}
}
......@@ -592,17 +595,18 @@ serialize_param(
TRACE_(olerelay)("<bstr NULL>");
}
if (writeit) {
if (!*arg) {
DWORD fakelen = -1;
hres = xbuf_add(buf,(LPBYTE)&fakelen,4);
if (hres)
return hres;
BSTR bstr = (BSTR)*arg;
DWORD len;
if (!bstr) {
len = -1;
hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
if (hres) return hres;
} else {
DWORD *bstr = ((DWORD*)(*arg))-1;
hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
if (hres)
return hres;
len = *((DWORD*)bstr-1)/sizeof(WCHAR);
hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
if (hres) return hres;
hres = xbuf_add(buf,(LPBYTE)bstr,len * sizeof(WCHAR));
if (hres) return hres;
}
}
......@@ -1139,8 +1143,8 @@ deserialize_param(
**bstr = NULL;
if (debugout) TRACE_(olerelay)("<bstr NULL>");
} else {
str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
hres = xbuf_get(buf,(LPBYTE)str,len);
str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
if (hres) {
ERR("Failed to read BSTR.\n");
return hres;
......@@ -1169,8 +1173,8 @@ deserialize_param(
*arg = 0;
if (debugout) TRACE_(olerelay)("<bstr NULL>");
} else {
str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
hres = xbuf_get(buf,(LPBYTE)str,len);
str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
if (hres) {
ERR("Failed to read BSTR.\n");
return hres;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment