You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Milan Tomic <mi...@setcce.org> on 2004/03/10 13:46:53 UTC

Janitor

    I had this code:

try {
  //more code here...	
  XercesDOMParser * parser = new XercesDOMParser;
  Janitor<XercesDOMParser> j_parser(parser);
  //more code here...
  //my app crashes here
} catch (...) {
  //never come here
}
//never come here

    My app crashes (not allways) before catch block. Am I using Janitor
in a wrong way? Is there some known bug/issue with Janitor? I'm using
Xerces 2.4/VC++6/WinXP.

Best regards,
Milan

Re: Janitor

Posted by Berin Lautenbach <be...@wingsofhermes.org>.
Most strange.  I've never seen anything like this.

If you can send me an XML document that triggers the problem with the 
changes you mention to checksig, I'll have a look-see.

Cheers,
	Berin


Milan Tomic wrote:

> Berin,
> 
> 	I'm using Xerces 2.3, Xalan 1.6 and XSec 1.0. This is error
> message:
> 
> ---------------------------
> Microsoft Visual C++
> ---------------------------
> Unhandled exception in checksig.exe (KERNEL32.DLL): 0xE06D7363:
> Microsoft C++ Exception.
> ---------------------------
> OK   
> ---------------------------
> 
> Best regards,
> Milan
> 
> 
> 
>>-----Original Message-----
>>From: Berin Lautenbach [mailto:berin@wingsofhermes.org] 
>>Sent: Monday, March 15, 2004 11:30 AM
>>To: security-dev@xml.apache.org
>>Subject: Re: Janitor
>>
>>
>>Milan,
>>
>>THey should not be throwing an exception - that's really basic stuff!
>>
>>What version of Xerces are you using?  I know there were some 
>>problems 
>>with 2.4?
>>
>>Cheers,
>>	Berin
> 
> 
> 
> 
> 

RE: Janitor

Posted by Milan Tomic <mi...@setcce.org>.
Berin,

	I'm using Xerces 2.3, Xalan 1.6 and XSec 1.0. This is error
message:

---------------------------
Microsoft Visual C++
---------------------------
Unhandled exception in checksig.exe (KERNEL32.DLL): 0xE06D7363:
Microsoft C++ Exception.
---------------------------
OK   
---------------------------

Best regards,
Milan


> -----Original Message-----
> From: Berin Lautenbach [mailto:berin@wingsofhermes.org] 
> Sent: Monday, March 15, 2004 11:30 AM
> To: security-dev@xml.apache.org
> Subject: Re: Janitor
> 
> 
> Milan,
> 
> THey should not be throwing an exception - that's really basic stuff!
> 
> What version of Xerces are you using?  I know there were some 
> problems 
> with 2.4?
> 
> Cheers,
> 	Berin



Re: Janitor

Posted by Berin Lautenbach <be...@wingsofhermes.org>.
Milan,

THey should not be throwing an exception - that's really basic stuff!

What version of Xerces are you using?  I know there were some problems 
with 2.4?

Cheers,
	Berin


Milan Tomic wrote:

> Berin,
> 
> 	I belive I've found it. :-)
> 
> 	I've copied those three lines of code:
> 
> DOMNode *x509Node = findDSIGNode(doc, "X509Certificate");
> XMLString::transcode(x509Node->getTextContent());
> XMLString::transcode(x509Node->getTextContent());//exception
> 
> 	After this line:
> 
> sig->load();
> 
> 	In checksig.cpp file and VC++ 6 debugger reports unhandled
> exception on third line. This happens only on few XML documents. I'll
> send you one later on private mail.
> 
> Best regards,
> Milan
> 
> 
> 
> 

RE: Janitor

Posted by Milan Tomic <mi...@setcce.org>.
Berin,

	I belive I've found it. :-)

	I've copied those three lines of code:

DOMNode *x509Node = findDSIGNode(doc, "X509Certificate");
XMLString::transcode(x509Node->getTextContent());
XMLString::transcode(x509Node->getTextContent());//exception

	After this line:

sig->load();

	In checksig.cpp file and VC++ 6 debugger reports unhandled
exception on third line. This happens only on few XML documents. I'll
send you one later on private mail.

Best regards,
Milan



RE: Janitor

Posted by Milan Tomic <mi...@setcce.org>.
Berin,

> Are you able to provide a small piece of code that reproduces the 
> problem?  Happy to have a look-see!
Thank you, I'll try to make small example and to send it to you.

I've done some debugging and found out that under Debug mode it fails to
allocate memory. This is one example (DOMDocumentImpl.cpp):

void* newBlock = 0;
try {
  newBlock = fMemoryManager->allocate(kHeapAllocSize * sizeof(char));
//new char[kHeapAllocSize];
} catch (...) {
  ThrowXML(RuntimeException, XMLExcepts::Out_Of_Memory);
}
if (!newBlock)
  ThrowXML(RuntimeException, XMLExcepts::Out_Of_Memory);

As newBlock is 0 an exception will raise ( ThrowXML() ) on the last line
of code.

Do you have any ideas why malloc() fails? I have more than enough
memory. I've noticed that even "new" fails in CString::GetBuffer()
function (MFC\SRC\strcore.cpp).

Best regards,
Milan



Re: Janitor

Posted by Berin Lautenbach <be...@wingsofhermes.org>.
Milan,

Are you able to provide a small piece of code that reproduces the 
problem?  Happy to have a look-see!

Cheers,
	Berin


Milan Tomic wrote:

