[Spice-devel] [vdagent-win PATCH] vdservice: add quotes to service path

agilboa at redhat.com agilboa at redhat.com
Tue Apr 9 06:25:06 PDT 2013


On 04/09/2013 04:12 PM, Hans de Goede wrote:
> Hi,
>
> On 04/09/2013 03:02 PM, Arnon Gilboa wrote:
>> for the case path contains a space, see CreateService() doc:
>> http://msdn.microsoft.com/en-us/library/windows/desktop/ms682450.aspx
>>
>> rhbz #918635
>> ---
>>   vdservice/vdservice.cpp |    8 ++++++--
>>   1 files changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
>> index 9134c4b..89e0dbb 100644
>> --- a/vdservice/vdservice.cpp
>> +++ b/vdservice/vdservice.cpp
>> @@ -170,12 +170,16 @@ bool VDService::install()
>>           printf("OpenSCManager failed\n");
>>           return false;
>>       }
>> -    TCHAR path[_MAX_PATH + 1];
>> -    if (!GetModuleFileName(0, path, sizeof(path) / sizeof(path[0]))) {
>> +    TCHAR path[_MAX_PATH + 2];
>
> Shouldn't that be _MAX_PATH + 3, 2 quotes + 0, or does GetModuleFileName
> already take the terminating 0 into account and was the old + 1 bogus ?
>
The old size given to GetModuleFileName was bogus.
Note in XP:
"The string is truncated to nSize characters and is not null-terminated...
If the buffer is too small to hold the module name, the function returns 
nSize".
That's why we now check (len == 0 || len == _MAX_PATH)
>> +    DWORD len = GetModuleFileName(0, path + 1, _MAX_PATH);
>> +    if (len == 0 || len == _MAX_PATH) {
>>           printf("GetModuleFileName failed\n");
>>           CloseServiceHandle(service_control_manager);
>>           return false;
>>       }
>> +    // add quotes for the case path contains a space (see 
>> CreateService doc)
>> +    path[0] = path[len + 1] = TEXT('\"');
>> +    path[len + 2] = 0;
>>       SC_HANDLE service = CreateService(service_control_manager, 
>> VD_SERVICE_NAME,
>>                                         VD_SERVICE_DISPLAY_NAME, 
>> SERVICE_ALL_ACCESS,
>> SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START,
>>
>
> Regards,
>
> Hans
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel



More information about the Spice-devel mailing list