Discussion:
QCA unhandled exception at termination in windows
Acenes
2008-03-03 08:08:28 UTC
Permalink
Hi,



I have successfully installed qca-2.2.0 exactly after the INSTALL
instructions in this environment:



MS Windows XP home SP2

Visual Studio 2005 SP1

Qt 4.3.4 Commercial

Qt Visual Studio Integration 1.3.3



Installation/compiling the libs went smooth without any hickups.



Compiling and testing the example md5crypt, everything works perfectly up to
the point where where the program terminates, e.g. destroys the stack
allocated objects.



I get this message:



Unhandled exception at 0x1002d94d(qcad2.dll) in QCATest.exe:

0xC0000005: Access violation reading location 0xfeeefef2



Here is the call stack:



qcad2.dll!QCA::Botan::MemoryRegion<unsigned char>::deallocate(unsigned char
* p=0x009700e8, unsigned int n=7) Line 114 + 0x1d bytes C++

qcad2.dll!QCA::Botan::MemoryRegion<unsigned char>::~MemoryRegion<unsigned
char>() Line 98 + 0x1c bytes C++

qcad2.dll!QCA::Botan::SecureVector<unsigned char>::~SecureVector<unsigned
char>() + 0xf bytes C++

qcad2.dll!QCA::Botan::SecureVector<unsigned char>::`scalar deleting
destructor'() + 0xf bytes C++

qcad2.dll!QCA::ai_delete(QCA::alloc_info * ai=0x003de9f4) Line 377 + 0x1f
bytes C++

qcad2.dll!QCA::MemoryRegion::Private::~Private() Line 411 + 0xc bytes
C++

qcad2.dll!QCA::MemoryRegion::Private::`scalar deleting destructor'() + 0xf
bytes C++

qcad2.dll!QSharedDataPointer<QCA::MemoryRegion::Private>::~QSharedDataPointe
r<QCA::MemoryRegion::Private>() Line 65 + 0x40 bytes C++

qcad2.dll!QCA::MemoryRegion::~MemoryRegion() Line 455 + 0xb bytes
C++

qcad2.dll!QCA::SecureArray::~SecureArray() Line 636 + 0x8 bytes C++

QCATest.exe!main(int argc=3, char * * argv=0x003d3c10) Line 216 + 0x21
bytes C++

QCATest.exe!__tmainCRTStartup() Line 597 + 0x19 bytes C

QCATest.exe!mainCRTStartup() Line 414 C

kernel32.dll!7c816fd7()

[Frames below may be incorrect and/or missing, no symbols loaded for
kernel32.dll]



Is this a known issue?



Cheers, Acenes
Justin Karneges
2008-03-03 17:12:08 UTC
Permalink
Post by Acenes
qcad2.dll!QCA::Botan::MemoryRegion<unsigned char>::deallocate(unsigned char
* p=0x009700e8, unsigned int n=7) Line 114 + 0x1d bytes C++
qcad2.dll!QCA::Botan::MemoryRegion<unsigned char>::~MemoryRegion<unsigned
char>() Line 98 + 0x1c bytes C++
qcad2.dll!QCA::Botan::SecureVector<unsigned char>::~SecureVector<unsigned
char>() + 0xf bytes C++
qcad2.dll!QCA::Botan::SecureVector<unsigned char>::`scalar deleting
destructor'() + 0xf bytes C++
qcad2.dll!QCA::ai_delete(QCA::alloc_info * ai=0x003de9f4) Line 377 + 0x1f
bytes C++
qcad2.dll!QCA::MemoryRegion::Private::~Private() Line 411 + 0xc bytes
C++
qcad2.dll!QCA::MemoryRegion::Private::`scalar deleting destructor'() + 0xf
bytes C++
qcad2.dll!QSharedDataPointer<QCA::MemoryRegion::Private>::~QSharedDataPoint
e r<QCA::MemoryRegion::Private>() Line 65 + 0x40 bytes C++
qcad2.dll!QCA::MemoryRegion::~MemoryRegion() Line 455 + 0xb bytes
C++
qcad2.dll!QCA::SecureArray::~SecureArray() Line 636 + 0x8 bytes
C++
QCATest.exe!main(int argc=3, char * * argv=0x003d3c10) Line 216 + 0x21
bytes C++
QCATest.exe!__tmainCRTStartup() Line 597 + 0x19 bytes C
QCATest.exe!mainCRTStartup() Line 414 C
kernel32.dll!7c816fd7()
[Frames below may be incorrect and/or missing, no symbols loaded for
kernel32.dll]
Is this a known issue?
Hi,

This should not happen.

Can you share the source code to QCATest.exe ?

-Justin
Acenes
2008-03-04 05:38:49 UTC
Permalink
Post by Justin Karneges
This should not happen.
Can you share the source code to QCATest.exe ?
-Justin
The source code is completely in the tar archive of qca-2.0.0:

examples/md5crypt/md5crypt.cpp

What I did exactly was:

