[evolution-patches] gpg --verify patch



Checking some of Ettore's signatures today, I noticed that the validity
description was sometimes getting truncated.

Turned out to be a simple logic bug...

pseudo code:

while (!gpg->complete && !gpg->exited) {
	read_from_gpg();
}

the problem was that gpg would exit before we'd gotten to read all the
data from the pipes, so we'd exit the loop prematurely.

While I fixed that, I also removed some previous debug printf's I had
added. Also simplified the process to check if we had flushed the
diagnostics stream by just using a bit field (had 18 to spare) rather
than checking of the GByteArray ended with a '\0'

Jeff

-- 
Jeffrey Stedfast
Evolution Hacker - Ximian, Inc.
fejj ximian com  - www.ximian.com
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/camel/ChangeLog,v
retrieving revision 1.1794
diff -u -r1.1794 ChangeLog
--- ChangeLog	10 Apr 2003 17:13:13 -0000	1.1794
+++ ChangeLog	15 Apr 2003 20:28:22 -0000
@@ -1,3 +1,19 @@
+2003-04-15  Jeffrey Stedfast  <fejj ximian com>
+
+	* camel-gpg-context.c (gpg_verify): The gpg child process exiting
+	does not necessarily mean that we've ready everything that we can
+	from its pipes, so don't use gpg_ctx_op_exited() as a loop-exit
+	condition. If for some reason the gpg child process does exit (due
+	to an error), gpg_ctx_op_step() will eventually fail (as soon as
+	it has finished reading any data in the pipes) and cause the loop
+	to be terminated anyway. This fixes truncation of the gpg --verify
+	stderr output that Evolution displays as the "validity report"
+	(for lack of a better description).
+	(gpg_ctx_op_step): Removed some debugging printf's
+	(gpg_ctx_get_diagnostics): Use a bitfield to decide if we've
+	already flushed the diagnostics stream, much simpler (plus we have
+	plenty of bits to spare so might as well use them).
+
 2003-04-10  Jeffrey Stedfast  <fejj ximian com>
 
 	* providers/smtp/camel-smtp-transport.c: Turn off debugging if
Index: camel-gpg-context.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-gpg-context.c,v
retrieving revision 1.32
diff -u -r1.32 camel-gpg-context.c
--- camel-gpg-context.c	9 Apr 2003 23:21:15 -0000	1.32
+++ camel-gpg-context.c	15 Apr 2003 20:28:22 -0000
@@ -282,7 +282,9 @@
 	unsigned int validsig:1;
 	unsigned int trust:3;
 	
-	unsigned int padding:18;
+	unsigned int diagflushed:1;
+	
+	unsigned int padding:17;
 };
 
 static struct _GpgCtx *
@@ -334,6 +336,7 @@
 	
 	stream = camel_stream_mem_new ();
 	gpg->diagbuf = CAMEL_STREAM_MEM (stream)->buffer;
+	gpg->diagflushed = FALSE;
 	
 	if ((charset = e_iconv_locale_charset ()) && !strcasecmp (charset, "UTF-8")) {
 		CamelMimeFilterCharset *filter;
@@ -426,7 +429,8 @@
 static const char *
 gpg_ctx_get_diagnostics (struct _GpgCtx *gpg)
 {
-	if (!gpg->diagbuf->len || gpg->diagbuf->data[gpg->diagbuf->len - 1] != '\0') {
+	if (!gpg->diagflushed) {
+		gpg->diagflushed = TRUE;
 		camel_stream_flush (gpg->diagnostics);
 		if (gpg->diagbuf->len == 0)
 			return NULL;
@@ -1063,9 +1067,7 @@
 			goto exception;
 		
 		if (nread > 0) {
-			printf ("pre-diag: %.*s\n", nread, buffer);
 			camel_stream_write (gpg->diagnostics, buffer, nread);
-			printf ("post-diag: %.*s\n", gpg->diagbuf->len, gpg->diagbuf->data);
 		} else {
 			gpg->seen_eof2 = TRUE;
 		}
@@ -1390,7 +1392,7 @@
 		goto exception;
 	}
 	
-	while (!gpg_ctx_op_complete (gpg) && !gpg_ctx_op_exited (gpg)) {
+	while (!gpg_ctx_op_complete (gpg)) {
 		if (camel_operation_cancel_check (NULL)) {
 			camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
 					     _("Cancelled."));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]