Skip to content

Commit da2727f

Browse files
drafnelgitster
authored andcommitted
contrib/git-credential-gnome-keyring.c: use secure memory for reading passwords
gnome-keyring provides functions to allocate non-pageable memory (if possible). Let's use them to allocate memory that may be used to hold secure data read from the keyring. Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9fe3e6c commit da2727f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,14 @@ static void credential_clear(struct credential *c)
289289

290290
static int credential_read(struct credential *c)
291291
{
292-
char buf[1024];
292+
char *buf;
293293
size_t line_len;
294-
char *key = buf;
294+
char *key;
295295
char *value;
296296

297-
while (fgets(buf, sizeof(buf), stdin))
297+
key = buf = gnome_keyring_memory_alloc(1024);
298+
299+
while (fgets(buf, 1024, stdin))
298300
{
299301
line_len = strlen(buf);
300302

@@ -307,6 +309,7 @@ static int credential_read(struct credential *c)
307309
value = strchr(buf,'=');
308310
if (!value) {
309311
warning("invalid credential line: %s", key);
312+
gnome_keyring_memory_free(buf);
310313
return -1;
311314
}
312315
*value++ = '\0';
@@ -339,6 +342,9 @@ static int credential_read(struct credential *c)
339342
* learn new lines, and the helpers are updated to match.
340343
*/
341344
}
345+
346+
gnome_keyring_memory_free(buf);
347+
342348
return 0;
343349
}
344350

0 commit comments

Comments
 (0)