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

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