> Berin,
> 
> 
>>Seen that one too :>.
>>
>> From memory it's something to do with MFC - if you define 
>>something as 
>>being MFC (and it creates stdafx.??) but you don't link in the MFC 
>>libraries, or you don't join in MFC using the shared 
>>libraries (been a 
>>while, so apologies if that sounded confused)
> 
> Yes, you're right. MFC *have to* be linked as shared library if
> "Multithreaded DLL" option selected. I prefer static MFC link, because
> of smaller deployment binaries size.
> 
> However, I've built my app with "Multithreaded DLL" option and still
> same errors persists. My app crashes (exe diseapear from the screen,
> try/catch block doesn't help) on this line:
> 
> delete parser; //delete Xerces
> 
> The same thing is when I use Janitor to delete Xerces. I've found only
> few XML documents that "causes" this behavior, and they does not contain
> anything special (no special characters, size only 10K...). I don't have
> any problems with most of other XML documents.
> 
> I've found very interesting that since I switced to "Multithreaded DLL"
> (/MD) compiler option (from "Multithreaded" - /MT), even signing of some
> files (that worked fine before) does not work now. Before, only
> verification failed.
> 
> I have never belived that one could have such problems. I'm loosing
> faith that I'll find solution (what crashes my app?).
> 
> 
>>1.  I had had forgotten about the Janitor and deleted the parser 
>>instance previously in the code.
>>
>>2.  When I had deleted something the parser owned, and thus when the 
>>parser was deleted it tried to re-delete whatever I had already done.
> 
> I've checked and I'm not doing anything of these.
> 
> Best regards,
> Milan
> 
> 
> 
> 

RE: Janitor

Posted by Milan Tomic <mi...@setcce.org>.
Berin,

> Seen that one too :>.
> 
>  From memory it's something to do with MFC - if you define 
> something as 
> being MFC (and it creates stdafx.??) but you don't link in the MFC 
> libraries, or you don't join in MFC using the shared 
> libraries (been a 
> while, so apologies if that sounded confused)
Yes, you're right. MFC *have to* be linked as shared library if
"Multithreaded DLL" option selected. I prefer static MFC link, because
of smaller deployment binaries size.

However, I've built my app with "Multithreaded DLL" option and still
same errors persists. My app crashes (exe diseapear from the screen,
try/catch block doesn't help) on this line:

delete parser; //delete Xerces

The same thing is when I use Janitor to delete Xerces. I've found only
few XML documents that "causes" this behavior, and they does not contain
anything special (no special characters, size only 10K...). I don't have
any problems with most of other XML documents.

I've found very interesting that since I switced to "Multithreaded DLL"
(/MD) compiler option (from "Multithreaded" - /MT), even signing of some
files (that worked fine before) does not work now. Before, only
verification failed.

I have never belived that one could have such problems. I'm loosing
faith that I'll find solution (what crashes my app?).

> 1.  I had had forgotten about the Janitor and deleted the parser 
> instance previously in the code.
> 
> 2.  When I had deleted something the parser owned, and thus when the 
> parser was deleted it tried to re-delete whatever I had already done.
I've checked and I'm not doing anything of these.

Best regards,
Milan



Re: Janitor

Posted by Berin Lautenbach <be...@wingsofhermes.org>.
Milan,

Seen that one too :>.

 From memory it's something to do with MFC - if you define something as 
being MFC (and it creates stdafx.??) but you don't link in the MFC 
libraries, or you don't join in MFC using the shared libraries (been a 
while, so apologies if that sounded confused)

Cheers,
	Berin


Milan Tomic wrote:

> Berin,
> 
>     Thank you very much for your help.
> 
> 
>>3.  I am used a different memory model in my app from Xerces 
>>(Runtime in 
>>a DLL) as the Janitor then uses it's runtime library to 
>>delete an object 
>>created by a different runtime library.
> 
> I belive this is a problem. I had /MT compiler option and Xerces/Xsec
> uses /MD. I've tried to change it from /MT to /MD, but got strange
> linker errors:
> 
> nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol
> ___argv
> nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol
> ___argc
> nafxcw.lib(apphelp.obj) : error LNK2001: unresolved external symbol
> __mbctype
> nafxcw.lib(filelist.obj) : error LNK2001: unresolved external symbol
> __mbctype
> nafxcw.lib(timecore.obj) : error LNK2001: unresolved external symbol
> __mbctype
> 
> At present I'm trying to fix it.
> 
> Best regards,
> Milan
> 
> 
> 
> 

RE: Janitor

Posted by Milan Tomic <mi...@setcce.org>.
Berin,

    Thank you very much for your help.

> 3.  I am used a different memory model in my app from Xerces 
> (Runtime in 
> a DLL) as the Janitor then uses it's runtime library to 
> delete an object 
> created by a different runtime library.
I belive this is a problem. I had /MT compiler option and Xerces/Xsec
uses /MD. I've tried to change it from /MT to /MD, but got strange
linker errors:

nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol
___argv
nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol
___argc
nafxcw.lib(apphelp.obj) : error LNK2001: unresolved external symbol
__mbctype
nafxcw.lib(filelist.obj) : error LNK2001: unresolved external symbol
__mbctype
nafxcw.lib(timecore.obj) : error LNK2001: unresolved external symbol
__mbctype

At present I'm trying to fix it.

Best regards,
Milan



Re: Janitor

Posted by Berin Lautenbach <be...@wingsofhermes.org>.
Milan,

I've seen crashes like this when :

1.  I had had forgotten about the Janitor and deleted the parser 
instance previously in the code.

2.  When I had deleted something the parser owned, and thus when the 
parser was deleted it tried to re-delete whatever I had already done.

3.  I am used a different memory model in my app from Xerces (Runtime in 
a DLL) as the Janitor then uses it's runtime library to delete an object 
created by a different runtime library.

Cheers,
	Berin

Milan Tomic wrote:

> 
>     I had this code:
> 
> try {
>   //more code here...  
>   XercesDOMParser * parser = new XercesDOMParser;
>   Janitor<XercesDOMParser> j_parser(parser);
>   //more code here...
>   //my app crashes here
> } catch (...) {
>   //never come here
> }
> //never come here
> 
>     My app crashes (not allways) before catch block. Am I using Janitor 
> in a wrong way? Is there some known bug/issue with Janitor? I'm using 
> Xerces 2.4/VC++6/WinXP.
> 
> Best regards,
> Milan
>