]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Ensure input read using systemd-ask-password is null terminated
authorSelva Nair <selva.nair@gmail.com>
Thu, 14 Apr 2016 03:53:33 +0000 (23:53 -0400)
committerGert Doering <gert@greenie.muc.de>
Thu, 14 Apr 2016 20:07:26 +0000 (22:07 +0200)
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>
src/openvpn/console.c

index e1d46c413e46f5d5eda1ad39b01e8ae0680e845c..86331a11c23ce8021bb7965ff3d77141a69fc6e5 100644 (file)
@@ -172,8 +172,9 @@ get_console_input_systemd (const char *prompt, const bool echo, char *input, con
   if ((std_out = openvpn_popen (&argv, NULL)) < 0) {
          return false;
   }
-  CLEAR (*input);
-  if (read (std_out, input, capacity) != 0)
+
+  memset (input, 0, capacity);
+  if (read (std_out, input, capacity-1) > 0)
     {
        chomp (input);
        ret = true;