From 148ded5c56d62dc358f566d322ea96dddfdd8faf Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 4 Jul 2011 18:59:54 +0200 Subject: [PATCH 1/2] password-agent: make sure not to access unallocated memory Tracked down by Frederic Crozat --- src/tty-ask-password-agent.c | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/tty-ask-password-agent.c b/src/tty-ask-password-agent.c index d7e1eba..bee2f97 100644 --- a/src/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent.c @@ -376,12 +376,14 @@ static int parse_password(const char *filename, char **wall) { release_terminal(); } - packet_length = 1+strlen(password)+1; - if (!(packet = new(char, packet_length))) - r = -ENOMEM; - else { - packet[0] = '+'; - strcpy(packet+1, password); + if (r >= 0) { + packet_length = 1+strlen(password)+1; + if (!(packet = new(char, packet_length))) + r = -ENOMEM; + else { + packet[0] = '+'; + strcpy(packet+1, password); + } } free(password); -- 1.7.3.4 From 722dad411964f71adc0a22a74609d35308c8ab9b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 4 Jul 2011 19:06:32 +0200 Subject: [PATCH 2/2] password-agent: actually really don't access unallocated memory Fix for 9726f9ff11fa7b94dceed2972cd2453a08b9ee6a --- src/tty-ask-password-agent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tty-ask-password-agent.c b/src/tty-ask-password-agent.c index bee2f97..70d33ea 100644 --- a/src/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent.c @@ -384,9 +384,9 @@ static int parse_password(const char *filename, char **wall) { packet[0] = '+'; strcpy(packet+1, password); } - } - free(password); + free(password); + } } if (r == -ETIME || r == -ENOENT) { -- 1.7.3.4