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

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