Module: wine Branch: master Commit: f621f8ea787df007b55e4369563502eb69cc421b URL: http://source.winehq.org/git/wine.git/?a=commit;h=f621f8ea787df007b55e436956...
Author: Bruno Jesus 00cpxxx@gmail.com Date: Tue Oct 25 23:35:13 2011 -0200
shell32: Don't parse command line if numargs is NULL in CommandLineToArgvW.
---
dlls/shell32/shell32_main.c | 12 ++++++++---- dlls/shell32/tests/shlexec.c | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/dlls/shell32/shell32_main.c b/dlls/shell32/shell32_main.c index 981a245..2561f8c 100644 --- a/dlls/shell32/shell32_main.c +++ b/dlls/shell32/shell32_main.c @@ -92,6 +92,12 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs) LPWSTR cmdline; int in_quotes,bcount;
+ if(!numargs) + { + SetLastError(ERROR_INVALID_PARAMETER); + return NULL; + } + if (*lpCmdline==0) { /* Return the path to the executable */ @@ -113,8 +119,7 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs) LocalFree( argv ); } argv[0]=(LPWSTR)(argv+1); - if (numargs) - *numargs=1; + *numargs=1;
return argv; } @@ -228,8 +233,7 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs) *d='\0'; argv[argc++]=arg; } - if (numargs) - *numargs=argc; + *numargs=argc;
return argv; } diff --git a/dlls/shell32/tests/shlexec.c b/dlls/shell32/tests/shlexec.c index 5542ea5..1c5fe7f 100644 --- a/dlls/shell32/tests/shlexec.c +++ b/dlls/shell32/tests/shlexec.c @@ -2157,6 +2157,7 @@ static void test_commandline(void) LPWSTR *args = (LPWSTR*)0xdeadcafe, pbuf; INT numargs = -1; size_t buflen; + DWORD lerror;
wsprintfW(cmdline,fmt1,one,two,three,four); args=CommandLineToArgvW(cmdline,&numargs); @@ -2171,6 +2172,15 @@ static void test_commandline(void) ok(lstrcmpW(args[2],three)==0,"arg2 is not as expected\n"); ok(lstrcmpW(args[3],four)==0,"arg3 is not as expected\n");
+ SetLastError(0xdeadbeef); + args=CommandLineToArgvW(cmdline,NULL); + lerror=GetLastError(); + ok(args == NULL && lerror == ERROR_INVALID_PARAMETER, "expected NULL with ERROR_INVALID_PARAMETER got %p with %d\n",args,lerror); + SetLastError(0xdeadbeef); + args=CommandLineToArgvW(NULL,NULL); + lerror=GetLastError(); + ok(args == NULL && lerror == ERROR_INVALID_PARAMETER, "expected NULL with ERROR_INVALID_PARAMETER got %p with %d\n",args,lerror); + wsprintfW(cmdline,fmt2,one,two,three,four); args=CommandLineToArgvW(cmdline,&numargs); ok(numargs == 5, "expected 5 args, got %i\n",numargs);