Skip to contentSkip to conversation

makedumpfile: code changes to satisfy the coverity scan

PATCH Superseded Chao Fan 2 participants 3 messages Aug 24, 2015 – Aug 26, 2015 2 messages not in the archive

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chao Fan

author
#0 lore raw

PATCH 1/1 makedumpfile: code changes to satisfy the coverity scan

Coverity scan found some uncheked return value when calling function. So the return value of the function set_page_size and lseek should be checked to satisfy the coverity scan.

In the function read_sadump_header, block_size is defined as an unsigned long value, and it will never be less than zero, so this comparison should be removed.

---
 makedumpfile.c | 3 ++-
 makedumpfile.h | 6 +++++-
 sadump_info.c  | 3 ---
 3 files changed, 7 insertions(+), 5 deletions(-)
makedumpfile.c +2 -1
index 32f5459..53efc04 100644
@@ -3213,7 +3213,8 @@ initial(void)
 			MSG("because the cyclic mode doesn't support sadump format.\n");
 		}
 
-		set_page_size(sadump_page_size());
+		if (!set_page_size(sadump_page_size()))
+			return FALSE;
 
 		if (!sadump_initialize_bitmap_memory())
 			return FALSE;
makedumpfile.h +5 -1
index d2fadbd..679e075 100644
@@ -1745,7 +1745,11 @@ is_dumpable(struct dump_bitmap *bitmap, mdf_pfn_t pfn)
 	off_t offset;
 	if (pfn == 0 || bitmap->no_block != pfn/PFN_BUFBITMAP) {
 		offset = bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
-		lseek(bitmap->fd, offset, SEEK_SET);
+		if (lseek(bitmap->fd, old_offset, SEEK_SET) < 0 ) {
+			ERRMSG("Can't seek the bitmap(%s). %s\n",
+				bitmap->file_name, strerror(errno));
+			return FALSE;
+		}
 		read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
 		if (pfn == 0)
 			bitmap->no_block = 0;
sadump_info.c +0 -3
index e2c4f03..e8154f4 100644
@@ -465,9 +465,6 @@ read_sadump_header(char *filename)
 	smh = si->smh_memory;
 
 restart:
-	if (block_size < 0)
-		return FALSE;
-
 	if (!read_device(sph, block_size, &offset))
 		return ERROR;
 
Signature · 7 lines
2.4.3


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw

Hello Chao,

Quoted 34 lines

Coverity scan found some uncheked return value when calling function. So the return value of the function set_page_size and lseek should be checked to satisfy the coverity scan.

In the function read_sadump_header, block_size is defined as an unsigned long value, and it will never be less than zero, so this comparison should be removed.

---

makedumpfile.c | 3 ++-
makedumpfile.h | 6 +++++-
sadump_info.c  | 3 ---
3 files changed, 7 insertions(+), 5 deletions(-)
makedumpfile.c +2 -1
index 32f5459..53efc04 100644
@@ -3213,7 +3213,8 @@ initial(void)
 			MSG("because the cyclic mode doesn't support sadump format.\n");
 		}
 
-		set_page_size(sadump_page_size());
+		if (!set_page_size(sadump_page_size()))
+			return FALSE;
 
 		if (!sadump_initialize_bitmap_memory())
 			return FALSE;
makedumpfile.h +0 -0
index d2fadbd..679e075 100644

makedumpfile.h is_dumpable(struct dump_bitmap *bitmap, mdf_pfn_t pfn) · line 1748

Quoted 5 lines
makedumpfile.h +1 -1
@@ -1745,7 +1745,11 @@ is_dumpable(struct dump_bitmap *bitmap, mdf_pfn_t pfn)
 	off_t offset;
 	if (pfn == 0 || bitmap->no_block != pfn/PFN_BUFBITMAP) {
 		offset = bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
-		lseek(bitmap->fd, offset, SEEK_SET);
+		if (lseek(bitmap->fd, old_offset, SEEK_SET) < 0 ) {

s/old_offset/offset/

makedumpfile.h is_dumpable(struct dump_bitmap *bitmap, mdf_pfn_t pfn) · line 1751

Quoted 3 lines
makedumpfile.h +3 -0
+			ERRMSG("Can't seek the bitmap(%s). %s\n",
+				bitmap->file_name, strerror(errno));
+			return FALSE;

You have to include print_info.h to use ERRMSG.

Thanks,
Atsushi Kumagai

Quoted 18 lines
makedumpfile.h +1 -0
+		}
 		read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
 		if (pfn == 0)
 			bitmap->no_block = 0;
sadump_info.c +0 -0
index e2c4f03..e8154f4 100644
@@ -465,9 +465,6 @@ read_sadump_header(char *filename)
 	smh = si->smh_memory;
 

restart:

sadump_info.c +0 -3
-	if (block_size < 0)
-		return FALSE;
-
	if (!read_device(sph, block_size, &offset))
		return ERROR;
Quoted 2 lines

--
2.4.3

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Hello Chao,

Quoted 4 lines

Hi Atsushi Kumagai,

Apologize for my mistake again. It is my first time to post patch,
and I am very sorry to make the big mistake.

That's Okay, I hope it was a good lesson for you.

Quoted 3 lines

I have updated and reposted the patch. If there are any problems,
please tell me and I will change it immediately.
This time, I have compiled it and test my patch. Hope it is good.

The v2 patch looks good to me, I'll merge it into v1.5.9.

Thanks,
Atsushi Kumagai

Quoted 101 lines

Thanks,
Chao Fan

----- Original Message -----

Quoted 97 lines

From: "Chao Fan" <[email protected]>
To: "Atsushi Kumagai" <[email protected]>
Sent: Tuesday, August 25, 2015 1:07:01 PM
Subject: Re: [PATCH] makedumpfile: code changes to satisfy the coverity scan

Hi Atsushi Kumagai,

Sorry for my mistake, I will update the patch. Thank you for your reply.

Thanks,
Chao Fan

----- Original Message -----

Quoted 83 lines

From: "Atsushi Kumagai" <[email protected]>
To: "Chao Fan" <[email protected]>
Cc: [email protected]
Sent: Tuesday, August 25, 2015 10:43:41 AM
Subject: RE: [PATCH] makedumpfile: code changes to satisfy the coverity scan

Hello Chao,

Quoted 34 lines

Coverity scan found some uncheked return value when calling function. So the return value of the function set_page_size and lseek should be checked to satisfy the coverity scan.

In the function read_sadump_header, block_size is defined as an unsigned long value, and it will never be less than zero, so this comparison should be removed.

---

makedumpfile.c | 3 ++-
makedumpfile.h | 6 +++++-
sadump_info.c  | 3 ---
3 files changed, 7 insertions(+), 5 deletions(-)
makedumpfile.c +2 -1
index 32f5459..53efc04 100644
@@ -3213,7 +3213,8 @@ initial(void)
 			MSG("because the cyclic mode doesn't support sadump format.\n");
 		}
 
-		set_page_size(sadump_page_size());
+		if (!set_page_size(sadump_page_size()))
+			return FALSE;
 
 		if (!sadump_initialize_bitmap_memory())
 			return FALSE;
makedumpfile.h +0 -0
index d2fadbd..679e075 100644

makedumpfile.h is_dumpable(struct dump_bitmap *bitmap, mdf_pfn_t · line 1749

Quoted 6 lines
makedumpfile.h +1 -1
@@ -1745,7 +1745,11 @@ is_dumpable(struct dump_bitmap *bitmap, mdf_pfn_t
 pfn)
 	off_t offset;
 	if (pfn == 0 || bitmap->no_block != pfn/PFN_BUFBITMAP) {
 		offset = bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
-		lseek(bitmap->fd, offset, SEEK_SET);
+		if (lseek(bitmap->fd, old_offset, SEEK_SET) < 0 ) {

s/old_offset/offset/

makedumpfile.h is_dumpable(struct dump_bitmap *bitmap, mdf_pfn_t pfn) · line 1751

Quoted 3 lines
makedumpfile.h +3 -0
+			ERRMSG("Can't seek the bitmap(%s). %s\n",
+				bitmap->file_name, strerror(errno));
+			return FALSE;

You have to include print_info.h to use ERRMSG.

Thanks,
Atsushi Kumagai

Quoted 20 lines
makedumpfile.h +1 -0
+		}
 		read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
 		if (pfn == 0)
			bitmap->no_block = 0;
sadump_info.c +0 -0
index e2c4f03..e8154f4 100644
@@ -465,9 +465,6 @@ read_sadump_header(char *filename)
 	smh = si->smh_memory;
 

restart:

sadump_info.c +0 -3
-	if (block_size < 0)
-		return FALSE;
-
	if (!read_device(sph, block_size, &offset))
		return ERROR;

--
2.4.3

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec