summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2014-03-05 23:03:20 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2014-03-05 23:03:20 +0000
commit7b83993f03185ffa08efce430b09e06de7dff575 (patch)
treee4a2405c78bb3dda7886abbb843f6f6edf3e8978
parent20fc2491169e71122b63b88a8b8c703f64802aa0 (diff)
when reading a message, add one byte so we can nul terminuate.
simplify verifychecksums with the knowledge that input is a proper string.
-rw-r--r--usr.bin/signify/signify.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/usr.bin/signify/signify.c b/usr.bin/signify/signify.c
index f6b3ace261d..d0a65c82fd3 100644
--- a/usr.bin/signify/signify.c
+++ b/usr.bin/signify/signify.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: signify.c,v 1.44 2014/03/05 22:55:07 tedu Exp $ */
+/* $OpenBSD: signify.c,v 1.45 2014/03/05 23:03:19 tedu Exp $ */
/*
* Copyright (c) 2013 Ted Unangst <tedu@openbsd.org>
*
@@ -193,8 +193,9 @@ readmsg(const char *filename, unsigned long long *msglenp)
msglen = sb.st_size;
if (msglen > (1UL << 30))
errx(1, "msg too large in %s", filename);
- msg = xmalloc(msglen);
+ msg = xmalloc(msglen + 1);
readall(fd, msg, msglen, filename);
+ msg[msglen] = 0;
close(fd);
*msglenp = msglen;
@@ -469,19 +470,16 @@ struct checksum {
};
static void
-verifychecksums(const char *msg, unsigned long long msglen, int argc,
- char **argv, int quiet)
+verifychecksums(char *msg, int argc, char **argv, int quiet)
{
char buf[1024];
- char *input, *line, *endline;
+ char *line, *endline;
struct checksum *checksums = NULL, *c = NULL;
int nchecksums = 0;
int i, j, uselist, count, hasfailed;
int *failures;
- if (!(input = strndup(msg, msglen)))
- err(1, "strndup");
- line = input;
+ line = msg;
while (line && *line) {
if (!(checksums = realloc(checksums,
sizeof(*c) * (nchecksums + 1))))
@@ -497,7 +495,6 @@ verifychecksums(const char *msg, unsigned long long msglen, int argc,
strlcpy(c->file, buf + 1, sizeof(c->file));
line = endline;
}
- free(input);
if (argc) {
uselist = 0;
@@ -581,7 +578,7 @@ check(const char *pubkeyfile, const char *sigfile, int quiet, int argc,
}
verifymsg(pubkey.pubkey, msg, msglen, sig.sig, quiet);
- verifychecksums(msg, msglen, argc, argv, quiet);
+ verifychecksums((char *)msg, argc, argv, quiet);
free(msg - siglen);
}