From 2c390390ed90d4baa27a8d75762c4868bdf65e84 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Sat, 7 Jan 2012 12:28:47 +0100 Subject: [PATCH] Password cannot contain spaces. Closes #265. Thanks to Tim Hansen for reporting this bug. --- bipmkpw.1 | 2 ++ src/bipmkpw.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/bipmkpw.1 b/bipmkpw.1 index 3dfaee1..de85379 100644 --- a/bipmkpw.1 +++ b/bipmkpw.1 @@ -13,6 +13,8 @@ bipmkpw \- Password hasher for BIP bipmkpw converts a password into the double-hash used by bip. Copy the generated output from bipmkpw into bip config file. +Password cannot contain spaces. + .SH SEE ALSO bip.conf diff --git a/src/bipmkpw.c b/src/bipmkpw.c index 20fb0b4..cc2d5ff 100644 --- a/src/bipmkpw.c +++ b/src/bipmkpw.c @@ -51,11 +51,14 @@ void readpass(char *buffer, int buflen) write(ttyfd, "Password: ", 10); int idx = 0; + int valid = 1; while (idx < buflen) { read(ttyfd, buffer+idx, 1); if (buffer[idx] == '\n') { buffer[idx] = 0; break; + } else if (buffer[idx] == ' ') { + valid = 0; } idx++; } @@ -64,6 +67,11 @@ void readpass(char *buffer, int buflen) tcsetattr(ttyfd, TCSANOW, &ttback); close(ttyfd); + + if (!valid) { + fprintf(stderr, "Password cannot contain spaces.\n"); + exit(1); + } } int main(void)