contrib/git-credential-gnome-keyring.c: use secure memory functions for passwds
gnome-keyring provides functions for allocating non-pageable memory (if possible) intended to be used for storing passwords. Let's use them. Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Casey committed
Sep 23, 2013 at 11:49 UTC
9fe3e6cf9e5e3dbf8777dd78dbd27c44cfc4eb85
1 file changed
+6
-15
contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
+6
-15
@@ -30,6 +30,7 @@
30
#include <errno.h>
31
#include <glib.h>
32
#include <gnome-keyring.h>
33
+#include <gnome-keyring-memory.h>
34
35
/*
36
* This credential struct and API is simplified from git's credential.{h,c}
@@ -60,16 +61,6 @@ struct credential_operation
61
62
/* ---------------- common helper functions ----------------- */
63
63
-static inline void free_password(char *password)
64
-{
65
- char *c = password;
66
- if (!password)
67
- return;
68
-
69
- while (*c) *c++ = '\0';
70
- free(password);
71
-}
72
-
64
static inline void warning(const char *fmt, ...)
65
{
66
va_list ap;
@@ -159,8 +150,8 @@ static int keyring_get(struct credential *c)
150
/* pick the first one from the list */
151
password_data = (GnomeKeyringNetworkPasswordData *) entries->data;
152
162
- free_password(c->password);
163
- c->password = xstrdup(password_data->password);
153
+ gnome_keyring_memory_free(c->password);
154
+ c->password = gnome_keyring_memory_strdup(password_data->password);
155
156
if (!c->username)
157
c->username = xstrdup(password_data->user);
@@ -291,7 +282,7 @@ static void credential_clear(struct credential *c)
282
free(c->host);
283
free(c->path);
284
free(c->username);
294
- free_password(c->password);
285
+ gnome_keyring_memory_free(c->password);
286
287
credential_init(c);
288
}
@@ -338,8 +329,8 @@ static int credential_read(struct credential *c)
329
free(c->username);
330
c->username = xstrdup(value);
331
} else if (!strcmp(key, "password")) {
341
- free_password(c->password);
342
- c->password = xstrdup(value);
332
+ gnome_keyring_memory_free(c->password);
333
+ c->password = gnome_keyring_memory_strdup(value);
334
while (*value) *value++ = '\0';
335
}
336
/*