On 23 December 2014 at 06:39, Maxim Uvarov <[email protected]> wrote:

> Fix covery waring for:
> platform/linux-generic/odp_packet_io.c: 250 in odp_pktio_open()
> CID 83058:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
>
And make all other code common.
>
> Signed-off-by: Maxim Uvarov <[email protected]>
>

Reviewed-and-Tested-by: Mike Holmes <[email protected]>

---
>  platform/linux-generic/odp_packet_io.c     | 11 ++++-------
>  platform/linux-generic/odp_packet_socket.c |  6 +++---
>  2 files changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/platform/linux-generic/odp_packet_io.c
> b/platform/linux-generic/odp_packet_io.c
> index 9376b6f..59590d2 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -247,7 +247,7 @@ odp_pktio_t odp_pktio_open(const char *dev,
> odp_buffer_pool_t pool)
>         return ODP_PKTIO_INVALID;
>
>  done:
> -       strncpy(pktio_entry->s.name, dev, IFNAMSIZ);
> +       snprintf(pktio_entry->s.name, IFNAMSIZ, "%s", dev);
>         unlock_entry_classifier(pktio_entry);
>         return id;
>  }
> @@ -560,8 +560,7 @@ int odp_pktio_mtu(odp_pktio_t id)
>         }
>
>         sockfd = sockfd_from_pktio_entry(entry);
> -       strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1);
> -       ifr.ifr_name[IFNAMSIZ - 1] = 0;
> +       snprintf(ifr.ifr_name, IFNAMSIZ, "%s", entry->s.name);
>
>         ret = ioctl(sockfd, SIOCGIFMTU, &ifr);
>         if (ret < 0) {
> @@ -596,8 +595,7 @@ int odp_pktio_promisc_mode_set(odp_pktio_t id,
> odp_bool_t enable)
>         }
>
>         sockfd = sockfd_from_pktio_entry(entry);
> -       strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1);
> -       ifr.ifr_name[IFNAMSIZ - 1] = 0;
> +       snprintf(ifr.ifr_name, IFNAMSIZ, "%s", entry->s.name);
>
>         ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr);
>         if (ret < 0) {
> @@ -644,8 +642,7 @@ int odp_pktio_promisc_mode(odp_pktio_t id)
>         }
>
>         sockfd = sockfd_from_pktio_entry(entry);
> -       strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1);
> -       ifr.ifr_name[IFNAMSIZ - 1] = 0;
> +       snprintf(ifr.ifr_name, IFNAMSIZ, "%s", entry->s.name);
>
>         ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr);
>         if (ret < 0) {
> diff --git a/platform/linux-generic/odp_packet_socket.c
> b/platform/linux-generic/odp_packet_socket.c
> index 340da88..3d3f4cb 100644
> --- a/platform/linux-generic/odp_packet_socket.c
> +++ b/platform/linux-generic/odp_packet_socket.c
> @@ -238,7 +238,7 @@ int setup_pkt_sock(pkt_sock_t *const pkt_sock, const
> char *netdev,
>
>         /* get if index */
>         memset(&ethreq, 0, sizeof(struct ifreq));
> -       strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
> +       snprintf(ethreq.ifr_name, IFNAMSIZ, "%s", netdev);
>         err = ioctl(sockfd, SIOCGIFINDEX, &ethreq);
>         if (err != 0) {
>                 perror("setup_pkt_sock() - ioctl(SIOCGIFINDEX)");
> @@ -248,7 +248,7 @@ int setup_pkt_sock(pkt_sock_t *const pkt_sock, const
> char *netdev,
>
>         /* get MAC address */
>         memset(&ethreq, 0, sizeof(ethreq));
> -       strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
> +       snprintf(ethreq.ifr_name, IFNAMSIZ, "%s", netdev);
>         err = ioctl(sockfd, SIOCGIFHWADDR, &ethreq);
>         if (err != 0) {
>                 perror("setup_pkt_sock() - ioctl(SIOCGIFHWADDR)");
> @@ -811,7 +811,7 @@ static int mmap_store_hw_addr(pkt_sock_mmap_t *const
> pkt_sock,
>
>         /* get MAC address */
>         memset(&ethreq, 0, sizeof(ethreq));
> -       strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
> +       snprintf(ethreq.ifr_name, IFNAMSIZ, "%s", netdev);
>         ret = ioctl(pkt_sock->sockfd, SIOCGIFHWADDR, &ethreq);
>         if (ret != 0) {
>                 perror("store_hw_addr() - ioctl(SIOCGIFHWADDR)");
> --
> 1.8.5.1.163.gd7aced9
>
>
> _______________________________________________
> lng-odp mailing list
> [email protected]
> http://lists.linaro.org/mailman/listinfo/lng-odp
>



-- 
*Mike Holmes*
Linaro  Sr Technical Manager
LNG - ODP
_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to