aboutsummaryrefslogtreecommitdiffstats
path: root/src/passphrase.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-11-19 00:54:52 +0100
committerMattias Andrée <maandree@operamail.com>2013-11-19 00:54:52 +0100
commit8ddb1140a188f921b02bd5266aa3ab659734a7e6 (patch)
treea96e347e68d1c921bbae92cdde6d86a4f08f4be1 /src/passphrase.c
parentm + spawn shell (diff)
downloadlibpassphrase-8ddb1140a188f921b02bd5266aa3ab659734a7e6.tar.gz
libpassphrase-8ddb1140a188f921b02bd5266aa3ab659734a7e6.tar.bz2
libpassphrase-8ddb1140a188f921b02bd5266aa3ab659734a7e6.tar.xz
m + redisable echo when the tty has been reopened
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/passphrase.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/passphrase.c b/src/passphrase.c
index 9482ba1..50c957f 100644
--- a/src/passphrase.c
+++ b/src/passphrase.c
@@ -46,11 +46,18 @@ char* get_passphrase(void)
we will not do that under normal usecases, if we do, it
okay to segfault on null derefencing and quit on that. */
- char* rc = malloc(START_PASSPHRASE_LIMIT);
+ char* rc = malloc(START_PASSPHRASE_LIMIT * sizeof(char));
long size = START_PASSPHRASE_LIMIT;
long len = 0;
int c;
+ if (rc == NULL)
+ {
+ perror("malloc");
+ sleep(ERROR_SLEEP);
+ _exit(1);
+ }
+
/* Read password until EOF or Enter, skip all ^0 as that
is probably not a part of the passphrase (good luck typing
that in X.org) and can be echoed into stdin by the kernel. */
@@ -63,7 +70,12 @@ char* get_passphrase(void)
{
*(rc + len++) = c;
if (len == size)
- rc = realloc(rc, size <<= 1L);
+ if ((rc = realloc(rc, (size <<= 1L) * sizeof(char))) == NULL)
+ {
+ perror("realloc");
+ sleep(ERROR_SLEEP);
+ _exit(1);
+ }
}
}
@@ -81,8 +93,8 @@ void disable_echo(void)
{
struct termios stty;
- tcgetattr(STDIN_FILENO, &saved_stty);
- stty = saved_stty;
+ tcgetattr(STDIN_FILENO, &stty);
+ saved_stty = stty;
stty.c_lflag &= ~ECHO;
tcsetattr(STDIN_FILENO, TCSAFLUSH, &stty);
}