summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-02-11 13:21:47 -0500
committerNick Mathewson <nickm@torproject.org>2016-02-12 08:54:09 -0500
commita874d66ea9ddb8c64189f33bb2a9ef05ee74f3fe (patch)
tree0bd0d6f991ecad67fde86a24d4a251b7f621a59f /src/tools
parent5a164d50bbfd66ef51408794d03c8db8071ddabb (diff)
downloadtor-a874d66ea9ddb8c64189f33bb2a9ef05ee74f3fe.tar.gz
tor-a874d66ea9ddb8c64189f33bb2a9ef05ee74f3fe.zip
Handle the case where tor-gencert gets a passphrase with no NL
Closes ticket 17443.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/tor-gencert.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/tools/tor-gencert.c b/src/tools/tor-gencert.c
index e833aa9ef5..4e5e1dc590 100644
--- a/src/tools/tor-gencert.c
+++ b/src/tools/tor-gencert.c
@@ -96,14 +96,21 @@ load_passphrase(void)
{
char *cp;
char buf[1024]; /* "Ought to be enough for anybody." */
+ memset(buf, 0, sizeof(buf)); /* should be needless */
ssize_t n = read_all(passphrase_fd, buf, sizeof(buf), 0);
if (n < 0) {
log_err(LD_GENERAL, "Couldn't read from passphrase fd: %s",
strerror(errno));
return -1;
}
+ /* We'll take everything from the buffer except for optional terminating
+ * newline. */
cp = memchr(buf, '\n', n);
- passphrase_len = cp-buf;
+ if (cp == NULL) {
+ passphrase_len = n;
+ } else {
+ passphrase_len = cp-buf;
+ }
passphrase = tor_strndup(buf, passphrase_len);
memwipe(buf, 0, sizeof(buf));
return 0;