From ff9a67870f79a844fe412a714e31379394582707 Mon Sep 17 00:00:00 2001 From: tedu Date: Tue, 6 May 2014 23:17:13 +0000 Subject: [PATCH] factor max message size --- usr.bin/signify/signify.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/usr.bin/signify/signify.c b/usr.bin/signify/signify.c index fe2e9d6165a..506ed3b644f 100644 --- a/usr.bin/signify/signify.c +++ b/usr.bin/signify/signify.c @@ -1,4 +1,4 @@ -/* $OpenBSD: signify.c,v 1.72 2014/04/22 21:24:20 tedu Exp $ */ +/* $OpenBSD: signify.c,v 1.73 2014/05/06 23:17:13 tedu Exp $ */ /* * Copyright (c) 2013 Ted Unangst * @@ -175,10 +175,11 @@ readmsg(const char *filename, unsigned long long *msglenp) struct stat sb; ssize_t x, space; int fd; + const unsigned long long maxmsgsize = 1UL << 30; fd = xopen(filename, O_RDONLY | O_NOFOLLOW, 0); if (fstat(fd, &sb) == 0 && S_ISREG(sb.st_mode)) { - if (sb.st_size > (1UL << 30)) + if (sb.st_size > maxmsgsize) errx(1, "msg too large in %s", filename); space = sb.st_size + 1; } else { @@ -188,7 +189,7 @@ readmsg(const char *filename, unsigned long long *msglenp) msg = xmalloc(space + 1); while (1) { if (space == 0) { - if (msglen * 2 > (1UL << 30)) + if (msglen * 2 > maxmsgsize) errx(1, "msg too large in %s", filename); space = msglen; if (!(msg = realloc(msg, msglen + space + 1))) -- 2.20.1