Also properly check the return value of read() and leave room
for termination.
Fixes junk data occasionally seen in strings read through systemd.
Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1460606013-4983-1-git-send-email-selva.nair@gmail.com>
URL: http://article.gmane.org/gmane.network.openvpn.devel/11437
Signed-off-by: Gert Doering <gert@greenie.muc.de>
... | ... |
@@ -172,8 +172,9 @@ get_console_input_systemd (const char *prompt, const bool echo, char *input, con |
172 | 172 |
if ((std_out = openvpn_popen (&argv, NULL)) < 0) { |
173 | 173 |
return false; |
174 | 174 |
} |
175 |
- CLEAR (*input); |
|
176 |
- if (read (std_out, input, capacity) != 0) |
|
175 |
+ |
|
176 |
+ memset (input, 0, capacity); |
|
177 |
+ if (read (std_out, input, capacity-1) > 0) |
|
177 | 178 |
{ |
178 | 179 |
chomp (input); |
179 | 180 |
ret = true; |