Blame SOURCES/0005-thin_show_duplicates-Fix-potential-errors.patch

85793c
From 32de33be68f3892698d492b9ab8f21f9186b3f4c Mon Sep 17 00:00:00 2001
85793c
From: Ming-Hung Tsai <mtsai@redhat.com>
85793c
Date: Wed, 2 Jun 2021 01:23:13 +0800
85793c
Subject: [PATCH 05/10] [thin_show_duplicates] Fix potential errors
85793c
85793c
- Fix error if no --block-sector provided
85793c
- Fix errors on pools without mappings, or zero-length file
85793c
---
85793c
 thin-provisioning/thin_show_duplicates.cc | 8 ++++++--
85793c
 1 file changed, 6 insertions(+), 2 deletions(-)
85793c
85793c
diff --git a/thin-provisioning/thin_show_duplicates.cc b/thin-provisioning/thin_show_duplicates.cc
85793c
index b1eebb7..f7354eb 100644
85793c
--- a/thin-provisioning/thin_show_duplicates.cc
85793c
+++ b/thin-provisioning/thin_show_duplicates.cc
85793c
@@ -56,7 +56,7 @@ using namespace thin_provisioning;
85793c
 
85793c
 namespace {
85793c
 	bool factor_of(block_address f, block_address n) {
85793c
-		return (n % f) == 0;
85793c
+		return f && (n % f) == 0;
85793c
 	}
85793c
 
85793c
 	uint64_t parse_int(string const &str, string const &desc) {
85793c
@@ -132,11 +132,15 @@ namespace {
85793c
 	class duplicate_detector {
85793c
 	public:
85793c
 		void scan_with_variable_sized_chunks(chunk_stream &stream) {
85793c
+			if (!stream.size())
85793c
+				return;
85793c
 			variable_chunk_stream vstream(stream, 4096);
85793c
 			scan(vstream);
85793c
 		}
85793c
 
85793c
 		void scan_with_fixed_sized_chunks(chunk_stream &stream, block_address chunk_size) {
85793c
+			if (!stream.size())
85793c
+				return;
85793c
 			fixed_chunk_stream fstream(stream, chunk_size);
85793c
 			scan(fstream);
85793c
 		}
85793c
@@ -222,7 +226,7 @@ namespace {
85793c
 		if (fs.content_based_chunks)
85793c
 			detector.scan_with_variable_sized_chunks(pstream);
85793c
 		else {
85793c
-			if (*fs.block_size) {
85793c
+			if (!!fs.block_size) {
85793c
 				if (factor_of(*fs.block_size, block_size))
85793c
 					block_size = *fs.block_size;
85793c
 				else
85793c
-- 
85793c
1.8.3.1
85793c