[Skiboot] [PATCH 1/4] external/pflash: Silence false positive Coverity CID 163739

Cyril Bur cyril.bur at au1.ibm.com
Wed Aug 16 19:35:37 AEST 2017


Several of the cases in the getopt loop take the optarg pointer and pass
it to functions which will dereference it. There is currently no bug as
all of these are marked to getopt as having a requirement argument so
optarg will never be null.

The rationale for this patch is firstly to silence coverity as it is
fairly simple to do. More importantly having a brand new version of this
Coverity error appear in the event of a future mistake with optional
arguments to getopt will be useful.

Fixes: CID 163739
Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
 external/pflash/pflash.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
index a08ea946..ed33a6fd 100644
--- a/external/pflash/pflash.c
+++ b/external/pflash/pflash.c
@@ -753,6 +753,8 @@ int main(int argc, char *argv[])
 			disable_4B = true;
 			break;
 		case 'r':
+			if (!optarg)
+				break;
 			do_read = true;
 			free(read_file);
 			read_file = strdup(optarg);
@@ -767,6 +769,8 @@ int main(int argc, char *argv[])
 			direct = true;
 			break;
 		case 'p':
+			if (!optarg)
+				break;
 			program = true;
 			free(write_file);
 			write_file = strdup(optarg);
@@ -803,6 +807,8 @@ int main(int argc, char *argv[])
 			flash_side = atoi(optarg);
 			break;
 		case 'T':
+			if (!optarg)
+				break;
 			ffs_toc_seen = true;
 			flash.toc = strtoul(optarg, &endptr, 0);
 			if (*endptr != '\0') {
-- 
2.14.1



More information about the Skiboot mailing list