diff mbox

linux-generic: setup_pktio_entry() null terminate pkio name

Message ID 1424100435-21015-1-git-send-email-maxim.uvarov@linaro.org
State Accepted
Commit a435d3b3e1b030cb7d8c5d58c249f82c9822ae1b
Headers show

Commit Message

Maxim Uvarov Feb. 16, 2015, 3:27 p.m. UTC
Pktio code uses snprintf instead of strncpy for name copying.

https://bugs.linaro.org/show_bug.cgi?id=1055

CID 85426:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
Calling strncpy with a maximum size argument of 16 bytes on
destination array "pktio_entry->s.name" of size 16 bytes might
leave the destination string unterminated.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 platform/linux-generic/odp_packet_io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Mike Holmes Feb. 16, 2015, 8:19 p.m. UTC | #1
On 16 February 2015 at 10:27, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

> Pktio code uses snprintf instead of strncpy for name copying.
>
> https://bugs.linaro.org/show_bug.cgi?id=1055
>
> CID 85426:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
> Calling strncpy with a maximum size argument of 16 bytes on
> destination array "pktio_entry->s.name" of size 16 bytes might
> leave the destination string unterminated.
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
>

Reviewed-by: Mike Holmes <mike.holmes@linaro.org>


> ---
>  platform/linux-generic/odp_packet_io.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/platform/linux-generic/odp_packet_io.c
> b/platform/linux-generic/odp_packet_io.c
> index 559b230..c5d0569 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -251,7 +251,7 @@ static odp_pktio_t setup_pktio_entry(const char *dev,
> odp_pool_t pool)
>                 id = ODP_PKTIO_INVALID;
>                 ODP_ERR("Unable to init any I/O type.\n");
>         } else {
> -               strncpy(pktio_entry->s.name, dev, IFNAMSIZ);
> +               snprintf(pktio_entry->s.name, IFNAMSIZ, "%s", dev);
>                 unlock_entry_classifier(pktio_entry);
>         }
>
> --
> 1.8.5.1.163.gd7aced9
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
diff mbox

Patch

diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index 559b230..c5d0569 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -251,7 +251,7 @@  static odp_pktio_t setup_pktio_entry(const char *dev, odp_pool_t pool)
 		id = ODP_PKTIO_INVALID;
 		ODP_ERR("Unable to init any I/O type.\n");
 	} else {
-		strncpy(pktio_entry->s.name, dev, IFNAMSIZ);
+		snprintf(pktio_entry->s.name, IFNAMSIZ, "%s", dev);
 		unlock_entry_classifier(pktio_entry);
 	}