Re: [gmime-devel] [Patch] multipart insert fix in current git master branch
- From: Jeffrey Stedfast <fejj novell com>
- To: harven <harven gingers rulez pl>
- Cc: gmime-devel-list gnome org
- Subject: Re: [gmime-devel] [Patch] multipart insert fix in current git master branch
- Date: Thu, 05 Nov 2009 11:16:24 -0500
harven wrote:
> Hello,
> When you insert new mime part to GMimeMultipart mime part at some existing
> index, the mime part at that index gets overwritten and later some strange
> things may happen (because multipart->children array is resized and nothing
> is placed at the new location). Here is the patch:
>
> [snip]
>
> As you can see it also adds new assertion so it doesn't crash when you
> insert at some out of range index.
>
>
Hey, thanks for pointing out this bug and providing a patch! I've just
fixed this in git master and gmime-2-4 banches using a slightly
different approach (same logic I used in
internet_address_group_insert()) which properly handles out-of-range
indexes by just appending.
I'll be releasing gmime-2-4.11 sometime soon (tonight or this weekend).
Thanks again,
Jeff
diff --git a/ChangeLog b/ChangeLog
index a31591b..a7a5d3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-11-05 Jeffrey Stedfast <fejj novell com>
+
+ * gmime/gmime-multipart.c (ptr_array_insert): Fixed to handle an
+ index larger than the current array length as well as fixing the
+ true insert case to shift items when index is les than the current
+ array length (as opposed to when it is equal-to). Thanks to
+ harven gingers rulez pl for finding this bug.
+
2009-10-10 Jeffrey Stedfast <fejj novell com>
* gmime/gmime-utils.c: Fixed the military timezone offsets.
diff --git a/gmime/gmime-multipart.c b/gmime/gmime-multipart.c
index a5d26d8..e4e85d5 100644
--- a/gmime/gmime-multipart.c
+++ b/gmime/gmime-multipart.c
@@ -482,18 +482,20 @@ ptr_array_insert (GPtrArray *array, guint index, gpointer object)
unsigned char *dest, *src;
guint n;
- g_ptr_array_set_size (array, array->len + 1);
-
- if (index == array->len) {
- /* need to move items down */
+ if (index < array->len) {
+ /* need to shift some items */
+ g_ptr_array_set_size (array, array->len + 1);
+
dest = ((unsigned char *) array->pdata) + (sizeof (void *) * (index + 1));
src = ((unsigned char *) array->pdata) + (sizeof (void *) * index);
n = array->len - index - 1;
g_memmove (dest, src, (sizeof (void *) * n));
+ array->pdata[index] = object;
+ } else {
+ /* the easy case */
+ g_ptr_array_add (array, object);
}
-
- array->pdata[index] = object;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]