aboutsummaryrefslogtreecommitdiff
path: root/libbb/bb_askpass.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/bb_askpass.c')
-rw-r--r--libbb/bb_askpass.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/libbb/bb_askpass.c b/libbb/bb_askpass.c
index 0f1f68687..5ad234921 100644
--- a/libbb/bb_askpass.c
+++ b/libbb/bb_askpass.c
@@ -9,7 +9,6 @@
9 */ 9 */
10 10
11#include <termios.h> 11#include <termios.h>
12//#include <sys/ioctl.h>
13 12
14#include "libbb.h" 13#include "libbb.h"
15 14
@@ -20,18 +19,22 @@ static void askpass_timeout(int ATTRIBUTE_UNUSED ignore)
20 19
21char *bb_askpass(int timeout, const char * prompt) 20char *bb_askpass(int timeout, const char * prompt)
22{ 21{
23 static char passwd[64]; 22 /* Was static char[BIGNUM] */
23 enum { sizeof_passwd = 128 };
24 static char *passwd;
24 25
25 char *ret; 26 char *ret;
26 int i; 27 int i;
27 struct sigaction sa; 28 struct sigaction sa;
28 struct termios old, new; 29 struct termios old, new;
29 30
31 if (!passwd)
32 passwd = xmalloc(sizeof_passwd);
33 memset(passwd, 0, sizeof_passwd);
34
30 tcgetattr(STDIN_FILENO, &old); 35 tcgetattr(STDIN_FILENO, &old);
31 tcflush(STDIN_FILENO, TCIFLUSH); 36 tcflush(STDIN_FILENO, TCIFLUSH);
32 37
33 memset(passwd, 0, sizeof(passwd));
34
35 fputs(prompt, stdout); 38 fputs(prompt, stdout);
36 fflush(stdout); 39 fflush(stdout);
37 40
@@ -48,7 +51,9 @@ char *bb_askpass(int timeout, const char * prompt)
48 } 51 }
49 52
50 ret = NULL; 53 ret = NULL;
51 if (read(STDIN_FILENO, passwd, sizeof(passwd)-1) > 0) { 54 /* On timeout, read will hopefully be interrupted by SIGALRM,
55 * and we return NULL */
56 if (read(STDIN_FILENO, passwd, sizeof_passwd-1) > 0) {
52 ret = passwd; 57 ret = passwd;
53 i = 0; 58 i = 0;
54 /* Last byte is guaranteed to be 0 59 /* Last byte is guaranteed to be 0
@@ -64,7 +69,7 @@ char *bb_askpass(int timeout, const char * prompt)
64 } 69 }
65 70
66 tcsetattr(STDIN_FILENO, TCSANOW, &old); 71 tcsetattr(STDIN_FILENO, TCSANOW, &old);
67 puts(""); 72 putchar('\n');
68 fflush(stdout); 73 fflush(stdout);
69 return ret; 74 return ret;
70} 75}