diff mbox

fwts: lib: clean up static analysis warnings

Message ID 1463471834-29067-1-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King May 17, 2016, 7:57 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Although this is not possible, I'd like to clean up a warning
from static analysis just for the sake ensuring we never do
a write to a null pointer to the buffer.

CID 1354842:  Null pointer dereferences  (FORWARD_NULL)
Passing null pointer "in_buf" to "write", which dereferences it.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_pipeio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alex Hung May 17, 2016, 8:16 a.m. UTC | #1
On 2016-05-17 03:57 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Although this is not possible, I'd like to clean up a warning
> from static analysis just for the sake ensuring we never do
> a write to a null pointer to the buffer.
>
> CID 1354842:  Null pointer dereferences  (FORWARD_NULL)
> Passing null pointer "in_buf" to "write", which dereferences it.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_pipeio.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_pipeio.c b/src/lib/src/fwts_pipeio.c
> index 859e63e..b501f7b 100644
> --- a/src/lib/src/fwts_pipeio.c
> +++ b/src/lib/src/fwts_pipeio.c
> @@ -206,7 +206,7 @@ int fwts_pipe_readwrite(
>   			*(ptr+out_size) = 0;
>   		}
>
> -		if (pollfds[1].revents) {
> +		if ((in_fd > 0) && in_buf && pollfds[1].revents) {
>   			n = write(in_fd, in_buf, in_size);
>
>   			if (n < 0) {
>

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu May 17, 2016, 9:37 a.m. UTC | #2
On 05/17/2016 03:57 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Although this is not possible, I'd like to clean up a warning
> from static analysis just for the sake ensuring we never do
> a write to a null pointer to the buffer.
>
> CID 1354842:  Null pointer dereferences  (FORWARD_NULL)
> Passing null pointer "in_buf" to "write", which dereferences it.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_pipeio.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_pipeio.c b/src/lib/src/fwts_pipeio.c
> index 859e63e..b501f7b 100644
> --- a/src/lib/src/fwts_pipeio.c
> +++ b/src/lib/src/fwts_pipeio.c
> @@ -206,7 +206,7 @@ int fwts_pipe_readwrite(
>   			*(ptr+out_size) = 0;
>   		}
>   
> -		if (pollfds[1].revents) {
> +		if ((in_fd > 0) && in_buf && pollfds[1].revents) {
>   			n = write(in_fd, in_buf, in_size);
>   
>   			if (n < 0) {
Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox

Patch

diff --git a/src/lib/src/fwts_pipeio.c b/src/lib/src/fwts_pipeio.c
index 859e63e..b501f7b 100644
--- a/src/lib/src/fwts_pipeio.c
+++ b/src/lib/src/fwts_pipeio.c
@@ -206,7 +206,7 @@  int fwts_pipe_readwrite(
 			*(ptr+out_size) = 0;
 		}
 
-		if (pollfds[1].revents) {
+		if ((in_fd > 0) && in_buf && pollfds[1].revents) {
 			n = write(in_fd, in_buf, in_size);
 
 			if (n < 0) {