Added patch to align terminating null WCHAR in SysAllocStringByteLen.

This commit is contained in:
Sebastian Lackner 2015-12-27 18:19:20 +01:00
parent 58890792b7
commit 5d94a2566b
7 changed files with 216 additions and 1 deletions

View File

@ -34,6 +34,11 @@ Wine. All those differences are also documented on the
Included bug fixes and improvements
-----------------------------------
**Bug fixes and features included in the next upcoming release [1]:**
* SysAllocStringByteLen should align terminating null WCHAR
**Bug fixes and features in Wine Staging 1.8 [268]:**
*Note: The following list only contains features and bug fixes which are not

View File

@ -0,0 +1,52 @@
From 58ca159c89e1eb626f287a37320369df5f8ba98e Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Fri, 25 Dec 2015 06:37:44 +0100
Subject: oleaut32: Pass size without terminating null to get_cache_entry.
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
---
dlls/oleaut32/oleaut.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/dlls/oleaut32/oleaut.c b/dlls/oleaut32/oleaut.c
index 0352215..75f9cb4 100644
--- a/dlls/oleaut32/oleaut.c
+++ b/dlls/oleaut32/oleaut.c
@@ -119,7 +119,7 @@ static inline bstr_t *bstr_from_str(BSTR str)
static inline bstr_cache_entry_t *get_cache_entry(size_t size)
{
- unsigned cache_idx = FIELD_OFFSET(bstr_t, u.ptr[size-1])/BUCKET_SIZE;
+ unsigned cache_idx = FIELD_OFFSET(bstr_t, u.ptr[size+sizeof(WCHAR)-1])/BUCKET_SIZE;
return bstr_cache_enabled && cache_idx < sizeof(bstr_cache)/sizeof(*bstr_cache)
? bstr_cache + cache_idx
: NULL;
@@ -127,14 +127,14 @@ static inline bstr_cache_entry_t *get_cache_entry(size_t size)
static bstr_t *alloc_bstr(size_t size)
{
- bstr_cache_entry_t *cache_entry = get_cache_entry(size+sizeof(WCHAR));
+ bstr_cache_entry_t *cache_entry = get_cache_entry(size);
bstr_t *ret;
if(cache_entry) {
EnterCriticalSection(&cs_bstr_cache);
if(!cache_entry->cnt) {
- cache_entry = get_cache_entry(size+sizeof(WCHAR)+BUCKET_SIZE);
+ cache_entry = get_cache_entry(size+BUCKET_SIZE);
if(cache_entry && !cache_entry->cnt)
cache_entry = NULL;
}
@@ -258,7 +258,7 @@ void WINAPI SysFreeString(BSTR str)
return;
bstr = bstr_from_str(str);
- cache_entry = get_cache_entry(bstr->size+sizeof(WCHAR));
+ cache_entry = get_cache_entry(bstr->size);
if(cache_entry) {
unsigned i;
--
2.6.4

View File

@ -0,0 +1,103 @@
From cd1a0baf46ef8d3394fbd7ba220d850a372c172a Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Fri, 25 Dec 2015 06:38:10 +0100
Subject: oleaut32: Align terminating null character in SysAllocStringByteLen.
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
---
dlls/oleaut32/oleaut.c | 14 ++++++--------
dlls/oleaut32/tests/vartype.c | 29 +++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/dlls/oleaut32/oleaut.c b/dlls/oleaut32/oleaut.c
index 75f9cb4..78cb083 100644
--- a/dlls/oleaut32/oleaut.c
+++ b/dlls/oleaut32/oleaut.c
@@ -149,12 +149,9 @@ static bstr_t *alloc_bstr(size_t size)
if(cache_entry) {
if(WARN_ON(heap)) {
- size_t tail;
-
- memset(ret, ARENA_INUSE_FILLER, FIELD_OFFSET(bstr_t, u.ptr[size+sizeof(WCHAR)]));
- tail = bstr_alloc_size(size) - FIELD_OFFSET(bstr_t, u.ptr[size+sizeof(WCHAR)]);
- if(tail)
- memset(ret->u.ptr+size+sizeof(WCHAR), ARENA_TAIL_FILLER, tail);
+ size_t fill_size = (FIELD_OFFSET(bstr_t, u.ptr[size])+2*sizeof(WCHAR)-1) & ~(sizeof(WCHAR)-1);
+ memset(ret, ARENA_INUSE_FILLER, fill_size);
+ memset((char *)ret+fill_size, ARENA_TAIL_FILLER, bstr_alloc_size(size)-fill_size);
}
ret->size = size;
return ret;
@@ -418,10 +415,11 @@ BSTR WINAPI SysAllocStringByteLen(LPCSTR str, UINT len)
if(str) {
memcpy(bstr->u.ptr, str, len);
- bstr->u.ptr[len] = bstr->u.ptr[len+1] = 0;
+ bstr->u.ptr[len] = 0;
}else {
- memset(bstr->u.ptr, 0, len+sizeof(WCHAR));
+ memset(bstr->u.ptr, 0, len+1);
}
+ bstr->u.str[(len+sizeof(WCHAR)-1)/sizeof(WCHAR)] = 0;
return bstr->u.str;
}
diff --git a/dlls/oleaut32/tests/vartype.c b/dlls/oleaut32/tests/vartype.c
index 7cbb059..d905d37 100644
--- a/dlls/oleaut32/tests/vartype.c
+++ b/dlls/oleaut32/tests/vartype.c
@@ -5444,7 +5444,9 @@ static void test_SysAllocStringByteLen(void)
{
const OLECHAR szTest[10] = { 'T','e','s','t','\0' };
const CHAR szTestA[6] = { 'T','e','s','t','\0','?' };
+ char *buf;
BSTR str;
+ int i;
if (sizeof(void *) == 4) /* not limited to 0x80000000 on Win64 */
{
@@ -5487,6 +5489,7 @@ static void test_SysAllocStringByteLen(void)
ok (bstr->dwLen == 3, "Expected 3, got %d\n", bstr->dwLen);
ok (!lstrcmpA((LPCSTR)bstr->szString, szTestTruncA), "String different\n");
+ ok (!bstr->szString[2], "String not terminated\n");
SysFreeString(str);
}
@@ -5500,6 +5503,32 @@ static void test_SysAllocStringByteLen(void)
ok (!lstrcmpW(bstr->szString, szTest), "String different\n");
SysFreeString(str);
}
+
+ /* Make sure terminating null is aligned properly */
+ buf = HeapAlloc(GetProcessHeap(), 0, 1025);
+ ok (buf != NULL, "Expected non-NULL\n");
+ for (i = 0; i < 1024; i++)
+ {
+ LPINTERNAL_BSTR bstr;
+
+ str = SysAllocStringByteLen(NULL, i);
+ ok (str != NULL, "Expected non-NULL\n");
+ bstr = Get(str);
+ ok (bstr->dwLen == i, "Expected %d, got %d\n", i, bstr->dwLen);
+ ok (!bstr->szString[(i+sizeof(WCHAR)-1)/sizeof(WCHAR)], "String not terminated\n");
+ SysFreeString(str);
+
+ memset(buf, 0xaa, 1025);
+ str = SysAllocStringByteLen(buf, i);
+ ok (str != NULL, "Expected non-NULL\n");
+ bstr = Get(str);
+ ok (bstr->dwLen == i, "Expected %d, got %d\n", i, bstr->dwLen);
+ buf[i] = 0;
+ ok (!lstrcmpA((LPCSTR)bstr->szString, buf), "String different\n");
+ ok (!bstr->szString[(i+sizeof(WCHAR)-1)/sizeof(WCHAR)], "String not terminated\n");
+ SysFreeString(str);
+ }
+ HeapFree(GetProcessHeap(), 0, buf);
}
static void test_SysReAllocString(void)
--
2.6.4

View File

@ -0,0 +1,33 @@
From ab8673852c2b53cf96fca841687cdf482b729510 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sun, 27 Dec 2015 18:16:42 +0100
Subject: oleaut32/tests: Test SysStringLen() on string allocated with
SysAllocStringByteLen.
---
dlls/oleaut32/tests/vartype.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/dlls/oleaut32/tests/vartype.c b/dlls/oleaut32/tests/vartype.c
index d905d37..975922f 100644
--- a/dlls/oleaut32/tests/vartype.c
+++ b/dlls/oleaut32/tests/vartype.c
@@ -5515,6 +5515,7 @@ static void test_SysAllocStringByteLen(void)
ok (str != NULL, "Expected non-NULL\n");
bstr = Get(str);
ok (bstr->dwLen == i, "Expected %d, got %d\n", i, bstr->dwLen);
+ ok (SysStringLen(str) == i/sizeof(WCHAR), "Expected %d, got %d\n", i/sizeof(WCHAR), SysStringLen(str));
ok (!bstr->szString[(i+sizeof(WCHAR)-1)/sizeof(WCHAR)], "String not terminated\n");
SysFreeString(str);
@@ -5525,6 +5526,7 @@ static void test_SysAllocStringByteLen(void)
ok (bstr->dwLen == i, "Expected %d, got %d\n", i, bstr->dwLen);
buf[i] = 0;
ok (!lstrcmpA((LPCSTR)bstr->szString, buf), "String different\n");
+ ok (SysStringLen(str) == i/sizeof(WCHAR), "Expected %d, got %d\n", i/sizeof(WCHAR), SysStringLen(str));
ok (!bstr->szString[(i+sizeof(WCHAR)-1)/sizeof(WCHAR)], "String not terminated\n");
SysFreeString(str);
}
--
2.6.4

View File

@ -0,0 +1 @@
Fixes: SysAllocStringByteLen should align terminating null WCHAR

View File

@ -52,7 +52,7 @@ usage()
# Get the upstream commit sha
upstream_commit()
{
echo "6767ac4bb79ad774f0c850a8c4753a2e6fdea75f"
echo "93d7356290bfe5bfd2104f98592790841e33420e"
}
# Show version information
@ -225,6 +225,7 @@ patch_enable_all ()
enable_nvcuda_CUDA_Support="$1"
enable_nvcuvid_CUDA_Video_Support="$1"
enable_nvencodeapi_Video_Encoder="$1"
enable_oleaut32_SysAllocStringByteLen="$1"
enable_oleaut32_TKIND_COCLASS="$1"
enable_oleaut32_x86_64_Marshaller="$1"
enable_openal32_EFX_Extension="$1"
@ -784,6 +785,9 @@ patch_enable ()
nvencodeapi-Video_Encoder)
enable_nvencodeapi_Video_Encoder="$2"
;;
oleaut32-SysAllocStringByteLen)
enable_oleaut32_SysAllocStringByteLen="$2"
;;
oleaut32-TKIND_COCLASS)
enable_oleaut32_TKIND_COCLASS="$2"
;;
@ -4704,6 +4708,22 @@ if test "$enable_nvencodeapi_Video_Encoder" -eq 1; then
) >> "$patchlist"
fi
# Patchset oleaut32-SysAllocStringByteLen
# |
# | Modified files:
# | * dlls/oleaut32/oleaut.c, dlls/oleaut32/tests/vartype.c
# |
if test "$enable_oleaut32_SysAllocStringByteLen" -eq 1; then
patch_apply oleaut32-SysAllocStringByteLen/0001-oleaut32-Pass-size-without-terminating-null-to-get_c.patch
patch_apply oleaut32-SysAllocStringByteLen/0002-oleaut32-Align-terminating-null-character-in-SysAllo.patch
patch_apply oleaut32-SysAllocStringByteLen/0003-oleaut32-tests-Test-SysStringLen-on-string-allocated.patch
(
echo '+ { "Sebastian Lackner", "oleaut32: Pass size without terminating null to get_cache_entry.", 1 },';
echo '+ { "Sebastian Lackner", "oleaut32: Align terminating null character in SysAllocStringByteLen.", 1 },';
echo '+ { "Sebastian Lackner", "oleaut32/tests: Test SysStringLen() on string allocated with SysAllocStringByteLen.", 1 },';
) >> "$patchlist"
fi
# Patchset oleaut32-TKIND_COCLASS
# |
# | This patchset fixes the following Wine bugs:

View File

@ -1,4 +1,5 @@
wine-staging (1.9.0) UNRELEASED; urgency=low
* Added patch to align terminating null WCHAR in SysAllocStringByteLen.
* Removed patch to add a stub driver for tdi.sys (accepted upstream).
* Removed patch to implement support for ws2_32.dll.WSAPoll (accepted
upstream).