Update of /cvsroot/mahogany/M/src/modules/crypt
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16966/src/modules/crypt
Modified Files:
PGPEngine.cpp
Log Message:
fixed handling of big PGP-signed messages (we would dead lock trying to write to a
pipe while gpg was trying to write to it from other end before)
Index: PGPEngine.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/modules/crypt/PGPEngine.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -b -u -2 -r1.32 -r1.33
--- PGPEngine.cpp 16 Mar 2004 00:01:00 -0000 1.32
+++ PGPEngine.cpp 9 Jul 2004 19:04:41 -0000 1.33
@@ -472,8 +472,10 @@
options.c_str()
);
-#if !defined(NDEBUG)
- if (log)
+
+#ifdef DEBUG
+ if ( log )
log->AddMessage(command);
#endif
+
long pid = wxExecute
(command,
@@ -487,17 +489,11 @@
}
- // if we have data to write to PGP stdin, do it
wxOutputStream *in = process.GetOutputStream();
- CHECK( in, CANNOT_EXEC_PROGRAM, _T("where is PGP subprocess stdin?") );
-
- if ( !messageIn.empty() )
- {
- in->Write(messageIn.c_str(), messageIn.length());
- process.CloseOutput();
- }
-
wxInputStream *out = process.GetInputStream(),
*err = process.GetErrorStream();
+ CHECK( in && out && err, CANNOT_EXEC_PROGRAM,
+ _T("where is PGP subprocess stdin/out/err?") );
+
wxTextInputStream errText(*err);
@@ -512,4 +508,7 @@
wxChar buf[4096];
+ size_t lenIn = messageIn.length();
+ const wxChar *ptrIn = messageIn.c_str();
+
bool outEof = false,
errEof = false;
@@ -518,9 +517,13 @@
wxYield();
+ // the order is important here, lest we deadlock: first get everything
+ // gpg has for us and only then try to feed it more data
if ( out->GetLastError() == wxSTREAM_EOF )
{
outEof = true;
}
- else if ( out->CanRead() )
+ else
+ {
+ while ( out->CanRead() )
{
// leave space for terminating NUL
@@ -529,4 +532,18 @@
messageOut += buf;
}
+ }
+
+ if ( lenIn )
+ {
+ const size_t CHUNK_SIZE = 4096;
+ size_t lenChunk = lenIn > CHUNK_SIZE ? CHUNK_SIZE : lenIn;
+ in->Write(ptrIn, lenChunk);
+
+ lenIn -= lenChunk;
+ ptrIn += lenChunk;
+
+ if ( !lenIn )
+ process.CloseOutput();
+ }
if ( err->GetLastError() == wxSTREAM_EOF )
@@ -537,9 +554,11 @@
{
String line = errText.ReadLine();
-#if !defined(NDEBUG)
+
+#ifdef DEBUG
// In debug mode, log everything
if (log)
log->AddMessage(line);
-#endif
+#endif // DEBUG
+
if ( line.StartsWith(_T("[GNUPG:] "), &line) )
{
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates