From dccc4283a7848eafc53d99512bc39d1d8bacb018 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Thu, 15 May 2014 17:52:52 +0200 Subject: [PATCH] oleacc: Don't return partial data in GetRoleTextA if buffer is too small. --- dlls/oleacc/main.c | 6 ++++++ dlls/oleacc/tests/main.c | 11 +++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dlls/oleacc/main.c b/dlls/oleacc/main.c index 36349917d98..37d2269e26c 100644 --- a/dlls/oleacc/main.c +++ b/dlls/oleacc/main.c @@ -396,6 +396,12 @@ UINT WINAPI GetRoleTextA(DWORD role, LPSTR lpRole, UINT rolemax) return length - 1; } + if(rolemax < length) { + HeapFree(GetProcessHeap(), 0, roletextW); + lpRole[0] = 0; + return 0; + } + WideCharToMultiByte( CP_ACP, 0, roletextW, -1, lpRole, rolemax, NULL, NULL ); if(rolemax < length){ diff --git a/dlls/oleacc/tests/main.c b/dlls/oleacc/tests/main.c index 121a5d71a6c..be30da360a8 100644 --- a/dlls/oleacc/tests/main.c +++ b/dlls/oleacc/tests/main.c @@ -87,13 +87,16 @@ static void test_getroletext(void) ret = GetRoleTextA(ROLE_SYSTEM_TITLEBAR, buf, 1); ok(ret == 0, "GetRoleTextA returned wrong length\n"); ok(buf[0] == '\0', "GetRoleTextA returned not zero-length buffer\n"); - buf[1] = '*'; + buf[0] = '*'; ret = GetRoleTextA(ROLE_SYSTEM_TITLEBAR, buf, 2); - ok(ret == 1 || + ok(broken(ret == 1) || ret == 0, /* Vista and W2K8 */ "GetRoleTextA returned wrong length, got %d, expected 0 or 1\n", ret); - if (ret == 1) - ok(buf[1] == '\0', "GetRoleTextA returned not zero-length buffer : (%c)\n", buf[1]); + if (ret == 0) { + ok(!buf[0] || + broken(buf[0]!='*') /* WinXP */, + "GetRoleTextA returned not zero-length buffer : (%c)\n", buf[0]); + } bufW[0] = '*'; ret = GetRoleTextW(ROLE_SYSTEM_TITLEBAR, bufW, 1);