Skip to content

Commit 9fe3e6c

Browse files
drafnelgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8bb7a54 commit 9fe3e6c

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

contrib/credential/gnome-keyring/git-credential-gnome-keyring.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <errno.h>
3131
#include <glib.h>
3232
#include <gnome-keyring.h>
33+
#include <gnome-keyring-memory.h>
3334

3435
/*
3536
* This credential struct and API is simplified from git's credential.{h,c}
@@ -60,16 +61,6 @@ struct credential_operation
6061

6162
/* ---------------- common helper functions ----------------- */
6263

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-
7364
static inline void warning(const char *fmt, ...)
7465
{
7566
va_list ap;
@@ -159,8 +150,8 @@ static int keyring_get(struct credential *c)
159150
/* pick the first one from the list */
160151
password_data = (GnomeKeyringNetworkPasswordData *) entries->data;
161152

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);
164155

165156
if (!c->username)
166157
c->username = xstrdup(password_data->user);
@@ -291,7 +282,7 @@ static void credential_clear(struct credential *c)
291282
free(c->host);
292283
free(c->path);
293284
free(c->username);
294-
free_password(c->password);
285+
gnome_keyring_memory_free(c->password);
295286

296287
credential_init(c);
297288
}
@@ -338,8 +329,8 @@ static int credential_read(struct credential *c)
338329
free(c->username);
339330
c->username = xstrdup(value);
340331
} 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);
343334
while (*value) *value++ = '\0';
344335
}
345336
/*

0 commit comments

Comments
 (0)