diff mbox

[4/4] linux-generic: correctly copy pktio name with snprintf

Message ID 1419334799-19653-5-git-send-email-maxim.uvarov@linaro.org
State Accepted
Commit ff3f4e62c3b5e514678e8cedf3625d8a717f3c3a
Headers show

Commit Message

Maxim Uvarov Dec. 23, 2014, 11:39 a.m. UTC
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 <maxim.uvarov@linaro.org>
---
 platform/linux-generic/odp_packet_io.c     | 11 ++++-------
 platform/linux-generic/odp_packet_socket.c |  6 +++---
 2 files changed, 7 insertions(+), 10 deletions(-)

Comments

Mike Holmes Dec. 23, 2014, 4:49 p.m. UTC | #1
On 23 December 2014 at 06:39, Maxim Uvarov <maxim.uvarov@linaro.org> 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 <maxim.uvarov@linaro.org>
>

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

---
>  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
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
Maxim Uvarov Dec. 24, 2014, 2:20 p.m. UTC | #2
Merged this patch.

Maxim.

On 12/23/2014 07:49 PM, Mike Holmes wrote:
>
>
> On 23 December 2014 at 06:39, Maxim Uvarov <maxim.uvarov@linaro.org 
> <mailto:maxim.uvarov@linaro.org>> 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 <maxim.uvarov@linaro.org
>     <mailto:maxim.uvarov@linaro.org>>
>
>
> Reviewed-and-Tested-by: Mike Holmes <mike.holmes@linaro.org 
> <mailto:mike.holmes@linaro.org>>
>
>     ---
>      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 <http://s.name>, dev, IFNAMSIZ);
>     +       snprintf(pktio_entry->s.name <http://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 <http://s.name>,
>     IFNAMSIZ - 1);
>     -       ifr.ifr_name[IFNAMSIZ - 1] = 0;
>     +       snprintf(ifr.ifr_name, IFNAMSIZ, "%s", entry->s.name
>     <http://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 <http://s.name>,
>     IFNAMSIZ - 1);
>     -       ifr.ifr_name[IFNAMSIZ - 1] = 0;
>     +       snprintf(ifr.ifr_name, IFNAMSIZ, "%s", entry->s.name
>     <http://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 <http://s.name>,
>     IFNAMSIZ - 1);
>     -       ifr.ifr_name[IFNAMSIZ - 1] = 0;
>     +       snprintf(ifr.ifr_name, IFNAMSIZ, "%s", entry->s.name
>     <http://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
>     lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org>
>     http://lists.linaro.org/mailman/listinfo/lng-odp
>
>
>
>
> -- 
> *Mike Holmes*
> Linaro  Sr Technical Manager
> LNG - ODP
diff mbox

Patch

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)");