(I tried to send this upstream, but I can't understand how to add
comments in the upstream BTS - could you pass it on?)

The minimal fix for this bug is likely to be to change the gulongs to gsizes
in the replacement functions for g_malloc, etc., so they match the
signatures that GLib wants.

However, a better solution IMO would be: instead of replacing GLib's
normal memory allocation via linker tricks, why not use
g_mem_set_vtable() to set GLib's memory allocation in the normal and
documented way? You just need to supply an implementation of malloc,
realloc and free, which gtksecentry.c already has. I've attached an
untested patch.

    Simon
only in patch2:
unchanged:
--- pinentry-0.7.5.orig/gtk+-2/gtksecentry.h
+++ pinentry-0.7.5/gtk+-2/gtksecentry.h
@@ -173,6 +173,11 @@
 gtk_secure_entry_get_layout_offsets(GtkSecureEntry * entry,
 				    gint * x, gint * y);
 
+gpointer secentry_malloc(gsize size);
+gpointer secentry_malloc0(gsize size);
+gpointer secentry_realloc(gpointer mem, gsize size);
+void secentry_free(gpointer mem);
+
 #ifdef __cplusplus
 }
 #endif				/* __cplusplus */
only in patch2:
unchanged:
--- pinentry-0.7.5.orig/gtk+-2/gtksecentry.c
+++ pinentry-0.7.5/gtk+-2/gtksecentry.c
@@ -270,7 +270,7 @@
 
 
 gpointer
-g_malloc(gulong size)
+secentry_malloc(gsize size)
 {
     gpointer p;
 
@@ -282,13 +282,13 @@
     else
 	p = (gpointer) malloc(size);
     if (!p)
-	g_error("could not allocate %ld bytes", size);
+	g_error("could not allocate %" G_GSIZE_FORMAT " bytes", size);
 
     return p;
 }
 
 gpointer
-g_malloc0(gulong size)
+secentry_malloc0(gsize size)
 {
     gpointer p;
 
@@ -302,13 +302,13 @@
     } else
 	p = (gpointer) calloc(size, 1);
     if (!p)
-	g_error("could not allocate %ld bytes", size);
+	g_error("could not allocate %" G_GSIZE_FORMAT " bytes", size);
 
     return p;
 }
 
 gpointer
-g_realloc(gpointer mem, gulong size)
+secentry_realloc(gpointer mem, gsize size)
 {
     gpointer p;
 
@@ -332,13 +332,13 @@
     }
 
     if (!p)
-	g_error("could not reallocate %lu bytes", (gulong) size);
+	g_error("could not allocate %" G_GSIZE_FORMAT " bytes", size);
 
     return p;
 }
 
 void
-g_free(gpointer mem)
+secentry_free(gpointer mem)
 {
     if (mem) {
 	if (m_is_secure(mem))
only in patch2:
unchanged:
--- pinentry-0.7.5.orig/gtk+-2/pinentry-gtk-2.c
+++ pinentry-0.7.5/gtk+-2/pinentry-gtk-2.c
@@ -473,6 +473,17 @@
 int
 main (int argc, char *argv[])
 {
+  static GMemVTable secure = {
+    secentry_malloc,
+    secentry_realloc,
+    secentry_free,
+    NULL,
+    NULL,
+    NULL
+  };
+
+  g_mem_set_vtable (&secure);
+
   pinentry_init (PGMNAME);
     
 #ifdef FALLBACK_CURSES

Attachment: signature.asc
Description: Digital signature

Reply via email to