View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0003471CMakeCMakepublic2006-07-02 15:502006-10-09 20:02
ReporterCraig Ringer 
Assigned ToBrad King 
PrioritylowSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0003471: CMake crashes on win32 when EXEC_PROCESS(....) called with a target that exists but isn't executable
DescriptionCMake version: 2.5-20060702

CMake crashes when EXEC_PROCESS(...) is called with a target file that exists, but is not executable (at least on XP SP2; other win32 versions and other platforms not tested).

CMake was built from today's sources (2006-07-03 02:00 +0800 time) using MinGW (mingw32-make version 3.80, gcc version 3.4.2).

I'll attach a simple test case.

Still looking into the details of the crash, as I'm very new to development on win32. I haven't been able to run cmake under gdb yet, nor can I get a useful backtrace out of windbg (the latter presumably due to incompatible debug symbols).

I encountered this bug when running FREETYPEConfig.cmake under MinGW (and msys; same problem) while trying to get Scribus to build with MinGW and CMake. So it's not a purely abstract "why on earth would you do that" issue. FREETYPEConfig tries to execute freetype-config to get the libs and includes strings ... but on win32, freetype-config isn't executable, it's just text. *splat*.
TagsNo tags attached.
Attached Fileszip file icon fttest.zip [^] (19,489 bytes) 1969-12-31 19:00

 Relationships

  Notes
(0005205)
Brad King (manager)
2006-10-04 19:09

I just tried your example and several variations I constructed by hand using the current CVS version of CMake. Can you still reproduce this?
(0005229)
Craig Ringer (reporter)
2006-10-04 22:31

I actually can't build current CVS:

---
g++ -I/d/developer/cmake/Source -I/d/developer/cmake/Bootstrap.cmk -c /d/developer/cmake/Source/cmBootstrapCommands.cxx -o cmBootstrapCommands.o
In file included from d:/developer/cmake/Source/cmBootstrapCommands.cxx:38:
d:/developer/cmake/Source/cmFileCommand.cxx: In member function `bool cmFileCommand::HandleInstallCommand(const std::vector<std::string, std::allocator<std::string> >&)':
d:/developer/cmake/Source/cmFileCommand.cxx:1168: error: no matching function for call to `cmsys::SystemTools::JoinPath(__gnu_cxx::__normal_iterator<std::string*, std::vector<std::string, std::allocator<std::string> > >, __gnu_cxx::__normal_iterator<std::string*, std::vector<std::string, std::allocator<std::string> > >)'
d:/developer/cmake/Source/cmsys/SystemTools.hxx:351: note: candidates are: static std::string cmsys::SystemTools::JoinPath(const std::vector<std::string, std::allocator<std::string> >&
---

---
$ g++ --version
g++.exe (GCC) 3.4.2 (mingw-special)
(run under msys using CMake's `configure')
---

... so it's a bit hard to tell. I haven't retried or updated CMake since I reported this issue, but I do know that one of the other Scribus developers encountered what looked like this same crash about two weeks ago, and he'd just downloaded and built CMake.

I just retried, using CMake to bootstrap its self (generating MinGW makefiles) instead of building with configure and mingw32-make from msys. It built correctly, which I find interesting.

The new CMake (2.5-20061004) built from today's CVS still crashes on that test case here.
(0005237)
Brad King (manager)
2006-10-05 09:54

I don't know why it doesn't build for you. There are several machines that build CMake every night with MSYS. I just bootstrapped CMake from scratch using an MSYS prompt and ./bootstrap (./configure just calls ./boostrap).

I'm using

$ g++ --version
g++.exe (GCC) 3.4.2 (mingw-special)

I moved on to your test case.

In an out-of-source build I get this error:

CreateProcessError: The system cannot find the file specified.

for command: ./dummy-program

and no creash. In an in-source build I get this error:

CreateProcessError: Access is denied.

for command: ./dummy-program

and no crash.

If you are able please build in debug mode and trace the crash yourself. Thanks.
(0005254)
Craig Ringer (reporter)
2006-10-05 12:01

It's odd that it doesn't crash there. If you specify an absolute path to dummy-program does the behaviour change?

I see the same crash with in-tree and out-of-tree builds. CMake is run from the command line. It does not matter what Makefile generator I use - at least MinGW, MSYS, and VS 8 2005 makefile generation modes produce the same error.

I'll have a go at tracing it myself. Unfortunately I'm completely new to all Windows debugging (I'm a *nix user by strong preference and long experience). I would've provided a backtrace when initially filing the report if I'd had the faintest idea how to get one under Windows, and I haven't had much luck finding out about debugging under MinGW since. I haven't had much luck with gdb.

It seems unlikely to be related to dynamic linkage problems - `cmake.exe' is linked only to AVAPI32.DLL, KERNEL32.DLL, MSVCRT.DLL, RPCRT4.DLL and USER32.DLL according to dependency walker.

I get the same crash when running a MSVC++ (Express Edition) debug build, so it doesn't seem to be something going wrong with the MinGW build. Handily that means I can use VC++'s debugger, which is less familiar but I can actually get to work on Windows, so I might be able to have that backtrace for you soon.
(0005255)
Craig Ringer (reporter)
2006-10-05 12:15

MSVC++ reports the following error on the initial crash:

Unhandled exception at 0x1022fb10 in cmake.exe: 0xC0000005: Access violation reading location 0x00000000.

Backtrace:

     msvcr80d.dll!1022fb10()
     [Frames below may be incorrect and/or missing, no symbols loaded for msvcr80d.dll]
> cmake.exe!RealPopenCreateProcess(const char * cmdstring=0x01580f70, const char * path=0x00000000, const char * szConsoleSpawn=0x0115e7c4, void * hStdin=0x000017c4, void * hStdout=0x000017c0, void * hStderr=0x000017b8, void * * hProcess=0x0115e6c0, bool hideWindows=false, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & output="") Line 460 + 0xc bytes C++
     cmake.exe!cmWin32ProcessExecution::PrivateOpen(const char * cmdstring=0x01580f70, const char * path=0x00000000, int mode=16384, int n=3) Line 648 + 0x4a bytes C++
     cmake.exe!cmWin32ProcessExecution::StartProcess(const char * cmd=0x01580f70, const char * path=0x00000000, bool verbose=true) Line 269 C++
     cmake.exe!RunCommandViaWin32(const char * command=0x01580f70, const char * dir=0x00000000, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & output="", int & retVal=0, bool verbose=true, int timeout=0) Line 637 + 0x17 bytes C++
     cmake.exe!cmSystemTools::RunCommand(const char * command=0x01580f70, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & output="", int & retVal=0, const char * dir=0x00000000, bool verbose=true, int timeout=0) Line 884 + 0x1d bytes C++
     cmake.exe!cmExecProgramCommand::InitialPass(const std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > & args=[1]("D:/Developer/Scribus/fttest/dummy-program")) Line 116 + 0x34 bytes C++
     cmake.exe!cmCommand::InvokeInitialPass(const std::vector<cmListFileArgument,std::allocator<cmListFileArgument> > & args=[1]({Value="D:/Developer/Scribus/fttest/dummy-program" Quoted=true FilePath=0x0157cab0 "d:/Developer/Scribus/fttest/CMakeLists.txt" ...},...)) Line 66 + 0x13 bytes C++
     cmake.exe!cmMakefile::ExecuteCommand(const cmListFileFunction & lff={...}) Line 324 + 0x1c bytes C++
     cmake.exe!cmMakefile::ReadListFile(const char * filename_in=0x0157cab0, const char * external_in=0x00000000) Line 467 C++
     cmake.exe!cmLocalGenerator::Configure() Line 69 C++
     cmake.exe!cmLocalUnixMakefileGenerator3::Configure() Line 72 C++
     cmake.exe!cmGlobalGenerator::Configure() Line 618 + 0xf bytes C++
     cmake.exe!cmake::Configure() Line 1598 + 0x15 bytes C++
     cmake.exe!cmake::Run(const std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > & args=[3]("d:\Developer\CMake\bin\debug\cmake.exe","-G","MinGW Makefiles"), bool noconfigure=false) Line 1771 + 0x8 bytes C++
     cmake.exe!do_cmake(int ac=3, char * * av=0x00255da0) Line 269 + 0x19 bytes C++
     cmake.exe!main(int ac=3, char * * av=0x00255da0) Line 128 + 0xd bytes C++
     cmake.exe!__tmainCRTStartup() Line 586 + 0x19 bytes C
     cmake.exe!mainCRTStartup() Line 403 C


The crash appears to be when strcpy()ing a message buffer generated by a FormatMessage() call prior to LocalFree()ing it. The crash seems to be when informing the user that CreateProcess failed.

lpMsgBuf is 0 (the FormatMessage failed?) so it makes sense that it crashes at this point - either in the strlen or strcpy presumably. I should be able to tell, but MSVC++ doesn't seem to feel like using the symbol server for some reason.

I don't know anywhere near enough about win32 programming to know why FormatMessage might fail. It seems to be one of those functions that might do one of a bunch of different things depending on details of the arguments passed (which are 0, various flag combinations, etc). Hopefully the information above and following will be enough to tell why it's failing anyway.

Dump of automatics in current expression:

        &lpMsgBuf 0x0115e48c void * *
        lpMsgBuf 0x00000000 void *
- str 0xcccccccc <Bad Ptr> char *
            CXX0030: Error: expression cannot be evaluated

Dump of locals:

- cmdstring 0x01580f70 "D:/Developer/Scribus/fttest/dummy-program" const char *
            68 'D' const char
- path 0x00000000 <Bad Ptr> const char *
            CXX0030: Error: expression cannot be evaluated
- szConsoleSpawn 0x0115e7c4 "cmw9xcom.exe" const char *
            99 'c' const char
        hStdin 0x000017c4 void *
        hStdout 0x000017c0 void *
        hStderr 0x000017b8 void *
        hProcess 0x0115e6c0 void * *
        hideWindows false bool
- output "" std::basic_string<char,std::char_traits<char>,std::allocator<char> > &
+ [actual members] {_Bx={...} _Mysize=0 _Myres=15 } std::basic_string<char,std::char_traits<char>,std::allocator<char> >
- str 0xcccccccc <Bad Ptr> char *
            CXX0030: Error: expression cannot be evaluated
- s1 0x0158d1d8 "C:\WINDOWS\system32\cmd.exe" char *
            67 'C' char
- s2 0x0157f8b0 "D:/Developer/Scribus/fttest/dummy-program" char *
            68 'D' char
- siStartInfo {cb=68 lpReserved=0x00000000 <Bad Ptr> lpDesktop=0x00000000 <Bad Ptr> ...} _STARTUPINFOA
        cb 68 unsigned long
+ lpReserved 0x00000000 <Bad Ptr> char *
+ lpDesktop 0x00000000 <Bad Ptr> char *
+ lpTitle 0x00000000 <Bad Ptr> char *
        dwX 0 unsigned long
        dwY 0 unsigned long
        dwXSize 0 unsigned long
        dwYSize 0 unsigned long
        dwXCountChars 0 unsigned long
        dwYCountChars 0 unsigned long
        dwFillAttribute 0 unsigned long
        dwFlags 257 unsigned long
        wShowWindow 10 unsigned short
        cbReserved2 0 unsigned short
+ lpReserved2 0x00000000 <Bad Ptr> unsigned char *
        hStdInput 0x000017c4 void *
        hStdOutput 0x000017c0 void *
        hStdError 0x000017b8 void *
- piProcInfo {hProcess=0x00000000 hThread=0x00000000 dwProcessId=0 ...} _PROCESS_INFORMATION
        hProcess 0x00000000 void *
        hThread 0x00000000 void *
        dwProcessId 0 unsigned long
        dwThreadId 0 unsigned long
        i 28 int
- s3 0x0072ae30 " /c " char *
            32 ' ' char
        lpMsgBuf 0x00000000 void *


Loaded modules:

- cmdstring 0x01580f70 "D:/Developer/Scribus/fttest/dummy-program" const char *
            68 'D' const char
- path 0x00000000 <Bad Ptr> const char *
            CXX0030: Error: expression cannot be evaluated
- szConsoleSpawn 0x0115e7c4 "cmw9xcom.exe" const char *
            99 'c' const char
        hStdin 0x000017c4 void *
        hStdout 0x000017c0 void *
        hStderr 0x000017b8 void *
        hProcess 0x0115e6c0 void * *
        hideWindows false bool
- output "" std::basic_string<char,std::char_traits<char>,std::allocator<char> > &
+ [actual members] {_Bx={...} _Mysize=0 _Myres=15 } std::basic_string<char,std::char_traits<char>,std::allocator<char> >
- str 0xcccccccc <Bad Ptr> char *
            CXX0030: Error: expression cannot be evaluated
- s1 0x0158d1d8 "C:\WINDOWS\system32\cmd.exe" char *
            67 'C' char
- s2 0x0157f8b0 "D:/Developer/Scribus/fttest/dummy-program" char *
            68 'D' char
- siStartInfo {cb=68 lpReserved=0x00000000 <Bad Ptr> lpDesktop=0x00000000 <Bad Ptr> ...} _STARTUPINFOA
        cb 68 unsigned long
+ lpReserved 0x00000000 <Bad Ptr> char *
+ lpDesktop 0x00000000 <Bad Ptr> char *
+ lpTitle 0x00000000 <Bad Ptr> char *
        dwX 0 unsigned long
        dwY 0 unsigned long
        dwXSize 0 unsigned long
        dwYSize 0 unsigned long
        dwXCountChars 0 unsigned long
        dwYCountChars 0 unsigned long
        dwFillAttribute 0 unsigned long
        dwFlags 257 unsigned long
        wShowWindow 10 unsigned short
        cbReserved2 0 unsigned short
+ lpReserved2 0x00000000 <Bad Ptr> unsigned char *
        hStdInput 0x000017c4 void *
        hStdOutput 0x000017c0 void *
        hStdError 0x000017b8 void *
- piProcInfo {hProcess=0x00000000 hThread=0x00000000 dwProcessId=0 ...} _PROCESS_INFORMATION
        hProcess 0x00000000 void *
        hThread 0x00000000 void *
        dwProcessId 0 unsigned long
        dwThreadId 0 unsigned long
        i 28 int
- s3 0x0072ae30 " /c " char *
            32 ' ' char
        lpMsgBuf 0x00000000 void *
(0005257)
Craig Ringer (reporter)
2006-10-05 12:18

Sorry, correct loaded modules:

    cmake.exe D:\Developer\CMake\bin\debug\cmake.exe N/A N/A Symbols loaded. d:\Developer\CMake\Source\Debug\cmake.pdb 1 6/10/2006 12:03 AM 00400000-007C3000 [3452] cmake.exe: Native
    ntdll.dll C:\WINDOWS\system32\ntdll.dll N/A N/A Symbols loaded (source information stripped). C:\WINDOWS\symbols\dll\ntdll.pdb 2 5.1.2600.2180 (xpsp_sp2_rtm.040803-2158) 4/08/2004 3:56 PM 7C900000-7C9B0000 [3452] cmake.exe: Native
    kernel32.dll C:\WINDOWS\system32\kernel32.dll N/A N/A No symbols loaded. 3 5.1.2600.2945 (xpsp_sp2_gdr.060704-2349) 5/07/2006 6:55 PM 7C800000-7C8F4000 [3452] cmake.exe: Native
    rpcrt4.dll C:\WINDOWS\system32\rpcrt4.dll N/A N/A Symbols loaded (source information stripped). C:\WINDOWS\symbols\dll\rpcrt4.pdb 4 5.1.2600.2180 (xpsp_sp2_rtm.040803-2158) 4/08/2004 3:56 PM 77E70000-77F01000 [3452] cmake.exe: Native
    advapi32.dll C:\WINDOWS\system32\advapi32.dll N/A N/A Symbols loaded (source information stripped). C:\WINDOWS\symbols\dll\advapi32.pdb 5 5.1.2600.2180 (xpsp_sp2_rtm.040803-2158) 4/08/2004 3:56 PM 77DD0000-77E6B000 [3452] cmake.exe: Native
    msvcp80d.dll C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcp80d.dll N/A N/A No symbols loaded. 6 8.00.50727.42 23/09/2005 2:46 PM 10480000-1057C000 [3452] cmake.exe: Native
    msvcr80d.dll C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcr80d.dll N/A N/A No symbols loaded. 7 8.00.50727.42 23/09/2005 2:44 PM 10200000-10320000 [3452] cmake.exe: Native
    msvcrt.dll C:\WINDOWS\system32\msvcrt.dll N/A N/A Symbols loaded (source information stripped). C:\WINDOWS\symbols\dll\msvcrt.pdb 8 7.0.2600.2180 (xpsp_sp2_rtm.040803-2158) 4/08/2004 3:59 PM 77C10000-77C68000 [3452] cmake.exe: Native
    user32.dll C:\WINDOWS\system32\user32.dll N/A N/A No symbols loaded. 9 5.1.2600.2622 (xpsp_sp2_gdr.050301-1519) 3/03/2005 2:09 AM 77D40000-77DD0000 [3452] cmake.exe: Native
    gdi32.dll C:\WINDOWS\system32\gdi32.dll N/A N/A No symbols loaded. 10 5.1.2600.2818 (xpsp_sp2_gdr.051228-1427) 29/12/2005 10:54 AM 77F10000-77F57000 [3452] cmake.exe: Native
    imm32.dll C:\WINDOWS\system32\imm32.dll N/A N/A Symbols loaded (source information stripped). C:\WINDOWS\symbols\dll\imm32.pdb 11 5.1.2600.2180 (xpsp_sp2_rtm.040803-2158) 4/08/2004 3:56 PM 76390000-763AD000 [3452] cmake.exe: Native
    lpk.dll C:\WINDOWS\system32\lpk.dll N/A N/A Symbols loaded (source information stripped). C:\WINDOWS\symbols\dll\lpk.pdb 12 5.1.2600.2180 (xpsp_sp2_rtm.040803-2158) 4/08/2004 3:56 PM 629C0000-629C9000 [3452] cmake.exe: Native
    usp10.dll C:\WINDOWS\system32\usp10.dll N/A N/A Symbols loaded (source information stripped). C:\WINDOWS\symbols\dll\usp10.pdb 13 1.0420.2600.2180 (xpsp_sp2_rtm.040803-2158) 4/08/2004 3:56 PM 74D90000-74DFB000 [3452] cmake.exe: Native

(I'm still too used to *nix copy and paste it seems - select then paste.)
(0005258)
Craig Ringer (reporter)
2006-10-05 12:35

If I save the return value of the FormatMessage call in "DWORD ret" then insert the following code after the FormatMessage call:

  if (!ret)
  {
      // FormatMessage failed.
      DWORD failreason = GetLastError();
      std::cerr << "[CMAKE INTERNAL ERROR]\nFormatMessage failed in " << __FUNCSIG__ << " with (DWORD)" << failreason << std::endl;
      free(s2);
      free(s1);
      return FALSE;
  }

I get the following output:

[CMAKE INTERNAL ERROR]
FormatMessage failed in int __cdecl RealPopenCreateProcess(const char *,const ch
ar *,const char *,void *,void *,void *,void **,bool,class std::basic_string<char
,struct std::char_traits<char>,class std::allocator<char> > &) with (DWORD)87

A little scratch program using FormatMessage (the same invovation used in CMake, with a hard coded error value of 87) reveals that code 87 is "The parameter is incorrect".

Hope that means more to you than it does to me.
(0005259)
Brad King (manager)
2006-10-05 13:13

Wow, thanks for the detailed report. That should make remote debugging easier. I'm re-opening the bug.
(0005260)
Brad King (manager)
2006-10-05 13:43

I've modified the FormatMessage call to be more robust. Please try again.

/cvsroot/CMake/CMake/Source/cmWin32ProcessExecution.cxx,v <-- cmWin32ProcessExecution.cxx
new revision: 1.29; previous revision: 1.28

Also, if you change the test to use EXECUTE_PROCESS instead of EXEC_PROGRAM does the crash still occur?
(0005301)
Craig Ringer (reporter)
2006-10-08 01:41

That did the trick, thanks.

Output is now:

$ cmake -G "MinGW Makefiles"

$ d:\developer\cmake\bin\debug\cmake -G "MinGW Makefiles"
CreateProcessError: %1 is not a valid Win32 application.

for command: D:/Developer/Scribus/fttest/dummy-program
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Developer/Scribus/fttest


The output is a little odd ("%1 is not ...") but does the job, and more importantly doesn't crash.
(0005302)
Craig Ringer (reporter)
2006-10-08 01:47

Using EXECUTE_PROCESS(COMMAND "\path\to\dummy-command") fails silently. I'm pretty sure that's what'd be expected, and there's certainly no crash either before or after your patch.

Thanks.
(0005314)
Brad King (manager)
2006-10-09 20:02

Okay, I'm now closing this bug. Thanks for the detailed feedback.

 Issue History
Date Modified Username Field Change


Copyright © 2000 - 2018 MantisBT Team