Whamcloud - gitweb
LU-6612 utils: strengthen llog_reader vs wrong format/header 54/15654/5
authorBruno Faccini <bruno.faccini@intel.com>
Mon, 20 Jul 2015 14:30:11 +0000 (16:30 +0200)
committerOleg Drokin <green@whamcloud.com>
Tue, 26 Jul 2022 04:53:20 +0000 (04:53 +0000)
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 <bruno.faccini@intel.com>
Change-Id: I12be79e6c6a5da384a5fd81878a76a7ea8aa5834
Reviewed-on: https://review.whamcloud.com/15654
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Mike Pershin <mpershin@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/utils/llog_reader.c

index dc2ef05..153a471 100644 (file)
@@ -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;