diff mbox

odp_packet_socket.c: Fix unterminated string

Message ID 1413575257-40398-1-git-send-email-mike.holmes@linaro.org
State Accepted
Commit ee2ee879247668fcc8bb715f3513ed708d74751d
Headers show

Commit Message

Mike Holmes Oct. 17, 2014, 7:47 p.m. UTC
Termination of the string is not assured unless the string is
one char shorter than the buffer.

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

Comments

Maxim Uvarov Oct. 21, 2014, 12:08 p.m. UTC | #1
merged!
Maxim.

On 10/17/2014 11:47 PM, Mike Holmes wrote:
> Termination of the string is not assured unless the string is
> one char shorter than the buffer.
>
> Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
> ---
>   platform/linux-generic/odp_packet_socket.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/platform/linux-generic/odp_packet_socket.c b/platform/linux-generic/odp_packet_socket.c
> index 006d7bd..da9b5a0 100644
> --- a/platform/linux-generic/odp_packet_socket.c
> +++ b/platform/linux-generic/odp_packet_socket.c
> @@ -219,7 +219,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);
> +	strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
>   	err = ioctl(sockfd, SIOCGIFINDEX, &ethreq);
>   	if (err != 0) {
>   		perror("setup_pkt_sock() - ioctl(SIOCGIFINDEX)");
diff mbox

Patch

diff --git a/platform/linux-generic/odp_packet_socket.c b/platform/linux-generic/odp_packet_socket.c
index 006d7bd..da9b5a0 100644
--- a/platform/linux-generic/odp_packet_socket.c
+++ b/platform/linux-generic/odp_packet_socket.c
@@ -219,7 +219,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);
+	strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
 	err = ioctl(sockfd, SIOCGIFINDEX, &ethreq);
 	if (err != 0) {
 		perror("setup_pkt_sock() - ioctl(SIOCGIFINDEX)");