win32 dbus-launch.bat replacement
Ralf Habacker
ralf.habacker at freenet.de
Sun May 27 10:16:03 PDT 2007
Thiago Macieira schrieb:
> Ralf Habacker wrote:
>
>> Thiago Macieira schrieb:
>>
>>> Ralf Habacker wrote:
>>>
>>>> if ((p = strrchr(dbusDaemonPath,'\\'))) {
>>>> *(p+1)= '\0';
>>>> strcat(dbusDaemonPath,"dbus-daemon.exe");
>>>> }
>>>>
>>> This and all other sections like it have the problem of buffer
>>> overruns.
>>>
>>> dbusDaemonPath is MAX_PATH bytes in length, but if the
>>> GetModuleFileName syscall returns something more than MAX_PATH-15,
>>> you'll overrun the end of the buffer when you do strcat.
>>>
>> Then allocating MAX_PATH*2 should solve the problem for any case ?
>>
>
> Not sure. I guess it would be an overkill.
>
> If Windows can't handle more than MAX_PATH paths anywhere on the system,
> then D-Bus surely can't be installed in a place where that limit would be
> reached. However, it could still mean crashes.
>
from http://msdn2.microsoft.com/en-us/library/aa365247.aspx
In the Windows API, the maximum length for a path is MAX_PATH, which is
defined as 260 characters.
A path is structured in the following order: drive letter, colon,
backslash, components separated by backslashes, and a null-terminating
character, for example, the maximum path on the D drive is D:\<256
chars>NUL.
> So, if you allocate MAX_PATH + 1 + the max length of any of the strings
> you strcat, you'll always be safe.
>
>
the resulting command line consists of <path of dbus-daemon> + '
--config-file=' + <absolute path of session config file> which could be
in the worst case MAX_PATH-1+strlen(' --config-file=')+MAX_PATH-1,
so using MAX_PATH*3 would be enough in any non unicode case.
Additional dbus-launch exits immediatly when the dbus-daemon is started,
so this memory is only short time allocated and about 1300 Bytes
(7xMAXPATH) which looks not so an important issue. It is more important
to be sure to not have buffer overflows in any case.
Ralf
Ralf
More information about the dbus
mailing list