password-agent: make sure not to access unallocated memory

Tracked down by Frederic Crozat
This commit is contained in:
Lennart Poettering
2011-07-04 19:00:48 +02:00
parent b8590c197d
commit 9726f9ff11
+8 -6
View File
@@ -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);