diff mbox

odp_packet_socket.c: Replace strncpy size with size -1 for terminator

Message ID 1412031245-4709-1-git-send-email-mike.holmes@linaro.org
State Accepted
Commit 0e0bcce3b624c3a5afc0cca6b4d02ae940bbe47f
Headers show

Commit Message

Mike Holmes Sept. 29, 2014, 10:54 p.m. UTC
The buffer is not null terminated for ethreq.ifr_name if strncpy is passed
the maxsize of 16 and if netdev is not null terminated within that size.

Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---
 platform/linux-generic/odp_packet_socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Mike Holmes Oct. 2, 2014, 11:35 a.m. UTC | #1
ping - any comments ?

On 29 September 2014 18:54, Mike Holmes <mike.holmes@linaro.org> wrote:

> The buffer is not null terminated for ethreq.ifr_name if strncpy is passed
> the maxsize of 16 and if netdev is not null terminated within that size.
>
> Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
> ---
>  platform/linux-generic/odp_packet_socket.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/platform/linux-generic/odp_packet_socket.c
> b/platform/linux-generic/odp_packet_socket.c
> index 279a0cb..844504a 100644
> --- a/platform/linux-generic/odp_packet_socket.c
> +++ b/platform/linux-generic/odp_packet_socket.c
> @@ -229,7 +229,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);
> +       strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
>         err = ioctl(sockfd, SIOCGIFHWADDR, &ethreq);
>         if (err != 0) {
>                 perror("setup_pkt_sock() - ioctl(SIOCGIFHWADDR)");
> @@ -785,7 +785,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);
> +       strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
>         ret = ioctl(pkt_sock->sockfd, SIOCGIFHWADDR, &ethreq);
>         if (ret != 0) {
>                 perror("store_hw_addr() - ioctl(SIOCGIFHWADDR)");
> --
> 1.9.1
>
>
Maxim Uvarov Oct. 2, 2014, 11:55 a.m. UTC | #2
Merged, thanks!

Maxim.

On 10/02/2014 03:35 PM, Mike Holmes wrote:
> ping - any comments ?
>
> On 29 September 2014 18:54, Mike Holmes <mike.holmes@linaro.org 
> <mailto:mike.holmes@linaro.org>> wrote:
>
>     The buffer is not null terminated for ethreq.ifr_name if strncpy
>     is passed
>     the maxsize of 16 and if netdev is not null terminated within that
>     size.
>
>     Signed-off-by: Mike Holmes <mike.holmes@linaro.org
>     <mailto:mike.holmes@linaro.org>>
>     ---
>      platform/linux-generic/odp_packet_socket.c | 4 ++--
>      1 file changed, 2 insertions(+), 2 deletions(-)
>
>     diff --git a/platform/linux-generic/odp_packet_socket.c
>     b/platform/linux-generic/odp_packet_socket.c
>     index 279a0cb..844504a 100644
>     --- a/platform/linux-generic/odp_packet_socket.c
>     +++ b/platform/linux-generic/odp_packet_socket.c
>     @@ -229,7 +229,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);
>     +       strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
>             err = ioctl(sockfd, SIOCGIFHWADDR, &ethreq);
>             if (err != 0) {
>                     perror("setup_pkt_sock() - ioctl(SIOCGIFHWADDR)");
>     @@ -785,7 +785,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);
>     +       strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
>             ret = ioctl(pkt_sock->sockfd, SIOCGIFHWADDR, &ethreq);
>             if (ret != 0) {
>                     perror("store_hw_addr() - ioctl(SIOCGIFHWADDR)");
>     --
>     1.9.1
>
>
>
>
> -- 
> *Mike Holmes*
> Linaro  Sr Technical Manager
> LNG - ODP
>
>
> _______________________________________________
> 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_socket.c b/platform/linux-generic/odp_packet_socket.c
index 279a0cb..844504a 100644
--- a/platform/linux-generic/odp_packet_socket.c
+++ b/platform/linux-generic/odp_packet_socket.c
@@ -229,7 +229,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);
+	strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
 	err = ioctl(sockfd, SIOCGIFHWADDR, &ethreq);
 	if (err != 0) {
 		perror("setup_pkt_sock() - ioctl(SIOCGIFHWADDR)");
@@ -785,7 +785,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);
+	strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
 	ret = ioctl(pkt_sock->sockfd, SIOCGIFHWADDR, &ethreq);
 	if (ret != 0) {
 		perror("store_hw_addr() - ioctl(SIOCGIFHWADDR)");