summaryrefslogtreecommitdiff
path: root/readpass.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2002-01-22 23:05:31 +1100
committerDamien Miller <djm@mindrot.org>2002-01-22 23:05:31 +1100
commitf451e22e2134463062f7134f3e3556ab78ea0661 (patch)
tree60ad9ef0e5d187056937dd324f1b1cf18d9c6f6c /readpass.c
parenta41c8b15bd2137f99e70d792ea66ee98e390726b (diff)
- djm@cvs.openbsd.org 2001/12/21 08:53:45
[readpass.c] Avoid interruptable passphrase read; ok markus@
Diffstat (limited to 'readpass.c')
-rw-r--r--readpass.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/readpass.c b/readpass.c
index a0429818e..7e13828b7 100644
--- a/readpass.c
+++ b/readpass.c
@@ -32,7 +32,7 @@
32 */ 32 */
33 33
34#include "includes.h" 34#include "includes.h"
35RCSID("$OpenBSD: readpass.c,v 1.23 2001/11/08 10:51:08 markus Exp $"); 35RCSID("$OpenBSD: readpass.c,v 1.24 2001/12/21 08:53:45 djm Exp $");
36 36
37#include "xmalloc.h" 37#include "xmalloc.h"
38#include "readpass.h" 38#include "readpass.h"
@@ -46,7 +46,7 @@ ssh_askpass(char *askpass, const char *msg)
46 pid_t pid; 46 pid_t pid;
47 size_t len; 47 size_t len;
48 char *pass; 48 char *pass;
49 int p[2], status; 49 int p[2], status, ret;
50 char buf[1024]; 50 char buf[1024];
51 51
52 if (fflush(stdout) != 0) 52 if (fflush(stdout) != 0)
@@ -71,14 +71,23 @@ ssh_askpass(char *askpass, const char *msg)
71 fatal("ssh_askpass: exec(%s): %s", askpass, strerror(errno)); 71 fatal("ssh_askpass: exec(%s): %s", askpass, strerror(errno));
72 } 72 }
73 close(p[1]); 73 close(p[1]);
74 len = read(p[0], buf, sizeof buf -1); 74
75 len = ret = 0;
76 do {
77 ret = read(p[0], buf + len, sizeof(buf) - 1 - len);
78 if (ret == -1 && errno == EINTR)
79 continue;
80 if (ret <= 0)
81 break;
82 len += ret;
83 } while (sizeof(buf) - 1 - len > 0);
84 buf[len] = '\0';
85
75 close(p[0]); 86 close(p[0]);
76 while (waitpid(pid, &status, 0) < 0) 87 while (waitpid(pid, &status, 0) < 0)
77 if (errno != EINTR) 88 if (errno != EINTR)
78 break; 89 break;
79 if (len <= 1) 90
80 return xstrdup("");
81 buf[len] = '\0';
82 buf[strcspn(buf, "\r\n")] = '\0'; 91 buf[strcspn(buf, "\r\n")] = '\0';
83 pass = xstrdup(buf); 92 pass = xstrdup(buf);
84 memset(buf, 0, sizeof(buf)); 93 memset(buf, 0, sizeof(buf));