diff mbox

helper: test: chksum: catch errors in scan_ip

Message ID 1437744350-2732-1-git-send-email-mike.holmes@linaro.org
State Accepted
Commit f7afeec4a80c280d72a4f4d00ff051753102d5c1
Headers show

Commit Message

Mike Holmes July 24, 2015, 1:25 p.m. UTC
It is possible for scan_ip to return an error leaving the buf variable
pointed to undefined. Check scan_ips return code.

Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---
 helper/test/odp_chksum.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Bill Fischofer July 24, 2015, 1:29 p.m. UTC | #1
On Fri, Jul 24, 2015 at 8:25 AM, Mike Holmes <mike.holmes@linaro.org> wrote:

> It is possible for scan_ip to return an error leaving the buf variable
> pointed to undefined. Check scan_ips return code.
>
> Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
>

Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>


> ---
>  helper/test/odp_chksum.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/helper/test/odp_chksum.c b/helper/test/odp_chksum.c
> index dfd578f..1d417a8 100644
> --- a/helper/test/odp_chksum.c
> +++ b/helper/test/odp_chksum.c
> @@ -157,8 +157,16 @@ int main(int argc TEST_UNUSED, char *argv[]
> TEST_UNUSED)
>         memcpy((char *)eth->dst.addr, &des, ODPH_ETHADDR_LEN);
>         eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4);
>
> -       scan_ip("192.168.0.1", &dstip);
> -       scan_ip("192.168.0.2", &srcip);
> +       if (!scan_ip("192.168.0.1", &dstip)) {
> +               LOG_ERR("Error: scan_ip\n");
> +               return -1;
> +       }
> +
> +       if (!scan_ip("192.168.0.2", &srcip)) {
> +               LOG_ERR("Error: scan_ip\n");
> +               return -1;
> +       }
> +
>         /* ip */
>         odp_packet_l3_offset_set(test_packet, ODPH_ETHHDR_LEN);
>         ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN);
> --
> 2.1.4
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
>
Maxim Uvarov July 27, 2015, 9:25 a.m. UTC | #2
Merged.

Maxim.

On 07/24/15 16:29, Bill Fischofer wrote:
>
>
> On Fri, Jul 24, 2015 at 8:25 AM, Mike Holmes <mike.holmes@linaro.org 
> <mailto:mike.holmes@linaro.org>> wrote:
>
>     It is possible for scan_ip to return an error leaving the buf variable
>     pointed to undefined. Check scan_ips return code.
>
>     Signed-off-by: Mike Holmes <mike.holmes@linaro.org
>     <mailto:mike.holmes@linaro.org>>
>
>
> Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org 
> <mailto:bill.fischofer@linaro.org>>
>
>     ---
>      helper/test/odp_chksum.c | 12 ++++++++++--
>      1 file changed, 10 insertions(+), 2 deletions(-)
>
>     diff --git a/helper/test/odp_chksum.c b/helper/test/odp_chksum.c
>     index dfd578f..1d417a8 100644
>     --- a/helper/test/odp_chksum.c
>     +++ b/helper/test/odp_chksum.c
>     @@ -157,8 +157,16 @@ int main(int argc TEST_UNUSED, char *argv[]
>     TEST_UNUSED)
>             memcpy((char *)eth->dst.addr, &des, ODPH_ETHADDR_LEN);
>             eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4);
>
>     -       scan_ip("192.168.0.1", &dstip);
>     -       scan_ip("192.168.0.2", &srcip);
>     +       if (!scan_ip("192.168.0.1", &dstip)) {
>     +               LOG_ERR("Error: scan_ip\n");
>     +               return -1;
>     +       }
>     +
>     +       if (!scan_ip("192.168.0.2", &srcip)) {
>     +               LOG_ERR("Error: scan_ip\n");
>     +               return -1;
>     +       }
>     +
>             /* ip */
>             odp_packet_l3_offset_set(test_packet, ODPH_ETHHDR_LEN);
>             ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN);
>     --
>     2.1.4
>
>     _______________________________________________
>     lng-odp mailing list
>     lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org>
>     https://lists.linaro.org/mailman/listinfo/lng-odp
>
>
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/helper/test/odp_chksum.c b/helper/test/odp_chksum.c
index dfd578f..1d417a8 100644
--- a/helper/test/odp_chksum.c
+++ b/helper/test/odp_chksum.c
@@ -157,8 +157,16 @@  int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
 	memcpy((char *)eth->dst.addr, &des, ODPH_ETHADDR_LEN);
 	eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4);
 
-	scan_ip("192.168.0.1", &dstip);
-	scan_ip("192.168.0.2", &srcip);
+	if (!scan_ip("192.168.0.1", &dstip)) {
+		LOG_ERR("Error: scan_ip\n");
+		return -1;
+	}
+
+	if (!scan_ip("192.168.0.2", &srcip)) {
+		LOG_ERR("Error: scan_ip\n");
+		return -1;
+	}
+
 	/* ip */
 	odp_packet_l3_offset_set(test_packet, ODPH_ETHHDR_LEN);
 	ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN);