Skip to contentSkip to conversation

examples/ntb: fix error handling

PATCH Superseded Xiaoyun Li 3 participants 6 messages Aug 5, 2019 – Aug 6, 2019

lore
Share & tools
lore

Xiaoyun Li

author
#0 lore raw

PATCH 1/1 examples/ntb: fix error handling

This patch adds return value checking for fseek function to fix error handling issue found by coverity scan.

Coverity issue: 344996

Fixes c5eebf85badc ("examples/ntb: add example for NTB")
---
 examples/ntb/ntb_fwd.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
examples/ntb/ntb_fwd.c +11 -2
index c169f01a3..671b13f50 100644
@@ -107,6 +107,7 @@ cmd_sendfile_parsed(void *parsed_result,
 	uint8_t *buff;
 	uint32_t val;
 	FILE *file;
+	int status;
 
 	if (!rte_rawdevs[dev_id].started) {
 		printf("Device needs to be up first. Try later.\n");
@@ -125,9 +126,17 @@ cmd_sendfile_parsed(void *parsed_result,
 		return;
 	}
 
-	fseek(file, 0, SEEK_END);
+	status = fseek(file, 0, SEEK_END);
+	if (status) {
+		printf("Fail to get file size.\n");
+		return;
+	}
 	size = ftell(file);
-	fseek(file, 0, SEEK_SET);
+	status = fseek(file, 0, SEEK_SET);
+	if (status) {
+		printf("Fail to get file size.\n");
+		return;
+	}
 
 	/**
 	 * No FIFO now. Only test memory. Limit sending file
Signature · 1 line
2.17.1
#1 lore raw
Quoted 25 lines · Xiaoyun Li

This patch adds return value checking for fseek function to fix error handling issue found by coverity scan.

Coverity issue: 344996

Fixes c5eebf85badc ("examples/ntb: add example for NTB")

---
examples/ntb/ntb_fwd.c | 13 +++++++++++--

1 file changed, 11 insertions(+), 2 deletions(-)
examples/ntb/ntb_fwd.c +1 -0
index c169f01a3..671b13f50 100644
@@ -107,6 +107,7 @@ cmd_sendfile_parsed(void *parsed_result,
 	uint8_t *buff;
 	uint32_t val;
 	FILE *file;
+	int status;
 
 	if (!rte_rawdevs[dev_id].started) {
 		printf("Device needs to be up first. Try later.\n");

examples/ntb/ntb_fwd.c cmd_sendfile_parsed(void *parsed_result, · line 130

Quoted 6 lines
examples/ntb/ntb_fwd.c +2 -1
@@ -125,9 +126,17 @@ cmd_sendfile_parsed(void *parsed_result,
 		return;
 	}
 
-	fseek(file, 0, SEEK_END);
+	status = fseek(file, 0, SEEK_END);
+	if (status) {

How about simplify to

	if (fseek(file, 0, SEEK_END) < 0)

examples/ntb/ntb_fwd.c cmd_sendfile_parsed(void *parsed_result, · line 136

Quoted 7 lines
examples/ntb/ntb_fwd.c +5 -1
+		printf("Fail to get file size.\n");
+		return;
+	}
 	size = ftell(file);
-	fseek(file, 0, SEEK_SET);
+	status = fseek(file, 0, SEEK_SET);
+	if (status) {

Ditto.

Thanks,
Xiaolong

Quoted 9 lines
examples/ntb/ntb_fwd.c +3 -0
+		printf("Fail to get file size.\n");
+		return;
+	}
 
 	/**
 	 * No FIFO now. Only test memory. Limit sending file
Signature · 1 line
2.17.1
#2 lore raw

Sure. Will update in v2. Thx.

Quoted 65 lines

-----Original Message-----
From: Ye, Xiaolong
Sent: Monday, August 5, 2019 14:05
To: Li, Xiaoyun <[email protected]>
Cc: Wu, Jingjing <[email protected]>; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH] examples/ntb: fix error handling

Quoted 28 lines · Xiaoyun Li

This patch adds return value checking for fseek function to fix error handling issue found by coverity scan.

Coverity issue: 344996

Fixes c5eebf85badc ("examples/ntb: add example for NTB")

---
examples/ntb/ntb_fwd.c | 13 +++++++++++--

1 file changed, 11 insertions(+), 2 deletions(-)
examples/ntb/ntb_fwd.c index renamed from examples/ntb/ntb_fwd.c +0 -0

c169f01a3..671b13f50 100644

examples/ntb/ntb_fwd.c +2 -0
@@ -107,6 +107,7 @@ cmd_sendfile_parsed(void *parsed_result,
 	uint8_t *buff;
 	uint32_t val;
 	FILE *file;
+	int status;
 
 	if (!rte_rawdevs[dev_id].started) {
 		printf("Device needs to be up first. Try later.\n"); @@ -125,9
+126,17 @@ cmd_sendfile_parsed(void *parsed_result,
		return;
	}

examples/ntb/ntb_fwd.c cmd_sendfile_parsed(void *parsed_result, · line 130

Quoted 3 lines
examples/ntb/ntb_fwd.c +2 -1
-	fseek(file, 0, SEEK_END);
+	status = fseek(file, 0, SEEK_END);
+	if (status) {

How about simplify to

	if (fseek(file, 0, SEEK_END) < 0)

examples/ntb/ntb_fwd.c cmd_sendfile_parsed(void *parsed_result, · line 136

Quoted 7 lines
examples/ntb/ntb_fwd.c +3 -0
+		printf("Fail to get file size.\n");
+		return;
+	}
	size = ftell(file);
examples/ntb/ntb_fwd.c +2 -1
-	fseek(file, 0, SEEK_SET);
+	status = fseek(file, 0, SEEK_SET);
+	if (status) {

Ditto.

Thanks,
Xiaolong

Quoted 9 lines
examples/ntb/ntb_fwd.c +3 -0
+		printf("Fail to get file size.\n");
+		return;
+	}
	/**
	 * No FIFO now. Only test memory. Limit sending file

--
2.17.1

author
#3 lore raw

PATCH v2 1/1 examples/ntb: fix error handling

In reply to Xiaoyun Li

This patch adds return value checking for fseek function to fix error handling issue found by coverity scan.

Coverity issue: 344996

Fixes c5eebf85badc ("examples/ntb: add example for NTB")
---
 examples/ntb/ntb_fwd.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
examples/ntb/ntb_fwd.c +8 -2
index c169f01a3..f8c970cdb 100644
@@ -125,9 +125,15 @@ cmd_sendfile_parsed(void *parsed_result,
 		return;
 	}
 
-	fseek(file, 0, SEEK_END);
+	if (fseek(file, 0, SEEK_END) < 0) {
+		printf("Fail to get file size.\n");
+		return;
+	}
 	size = ftell(file);
-	fseek(file, 0, SEEK_SET);
+	if (fseek(file, 0, SEEK_SET) < 0) {
+		printf("Fail to get file size.\n");
+		return;
+	}
 
 	/**
 	 * No FIFO now. Only test memory. Limit sending file
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#4 lore raw
Quoted 37 lines · Xiaoyun Li

This patch adds return value checking for fseek function to fix error handling issue found by coverity scan.

Coverity issue: 344996

Fixes c5eebf85badc ("examples/ntb: add example for NTB")

---
examples/ntb/ntb_fwd.c | 10 ++++++++--

1 file changed, 8 insertions(+), 2 deletions(-)
examples/ntb/ntb_fwd.c +8 -2
index c169f01a3..f8c970cdb 100644
@@ -125,9 +125,15 @@ cmd_sendfile_parsed(void *parsed_result,
 		return;
 	}
 
-	fseek(file, 0, SEEK_END);
+	if (fseek(file, 0, SEEK_END) < 0) {
+		printf("Fail to get file size.\n");
+		return;
+	}
 	size = ftell(file);
-	fseek(file, 0, SEEK_SET);
+	if (fseek(file, 0, SEEK_SET) < 0) {
+		printf("Fail to get file size.\n");
+		return;
+	}
 
 	/**
 	 * No FIFO now. Only test memory. Limit sending file
Signature · 1 line
2.17.1