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.
This commit is contained in:
Robert Shearman 2005-07-19 19:42:50 +00:00 committed by Alexandre Julliard
parent c0d7a25a42
commit d8780c7546
1 changed files with 24 additions and 20 deletions

View File

@ -565,15 +565,18 @@ serialize_param(
if (writeit) { if (writeit) {
/* ptr to ptr to magic widestring, basically */ /* ptr to ptr to magic widestring, basically */
BSTR *bstr = (BSTR *) *arg; BSTR *bstr = (BSTR *) *arg;
DWORD len;
if (!*bstr) { if (!*bstr) {
/* -1 means "null string" which is equivalent to empty string */ /* -1 means "null string" which is equivalent to empty string */
DWORD fakelen = -1; len = -1;
xbuf_add(buf, (LPBYTE)&fakelen,4); hres = xbuf_add(buf, (LPBYTE)&len,sizeof(DWORD));
if (hres) return hres;
} else { } else {
/* BSTRs store the length behind the first character */ len = *((DWORD*)*bstr-1)/sizeof(WCHAR);
DWORD *len = ((DWORD *)(*bstr))-1; hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
hres = xbuf_add(buf, (LPBYTE) len, *len + 4); if (hres) return hres;
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>"); TRACE_(olerelay)("<bstr NULL>");
} }
if (writeit) { if (writeit) {
if (!*arg) { BSTR bstr = (BSTR)*arg;
DWORD fakelen = -1; DWORD len;
hres = xbuf_add(buf,(LPBYTE)&fakelen,4); if (!bstr) {
if (hres) len = -1;
return hres; hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
if (hres) return hres;
} else { } else {
DWORD *bstr = ((DWORD*)(*arg))-1; len = *((DWORD*)bstr-1)/sizeof(WCHAR);
hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4); if (hres) return hres;
if (hres) hres = xbuf_add(buf,(LPBYTE)bstr,len * sizeof(WCHAR));
return hres; if (hres) return hres;
} }
} }
@ -1139,8 +1143,8 @@ deserialize_param(
**bstr = NULL; **bstr = NULL;
if (debugout) TRACE_(olerelay)("<bstr NULL>"); if (debugout) TRACE_(olerelay)("<bstr NULL>");
} else { } else {
str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR)); str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
hres = xbuf_get(buf,(LPBYTE)str,len); hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
if (hres) { if (hres) {
ERR("Failed to read BSTR.\n"); ERR("Failed to read BSTR.\n");
return hres; return hres;
@ -1169,8 +1173,8 @@ deserialize_param(
*arg = 0; *arg = 0;
if (debugout) TRACE_(olerelay)("<bstr NULL>"); if (debugout) TRACE_(olerelay)("<bstr NULL>");
} else { } else {
str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR)); str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
hres = xbuf_get(buf,(LPBYTE)str,len); hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
if (hres) { if (hres) {
ERR("Failed to read BSTR.\n"); ERR("Failed to read BSTR.\n");
return hres; return hres;