[gmime/gmime-2-2] Backported some important fixes



commit 72e2dcf2220bd9dd3f764c30d484d21c036aaad9
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Mon Mar 7 13:07:23 2011 -0500

    Backported some important fixes
    
    2011-03-07  Jeffrey Stedfast  <fejj novell com>
    
    	* gmime/gmime-gpg-context.c (gpg_ctx_parse_status): Treat EXPSIG,
    	EXPKEYSIG, and REVKEYSIG the same as GOODSIG/BADSIG status
    	messages in that all of them denote a new signer info.
    
    	* gmime/gmime-stream-mem.c (stream_write): Correctly calculate the
    	end boundary of the stream when bound_end is -1.
    
    	* gmime/gmime-utils.h (GMIME_QP_ENCODE_LEN): Fixed to take into
    	acount the possibility of having to force-wrap lines at 72+
    	characters.
    	(GMIME_UUENCODE_LEN): Fixed to prevent possible buffer overflows.

 ChangeLog                 |   14 +++++++++
 gmime/gmime-gpg-context.c |   70 +++++++++++++++++++++++++--------------------
 gmime/gmime-stream-mem.c  |    9 ++++--
 gmime/gmime-utils.h       |    4 +-
 4 files changed, 61 insertions(+), 36 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6778a7a..ebbf104 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-03-07  Jeffrey Stedfast  <fejj novell com>
+
+	* gmime/gmime-gpg-context.c (gpg_ctx_parse_status): Treat EXPSIG,
+	EXPKEYSIG, and REVKEYSIG the same as GOODSIG/BADSIG status
+	messages in that all of them denote a new signer info.
+
+	* gmime/gmime-stream-mem.c (stream_write): Correctly calculate the
+	end boundary of the stream when bound_end is -1.
+
+	* gmime/gmime-utils.h (GMIME_QP_ENCODE_LEN): Fixed to take into
+	acount the possibility of having to force-wrap lines at 72+
+	characters.
+	(GMIME_UUENCODE_LEN): Fixed to prevent possible buffer overflows.
+
 2010-03-26  Jeffrey Stedfast  <fejj novell com>
 
 	* README: Bumped version
diff --git a/gmime/gmime-gpg-context.c b/gmime/gmime-gpg-context.c
index edd38b1..68169a0 100644
--- a/gmime/gmime-gpg-context.c
+++ b/gmime/gmime-gpg-context.c
@@ -768,6 +768,34 @@ next_token (char *in, char **token)
 	return inptr;
 }
 
+/**
+ * gpg_ctx_add_signer:
+ * @gpg: GnuPG context
+ * @info: a string with the signer's info
+ *
+ * Parses GOODSIG, BADSIG, EXPSIG, EXPKEYSIG, and REVKEYSIG status messages
+ * into a newly allocated #GMimeSigner, adding it to @gpg's signer list.
+ *
+ * Returns: the newly added signer for the caller to add more info to.
+ **/
+static GMimeSigner *
+gpg_ctx_add_signer (struct _GpgCtx *gpg, char *info)
+{
+	GMimeSigner *signer;
+	
+	signer = g_mime_signer_new ();
+	gpg->signer->next = signer;
+	gpg->signer = signer;
+	
+	/* get the key id of the signer */
+	info = next_token (info, &signer->keyid);
+	
+	/* the rest of the string is the signer's name */
+	signer->name = g_strdup (info);
+	
+	return signer;
+}
+
 static int
 gpg_ctx_parse_status (struct _GpgCtx *gpg, GError **err)
 {
@@ -969,33 +997,20 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, GError **err)
 			if (!strncmp (status, "SIG_ID ", 7)) {
 				/* not sure if this contains anything we care about... */
 			} else if (!strncmp (status, "GOODSIG ", 8)) {
+				signer = gpg_ctx_add_signer (gpg, status + 8);
 				gpg->goodsig = TRUE;
-				status += 8;
-				
-				signer = g_mime_signer_new ();
-				signer->status = GMIME_SIGNER_STATUS_GOOD;
-				gpg->signer->next = signer;
-				gpg->signer = signer;
-				
-				/* get the key id of the signer */
-				status = next_token (status, &signer->keyid);
-				
-				/* the rest of the string is the signer's name */
-				signer->name = g_strdup (status);
 			} else if (!strncmp (status, "BADSIG ", 7)) {
+				signer = gpg_ctx_add_signer (gpg, status + 7);
 				gpg->badsig = TRUE;
-				status += 7;
-				
-				signer = g_mime_signer_new ();
-				signer->status = GMIME_SIGNER_STATUS_BAD;
-				gpg->signer->next = signer;
-				gpg->signer = signer;
-				
-				/* get the key id of the signer */
-				status = next_token (status, &signer->keyid);
-				
-				/* the rest of the string is the signer's name */
-				signer->name = g_strdup (status);
+			} else if (!strncmp (status, "EXPSIG ", 7)) {
+				signer = gpg_ctx_add_signer (gpg, status + 7);
+				signer->errors |= GMIME_SIGNER_ERROR_EXPSIG;
+			} else if (!strncmp (status, "EXPKEYSIG ", 10)) {
+				signer = gpg_ctx_add_signer (gpg, status + 10);
+				signer->errors |= GMIME_SIGNER_ERROR_EXPKEYSIG;
+			} else if (!strncmp (status, "REVKEYSIG ", 10)) {
+				signer = gpg_ctx_add_signer (gpg, status + 10);
+				signer->errors |= GMIME_SIGNER_ERROR_REVKEYSIG;
 			} else if (!strncmp (status, "ERRSIG ", 7)) {
 				/* Note: NO_PUBKEY often comes after an ERRSIG */
 				gpg->errsig = TRUE;
@@ -1027,13 +1042,6 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, GError **err)
 				/* the only token is the keyid, but we've already got it */
 				gpg->signer->errors |= GMIME_SIGNER_ERROR_NO_PUBKEY;
 				gpg->nopubkey = TRUE;
