From 45291b8c06eebf33d3654db3a7d3cfc5836004a6 Mon Sep 17 00:00:00 2001 From: Bruno Faccini Date: Mon, 20 Jul 2015 16:30:11 +0200 Subject: [PATCH] LU-6612 utils: strengthen llog_reader vs wrong format/header The following snippet shows that llog_reader can be puzzled due to an invalid 0 for the number of records when parsing an expected LLOG file header : root# dd if=/dev/zero bs=4096 count=1 of=/tmp/zeroes 1+0 records in 1+0 records out 4096 bytes (4.1 kB) copied, 0.000263962 s, 15.5 MB/s root# llog_reader /tmp/zeroes Memory Alloc for recs_buf error. Could not pack buffer; rc=-12 Test-Parameters: trivial testlist=sanity,sanity-hsm Signed-off-by: Bruno Faccini Change-Id: I12be79e6c6a5da384a5fd81878a76a7ea8aa5834 Reviewed-on: https://review.whamcloud.com/15654 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Mike Pershin Reviewed-by: Oleg Drokin --- lustre/utils/llog_reader.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lustre/utils/llog_reader.c b/lustre/utils/llog_reader.c index dc2ef05..153a471 100644 --- a/lustre/utils/llog_reader.c +++ b/lustre/utils/llog_reader.c @@ -222,6 +222,9 @@ int llog_pack_buffer(int fd, struct llog_log_hdr **llog, int count; int i, last_idx; + *recs = NULL; + *recs_number = 0; + rc = fstat(fd, &st); if (rc < 0) { rc = -errno; @@ -270,11 +273,13 @@ int llog_pack_buffer(int fd, struct llog_log_hdr **llog, } else if (count == 0) { llapi_printf(LLAPI_MSG_NORMAL, "uninitialized llog: zero record number\n"); - *recs_number = 0; goto clear_file_buf; } + /* the llog header not countable here.*/ recs_num = count - 1; + if (recs_num == 0) + goto clear_file_buf; recs_buf = calloc(recs_num, sizeof(**recs_pr)); if (!recs_buf) { @@ -343,7 +348,6 @@ int llog_pack_buffer(int fd, struct llog_log_hdr **llog, *recs = recs_pr; *recs_number = recs_num; - out: return rc; -- 1.8.3.1