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 <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Casey committed
Sep 23, 2013 at 11:49 UTC
da2727f23c68fb8cbda3cbd03e81141531166585
1 file changed
+9
-3
contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
+9
-3
@@ -289,12 +289,14 @@ static void credential_clear(struct credential *c)
289
290
static int credential_read(struct credential *c)
291
{
292
- char buf[1024];
292
+ char *buf;
293
size_t line_len;
294
- char *key = buf;
294
+ char *key;
295
char *value;
296
297
- while (fgets(buf, sizeof(buf), stdin))
297
+ key = buf = gnome_keyring_memory_alloc(1024);
298
+
299
+ while (fgets(buf, 1024, stdin))
300
{
301
line_len = strlen(buf);
302
@@ -307,6 +309,7 @@ static int credential_read(struct credential *c)
309
value = strchr(buf,'=');
310
if (!value) {
311
warning("invalid credential line: %s", key);
312
+ gnome_keyring_memory_free(buf);
313
return -1;
314
}
315
*value++ = '\0';
@@ -339,6 +342,9 @@ static int credential_read(struct credential *c)
342
* learn new lines, and the helpers are updated to match.
343
*/
344
}
345
+
346
+ gnome_keyring_memory_free(buf);
347
+
348
return 0;
349
}
350