-			} else if (!strncmp (status, "EXPSIG", 6)) {
-				/* FIXME: see what else we can glean from this... */
-				gpg->signer->errors |= GMIME_SIGNER_ERROR_EXPSIG;
-			} else if (!strncmp (status, "EXPKEYSIG", 9)) {
-				gpg->signer->errors |= GMIME_SIGNER_ERROR_EXPKEYSIG;
-			} else if (!strncmp (status, "REVKEYSIG", 9)) {
-				gpg->signer->errors |= GMIME_SIGNER_ERROR_REVKEYSIG;
 			} else if (!strncmp (status, "VALIDSIG ", 9)) {
 				char *inend;
 				
diff --git a/gmime/gmime-stream-mem.c b/gmime/gmime-stream-mem.c
index a67d9e8..938b606 100644
--- a/gmime/gmime-stream-mem.c
+++ b/gmime/gmime-stream-mem.c
@@ -24,6 +24,7 @@
 #endif
 
 #include <string.h>
+#include <errno.h>
 
 #include "gmime-stream-mem.h"
 
@@ -156,8 +157,10 @@ stream_write (GMimeStream *stream, const char *buf, size_t len)
 	
 	g_return_val_if_fail (mem->buffer != NULL, -1);
 	
-	if (stream->bound_end == -1 && stream->position + len > mem->buffer->len) {
-		g_byte_array_set_size (mem->buffer, stream->position + len);
+	if (stream->bound_end == -1) {
+		if (stream->position + len > mem->buffer->len)
+			g_byte_array_set_size (mem->buffer, stream->position + len);
+		
 		bound_end = mem->buffer->len;
 	} else
 		bound_end = stream->bound_end;
@@ -167,7 +170,7 @@ stream_write (GMimeStream *stream, const char *buf, size_t len)
 		memcpy (mem->buffer->data + stream->position, buf, n);
 		stream->position += n;
 	} else if (n < 0) {
-		/* FIXME: set errno?? */
+		errno = EINVAL;
 		n = -1;
 	}
 	
diff --git a/gmime/gmime-utils.h b/gmime/gmime-utils.h
index 50355f8..3b76408 100644
--- a/gmime/gmime-utils.h
+++ b/gmime/gmime-utils.h
@@ -93,7 +93,7 @@ struct _GMimeReferences {
  * Returns the number of output bytes needed to encode an input buffer
  * of size @x using the quoted-printable encoding.
  **/
-#define GMIME_QP_ENCODE_LEN(x)     ((size_t) ((((x) + 1) * 3) + 1))
+#define GMIME_QP_ENCODE_LEN(x)     ((size_t) ((((x) / 24) * 74) + 74))
 
 
 /**
@@ -106,7 +106,7 @@ struct _GMimeReferences {
  * Returns the number of output bytes needed to uuencode an input
  * buffer of size @x.
  **/
-#define GMIME_UUENCODE_LEN(x)      ((size_t) (((((x) + 2) / 45) * 62) + 62))
+#define GMIME_UUENCODE_LEN(x)      ((size_t) (((((x) + 2) / 45) * 62) + 64))
 
 
 /**



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