- Create a new "Qt Console Application" project named QCATest with the Qt
Visual Studio Integration.
- Copy/paste of the sample source code from md5crypt.cpp into main.cpp of my
new project.
- Add the qca include path and the library name (debug version: qcad2.lib)
to the project settings.
- Build the exe with otherwise default compiler and linker settings.

Do you think the problem might be from some special compile or link switches
that are required by qca?
Below is the build log where you can see what settings exactly were used for
compiling and linking.

Acenes



BUILDLOG:

Creating temporary file "c:\Visual Studio
2005\Projects\QCATest\QCATest\Debug\RSP00000518682436.rsp" with contents
[
/Od /I ".\GeneratedFiles\Debug" /I "C:\Qt\qca-2.0.0\include" /I
"C:\Qt\qca-2.0.0\include\QtCrypto" /I "C:\Qt\4.3.4\include" /I
"C:\Qt\4.3.4\include\QtCore" /D "UNICODE" /D "WIN32" /D "QT_THREAD_SUPPORT"
/D "QT_CORE_LIB" /FD /EHsc /MDd /Zc:wchar_t- /Fo"Debug\\"
/Fd"Debug\vc80.pdb" /c /Zi /TP ".\main.cpp"
]
Creating command line "cl.exe @"c:\Visual Studio
2005\Projects\QCATest\QCATest\Debug\RSP00000518682436.rsp" /nologo
/errorReport:prompt"
Creating temporary file "c:\Visual Studio
2005\Projects\QCATest\QCATest\Debug\RSP00000618682436.rsp" with contents
[
/OUT:"C:\Visual Studio 2005\Projects\QCATest\Debug\QCATest.exe"
/LIBPATH:"C:\Qt\4.3.4\lib" /MANIFEST
/MANIFESTFILE:"Debug\QCATest.exe.intermediate.manifest" /DEBUG
/PDB:"c:\Visual Studio 2005\Projects\QCATest\debug\QCATest.pdb"
/SUBSYSTEM:CONSOLE qcad2.lib qtmaind.lib QtCored4.lib kernel32.lib
user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib
ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

".\Debug\main.obj"
]
Creating command line "link.exe @"c:\Visual Studio
2005\Projects\QCATest\QCATest\Debug\RSP00000618682436.rsp" /NOLOGO
/ERRORREPORT:PROMPT"
Creating temporary file "c:\Visual Studio
2005\Projects\QCATest\QCATest\Debug\RSP00000718682436.rsp" with contents
[
/outputresource:"..\debug\QCATest.exe;#1" /manifest

".\Debug\QCATest.exe.intermediate.manifest"
]
Creating command line "mt.exe @"c:\Visual Studio
2005\Projects\QCATest\QCATest\Debug\RSP00000718682436.rsp" /nologo"
Creating temporary file "c:\Visual Studio
2005\Projects\QCATest\QCATest\Debug\BAT00000818682436.bat" with contents
[
@echo Manifest resource last updated at %TIME% on %DATE% > ".\Debug\mt.dep"
]
Creating command line """c:\Visual Studio
2005\Projects\QCATest\QCATest\Debug\BAT00000818682436.bat"""
Justin Karneges
2008-03-04 06:47:06 UTC
Permalink
Post by Acenes
Post by Justin Karneges
This should not happen.
Can you share the source code to QCATest.exe ?
-Justin
examples/md5crypt/md5crypt.cpp
Okay, I've figured it out. md5crypt.cpp is wrong. So much for setting a good
example to follow. :)

Actually, this is a really obscure aspect of QCA to know about. This code:

QCA::Initializer init;
QCA::SecureArray password, salt;
QCoreApplication app ( argc, argv );

should be written like this instead:

QCA::Initializer init;
QCoreApplication app ( argc, argv );
QCA::SecureArray password, salt;

QCA uses qAddPostRoutine() to deinitialize QCA. This means that when
QCoreApplication destructs, QCA is deinitialized (QCA::Initializer object
destruction then becomes a no-op). As you can see, the way md5crypt.cpp is
written, those SecureArray will be deleted *after* QCA deinitializes. Best
fix is to do nothing between Initializer and QCoreApplication construction.

Sorry about that!

-Justin
Acenes
2008-03-04 09:08:01 UTC
Permalink
Post by Justin Karneges
Okay, I've figured it out. md5crypt.cpp is wrong. So much for setting a good
example to follow. :)
Ahh, and lucky me hit exactly that one.
A quick look through the other examples shows that most time QCA:Initializer
is called before QCoreApplication, but some examples also have
QCoreApplication before QCA::Initializer which seems also to work and looks
more familiar to me.

Now I'm looking forward to digg deeper into qca. Thank you for your help!

Acenes
Justin Karneges
2008-03-04 17:39:14 UTC
Permalink
some examples also have QCoreApplication before QCA::Initializer which
seems also to work and looks more familiar to me.
Yes, this will also work. However, it is generally recommended that
QCA::Initializer be the first thing you do in main(), for high security on
unix. On Windows, I don't think the ordering matters (yet?), but it is good
to be portable. :)

-Justin

Loading...