Skip to content

Commit

Permalink
advapi32: Fix ChangeServiceConfig2 when given a null description.
Browse files Browse the repository at this point in the history
Signed-off-by: Bernhard Übelacker <[email protected]>
Signed-off-by: Alexandre Julliard <[email protected]>
  • Loading branch information
bernhardu authored and julliard committed Oct 12, 2017
1 parent 825f393 commit de7220e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
66 changes: 66 additions & 0 deletions dlls/advapi32/tests/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static const CHAR spooler[] = "Spooler"; /* Should be available on all platforms
static CHAR selfname[MAX_PATH];

static BOOL (WINAPI *pChangeServiceConfig2A)(SC_HANDLE,DWORD,LPVOID);
static BOOL (WINAPI *pChangeServiceConfig2W)(SC_HANDLE,DWORD,LPVOID);
static BOOL (WINAPI *pEnumServicesStatusExA)(SC_HANDLE, SC_ENUM_TYPE, DWORD,
DWORD, LPBYTE, DWORD, LPDWORD,
LPDWORD, LPDWORD, LPCSTR);
Expand All @@ -57,6 +58,7 @@ static void init_function_pointers(void)
HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");

pChangeServiceConfig2A = (void*)GetProcAddress(hadvapi32, "ChangeServiceConfig2A");
pChangeServiceConfig2W = (void*)GetProcAddress(hadvapi32, "ChangeServiceConfig2W");
pEnumServicesStatusExA= (void*)GetProcAddress(hadvapi32, "EnumServicesStatusExA");
pEnumServicesStatusExW= (void*)GetProcAddress(hadvapi32, "EnumServicesStatusExW");
pGetSecurityInfo = (void *)GetProcAddress(hadvapi32, "GetSecurityInfo");
Expand Down Expand Up @@ -1954,13 +1956,17 @@ static void test_queryconfig2(void)
DWORD expected, needed;
BYTE buffer[MAX_PATH];
LPSERVICE_DESCRIPTIONA pConfig = (LPSERVICE_DESCRIPTIONA)buffer;
LPSERVICE_DESCRIPTIONW pConfigW = (LPSERVICE_DESCRIPTIONW)buffer;
SERVICE_PRESHUTDOWN_INFO preshutdown_info;
static const CHAR servicename [] = "Winetest";
static const CHAR displayname [] = "Winetest dummy service";
static const CHAR pathname [] = "we_dont_care.exe";
static const CHAR dependencies[] = "Master1\0Master2\0+MasterGroup1\0";
static const CHAR password [] = "";
static const CHAR description [] = "Description";
static const CHAR description_empty[] = "";
static const WCHAR descriptionW [] = {'D','e','s','c','r','i','p','t','i','o','n','W',0};
static const WCHAR descriptionW_empty[] = {0};

if(!pQueryServiceConfig2A)
{
Expand Down Expand Up @@ -2121,6 +2127,66 @@ static void test_queryconfig2(void)
ret = pQueryServiceConfig2W(svc_handle, SERVICE_CONFIG_DESCRIPTION,buffer, needed,&needed);
ok(ret, "expected QueryServiceConfig2W to succeed\n");

pConfig->lpDescription = (LPSTR)description;
ret = pChangeServiceConfig2A(svc_handle, SERVICE_CONFIG_DESCRIPTION, &buffer);
ok(ret, "expected ChangeServiceConfig2A to succeed\n");

pConfig->lpDescription = NULL;
ret = pQueryServiceConfig2A(svc_handle, SERVICE_CONFIG_DESCRIPTION, buffer, sizeof(buffer), &needed);
ok(ret, "expected QueryServiceConfig2A to succeed\n");
ok(pConfig->lpDescription && !strcmp(description, pConfig->lpDescription),
"expected lpDescription to be %s, got %s\n", description, pConfig->lpDescription);

pConfig->lpDescription = NULL;
ret = pChangeServiceConfig2A(svc_handle, SERVICE_CONFIG_DESCRIPTION, &buffer);
ok(ret, "expected ChangeServiceConfig2A to succeed\n");

pConfig->lpDescription = NULL;
ret = pQueryServiceConfig2A(svc_handle, SERVICE_CONFIG_DESCRIPTION, buffer, sizeof(buffer), &needed);
ok(ret, "expected QueryServiceConfig2A to succeed\n");
ok(pConfig->lpDescription && !strcmp(description, pConfig->lpDescription),
"expected lpDescription to be %s, got %s\n", description, pConfig->lpDescription);

pConfig->lpDescription = (LPSTR)description_empty;
ret = pChangeServiceConfig2A(svc_handle, SERVICE_CONFIG_DESCRIPTION, &buffer);
ok(ret, "expected ChangeServiceConfig2A to succeed\n");

pConfig->lpDescription = (void*)0xdeadbeef;
ret = pQueryServiceConfig2A(svc_handle, SERVICE_CONFIG_DESCRIPTION, buffer, sizeof(buffer), &needed);
ok(ret, "expected QueryServiceConfig2A to succeed\n");
ok(!pConfig->lpDescription,
"expected lpDescription to be null, got %s\n", pConfig->lpDescription);

pConfigW->lpDescription = (LPWSTR)descriptionW;
ret = pChangeServiceConfig2W(svc_handle, SERVICE_CONFIG_DESCRIPTION, &buffer);
ok(ret, "expected ChangeServiceConfig2W to succeed\n");

pConfigW->lpDescription = NULL;
ret = pQueryServiceConfig2W(svc_handle, SERVICE_CONFIG_DESCRIPTION, buffer, sizeof(buffer), &needed);
ok(ret, "expected QueryServiceConfig2A to succeed\n");
ok(pConfigW->lpDescription && !lstrcmpW(descriptionW, pConfigW->lpDescription),
"expected lpDescription to be %s, got %s\n", wine_dbgstr_w(descriptionW), wine_dbgstr_w(pConfigW->lpDescription));

pConfigW->lpDescription = NULL;
ret = pChangeServiceConfig2W(svc_handle, SERVICE_CONFIG_DESCRIPTION, &buffer);
ok(ret, "expected ChangeServiceConfig2W to succeed\n");

pConfigW->lpDescription = NULL;
ret = pQueryServiceConfig2W(svc_handle, SERVICE_CONFIG_DESCRIPTION, buffer, sizeof(buffer), &needed);
ok(ret, "expected QueryServiceConfig2A to succeed\n");
ok(pConfigW->lpDescription && !lstrcmpW(descriptionW, pConfigW->lpDescription),
"expected lpDescription to be %s, got %s\n", wine_dbgstr_w(descriptionW), wine_dbgstr_w(pConfigW->lpDescription));

pConfigW->lpDescription = (LPWSTR)descriptionW_empty;
ret = pChangeServiceConfig2W(svc_handle, SERVICE_CONFIG_DESCRIPTION, &buffer);
ok(ret, "expected ChangeServiceConfig2W to succeed\n");

pConfigW->lpDescription = (void*)0xdeadbeef;
ret = pQueryServiceConfig2W(svc_handle, SERVICE_CONFIG_DESCRIPTION, buffer, sizeof(buffer), &needed);
ok(ret, "expected QueryServiceConfig2A to succeed\n");
ok(!pConfigW->lpDescription,
"expected lpDescription to be null, got %s\n", wine_dbgstr_w(pConfigW->lpDescription));

SetLastError(0xdeadbeef);
ret = pQueryServiceConfig2W(svc_handle, SERVICE_CONFIG_PRESHUTDOWN_INFO,
(LPBYTE)&preshutdown_info, sizeof(preshutdown_info), &needed);
Expand Down
3 changes: 3 additions & 0 deletions programs/services/rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,9 @@ DWORD __cdecl svcctl_ChangeServiceConfig2W( SC_RPC_HANDLE hService, SC_RPC_CONFI
{
WCHAR *descr = NULL;

if (!config.u.descr->lpDescription)
break;

if (config.u.descr->lpDescription[0])
{
if (!(descr = strdupW( config.u.descr->lpDescription )))
Expand Down

0 comments on commit de7220e

Please sign in to comment.