diff mbox

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

Message ID 20170816093540.27595-1-cyril.bur@au1.ibm.com
State Accepted
Headers show

Commit Message

Cyril Bur Aug. 16, 2017, 9:35 a.m. UTC
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@au1.ibm.com>
---
 external/pflash/pflash.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Stewart Smith Aug. 22, 2017, 4:57 a.m. UTC | #1
Cyril Bur <cyril.bur@au1.ibm.com> writes:
> 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@au1.ibm.com>
> ---
>  external/pflash/pflash.c | 6 ++++++
>  1 file changed, 6 insertions(+)

Series merged to master as of 916bc2d8da8fee71653c325cc752f0ce901a58a2
diff mbox

Patch

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') {