Make cmdline writable (cmdline4)

Francois Gouget fgouget at free.fr
Fri Sep 7 12:41:22 CDT 2001


On 7 Sep 2001, Alexandre Julliard wrote:

> Francois Gouget <fgouget at free.fr> writes:
> 
> >    CreateProcess may modify the command line that was passed as a
> > parameter. It does this not in the current process but in the child
> > process so that the caller may not realize it, but it may hit a snag if
> > the command line is not writable in the first place.
> 
> But the command line parameter is a LPSTR, so CreateProcess is allowed
> to modify it and the caller is not supposed to pass a const string. In
> what case does this cause a problem?

   In the case below. Works on Win98 but not in Wine. I believe the
reason is that Windows does not need to modify the command line anyway.
It just passes it as is to the child process. We, on the contrary, have
to convert it to argc/argv form and then convert it back.

--- cut here ---
#include <stdio.h>
#include <windows.h>

const char* cmdline="main a b";

int main(int argc,char** argv)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    int rc;

    memset(&si,'\0',sizeof(si));
    si.cb=sizeof(si);
    rc=CreateProcess(NULL,cmdline,
                     NULL,NULL,FALSE,0,NULL,NULL,
                     &si,&pi);
    printf("CreateProcess returned: %d error=%ld\n",rc,GetLastError());
    printf("cmdline=[%s]\n",cmdline);
    WaitForSingleObject(pi.hProcess,INFINITE);
    return 0;
}
--- cut here ---

   I did not test but I suspect that system("main a b") would fail
in the same way.


--
Francois Gouget         fgouget at free.fr        http://fgouget.free.fr/
                         Stolen from an Internet user:
              "f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng !"





More information about the wine-devel mailing list