Return-path: Received: from cantor2.suse.de ([195.135.220.15] helo=mx2.suse.de) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XNHfo-0001Lk-EP for kexec@lists.infradead.org; Fri, 29 Aug 2014 08:36:44 +0000 Date: Fri, 29 Aug 2014 10:36:20 +0200 From: Petr Tesarik Subject: [PATCH] dump_log_entry: replace magic constant with a variable Message-ID: <20140829103620.15aee556@hananiah.suse.cz> Mime-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kexec" Errors-To: kexec-bounces+dwmw2=infradead.org@lists.infradead.org To: Atsushi Kumagai Cc: "kexec@lists.infradead.org" If the buffer space requirements are changed, the magic constant is hard to spot, and the failure is easily overlooked, because it may fail only under special conditions. Signed-off-by: Petr Tesarik --- makedumpfile.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/makedumpfile.c b/makedumpfile.c index b4b6eca..37dea37 100644 --- a/makedumpfile.c +++ b/makedumpfile.c @@ -3949,7 +3949,7 @@ static int dump_log_entry(char *logptr, int fp) { char *msg, *p, *bufp; - unsigned int i, text_len; + unsigned int i, text_len, buf_need; unsigned long long ts_nsec; char buf[BUFSIZE]; ulonglong nanos; @@ -3966,9 +3966,11 @@ dump_log_entry(char *logptr, int fp) bufp = buf; bufp += sprintf(buf, "[%5lld.%06ld] ", nanos, rem/1000); + /* How much buffer space is needed in the worst case */ + buf_need = sizeof("\\xXX\n"); + for (i = 0, p = msg; i < text_len; i++, p++) { - /* 6bytes = "\\x%02x" + '\n' + '\0' */ - if (bufp - buf >= sizeof(buf) - 6) { + if (bufp - buf >= sizeof(buf) - buf_need) { if (write(info->fd_dumpfile, buf, bufp - buf) < 0) return FALSE; bufp = buf; -- _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec