aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Alex Bennee <alex@bennee.com>2011-03-28 19:34:48 +0100
committerGravatar Alex Bennee <alex@bennee.com>2011-03-28 19:34:48 +0100
commit55e2c3d68d3ba31190c2484db496e09756852ee6 (patch)
tree4e855e8d321501fc2bc55602f64e58117ebb5121
parent6f4b502f1e6be2644ca0d984f918afb802f4116f (diff)
misc.c: fix potential memory corruption
As reported by valgrind: Invalid read of size 1 at 0x4C28064: strlen (mc_replace_strmem.c:282) by 0x9690261: g_strdup (in /usr/lib64/libglib-2.0.so.0.2600.1) by 0x89E700C: value_collect_string (in /usr/lib64/libgobject-2.0.so.0.2600.1) by 0x89D7738: g_signal_emit_valist (in /usr/lib64/libgobject-2.0.so.0.2600.1) by 0x89D7CF1: g_signal_emit_by_name (in /usr/lib64/libgobject-2.0.so.0.2600.1) by 0x4EEF092: gtk_entry_insert_text (in /usr/lib64/libgtk-x11-2.0.so.0.2200.1) by 0x449F1A: Insert_Only_Digit (misc.c:437) by 0x89BD19D: g_closure_invoke (in /usr/lib64/libgobject-2.0.so.0.2600.1) by 0x89D6278: signal_emit_unlocked_R (in /usr/lib64/libgobject-2.0.so.0.2600.1) by 0x89D79F5: g_signal_emit_valist (in /usr/lib64/libgobject-2.0.so.0.2600.1) by 0x89D7CF1: g_signal_emit_by_name (in /usr/lib64/libgobject-2.0.so.0.2600.1) by 0x4EEF092: gtk_entry_insert_text (in /usr/lib64/libgtk-x11-2.0.so.0.2200.1) Address 0x1604d642 is 0 bytes after a block of size 2 alloc'd at 0x4C25218: calloc (vg_replace_malloc.c:467) by 0x9678639: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.2600.1) by 0x449E8E: Insert_Only_Digit (misc.c:418) by 0x89BD19D: g_closure_invoke (in /usr/lib64/libgobject-2.0.so.0.2600.1) by 0x89D6278: signal_emit_unlocked_R (in /usr/lib64/libgobject-2.0.so.0.2600.1) by 0x89D79F5: g_signal_emit_valist (in /usr/lib64/libgobject-2.0.so.0.2600.1) by 0x89D7CF1: g_signal_emit_by_name (in /usr/lib64/libgobject-2.0.so.0.2600.1) by 0x4EEF092: gtk_entry_insert_text (in /usr/lib64/libgtk-x11-2.0.so.0.2200.1) by 0x4EF4DB0: gtk_entry_set_text (in /usr/lib64/libgtk-x11-2.0.so.0.2200.1) by 0x43BFF9: ET_Display_File_Tag_To_UI (et_core.c:2802) by 0x43CC53: ET_Display_File_Data_To_UI (et_core.c:2545) by 0x4328A7: Action_Select_Nth_File_By_Etfile (easytag.c:1774) If we revisit this function it may be worth considering the guidance from the GTK manual about intercepting gtk_editible signals: http://library.gnome.org/devel/gtk/2.21/GtkEditable.html#GtkEditable-insert-text
-rw-r--r--src/misc.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/misc.c b/src/misc.c
index 5803279..91eab11 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -415,7 +415,7 @@ void Insert_Only_Digit (GtkEditable *editable, const gchar *inserted_text, gint
}
g_signal_stop_emission_by_name(G_OBJECT(editable),"insert_text");
- result = g_malloc0(length);
+ result = g_malloc0(length+1);
result[0] = inserted_text[0];
// Check the rest, if any...
@@ -426,6 +426,8 @@ void Insert_Only_Digit (GtkEditable *editable, const gchar *inserted_text, gint
result[j++] = inserted_text[i];
}
}
+ // Null terminate for the benefit of glib/gtk
+ result[j] = '\0';
if (result[0] == (gchar)NULL)
{