1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
--- gtk+-2/gtksecentry.c.orig 2007-11-19 16:20:50.000000000 +0500
+++ gtk+-2/gtksecentry.c 2008-04-26 22:52:13.000000000 +0600
@@ -256,7 +256,7 @@
static GtkWidgetClass *parent_class = NULL;
-gboolean g_use_secure_mem = FALSE;
+extern gboolean g_use_secure_mem;
# define g_sec_new(type, count) \
((type *) g_sec_malloc ((unsigned) sizeof (type) * (count)))
@@ -269,85 +269,6 @@
} while(0)
-gpointer
-g_malloc(gulong size)
-{
- gpointer p;
-
- if (size == 0)
- return NULL;
-
- if (g_use_secure_mem)
- p = (gpointer) secmem_malloc(size);
- else
- p = (gpointer) malloc(size);
- if (!p)
- g_error("could not allocate %ld bytes", size);
-
- return p;
-}
-
-gpointer
-g_malloc0(gulong size)
-{
- gpointer p;
-
- if (size == 0)
- return NULL;
-
- if (g_use_secure_mem) {
- p = (gpointer) secmem_malloc(size);
- if (p)
- memset(p, 0, size);
- } else
- p = (gpointer) calloc(size, 1);
- if (!p)
- g_error("could not allocate %ld bytes", size);
-
- return p;
-}
-
-gpointer
-g_realloc(gpointer mem, gulong size)
-{
- gpointer p;
-
- if (size == 0) {
- g_free(mem);
-
- return NULL;
- }
-
- if (!mem) {
- if (g_use_secure_mem)
- p = (gpointer) secmem_malloc(size);
- else
- p = (gpointer) malloc(size);
- } else {
- if (g_use_secure_mem) {
- g_assert(m_is_secure(mem));
- p = (gpointer) secmem_realloc(mem, size);
- } else
- p = (gpointer) realloc(mem, size);
- }
-
- if (!p)
- g_error("could not reallocate %lu bytes", (gulong) size);
-
- return p;
-}
-
-void
-g_free(gpointer mem)
-{
- if (mem) {
- if (m_is_secure(mem))
- secmem_free(mem);
- else
- free(mem);
- }
-}
-
GType
gtk_secure_entry_get_type(void)
{
--- gtk+-2/pinentry-gtk-2.c.orig 2007-11-19 16:44:07.000000000 +0500
+++ gtk+-2/pinentry-gtk-2.c 2008-04-26 22:52:13.000000000 +0600
@@ -39,6 +39,7 @@
#include "gtksecentry.h"
#include "pinentry.h"
+#include "memory.h"
#ifdef FALLBACK_CURSES
#include "pinentry-curses.h"
@@ -469,12 +470,36 @@
pinentry_cmd_handler_t pinentry_cmd_handler = gtk_cmd_handler;
+gboolean g_use_secure_mem = FALSE;
+
+static gpointer
+_malloc(gsize size) {
+ return g_use_secure_mem ? secmem_malloc(size) : malloc(size);
+}
+
+static gpointer
+_realloc(gpointer p, gsize size) {
+ return m_is_secure(p) ? secmem_realloc(p, size) : realloc(p, size);
+}
+
+static void
+_free(gpointer p) {
+ m_is_secure(p) ? secmem_free(p) : free(p);
+}
int
main (int argc, char *argv[])
{
pinentry_init (PGMNAME);
-
+
+ GMemVTable mem_vtable = {
+ _malloc,
+ _realloc,
+ _free
+ };
+
+ g_mem_set_vtable (&mem_vtable);
+
#ifdef FALLBACK_CURSES
if (pinentry_have_display (argc, argv))
gtk_init (&argc, &argv);
|