diff mbox

[10/10] lib: fwts_hwinfo: ensure buf.ifr_name is null terminated

Message ID 1398952881-27828-11-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King May 1, 2014, 2:01 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

don't strncpy the entire buffer size as this leaves no space for
string terminator.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_hwinfo.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Ivan Hu May 6, 2014, 3:48 a.m. UTC | #1
On 05/01/2014 10:01 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> don't strncpy the entire buffer size as this leaves no space for
> string terminator.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_hwinfo.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/lib/src/fwts_hwinfo.c b/src/lib/src/fwts_hwinfo.c
> index 3138485..6f0e5bf 100644
> --- a/src/lib/src/fwts_hwinfo.c
> +++ b/src/lib/src/fwts_hwinfo.c
> @@ -380,7 +380,7 @@ static int fwts_hwinfo_net_get(
>   	}
>
>   	while ((d = readdir(dp)) != NULL) {
> -		struct	ifreq buf;
> +		struct ifreq buf;
>   		struct in_addr in_addr;
>   		fwts_net_config *net_config;
>
> @@ -397,7 +397,7 @@ static int fwts_hwinfo_net_get(
>   			break;
>   		}
>   		memset(&buf, 0, sizeof(buf));
> -		strncpy(buf.ifr_name, d->d_name, sizeof(buf.ifr_name));
> +		strncpy(buf.ifr_name, d->d_name, sizeof(buf.ifr_name) - 1);
>   		if (ioctl(sock, SIOCGIFHWADDR, &buf) < 0) {
>   			fwts_log_error(fw, "Cannot get network information for device %s.", d->d_name);
>   			fwts_hwinfo_net_free(net_config);
> @@ -410,7 +410,7 @@ static int fwts_hwinfo_net_get(
>   			break;
>   		}
>   		memset(&buf, 0, sizeof(buf));
> -		strncpy(buf.ifr_name, d->d_name, sizeof(buf.ifr_name));
> +		strncpy(buf.ifr_name, d->d_name, sizeof(buf.ifr_name) - 1);
>   		if (ioctl(sock, SIOCGIFADDR, &buf) < 0) {
>   			if (errno != EADDRNOTAVAIL)
>   				fwts_log_error(fw, "Cannot get address for device %s.", d->d_name);
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>
Alex Hung May 6, 2014, 8:30 a.m. UTC | #2
On 05/01/2014 10:01 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> don't strncpy the entire buffer size as this leaves no space for
> string terminator.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_hwinfo.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/lib/src/fwts_hwinfo.c b/src/lib/src/fwts_hwinfo.c
> index 3138485..6f0e5bf 100644
> --- a/src/lib/src/fwts_hwinfo.c
> +++ b/src/lib/src/fwts_hwinfo.c
> @@ -380,7 +380,7 @@ static int fwts_hwinfo_net_get(
>   	}
>
>   	while ((d = readdir(dp)) != NULL) {
> -		struct	ifreq buf;
> +		struct ifreq buf;
>   		struct in_addr in_addr;
>   		fwts_net_config *net_config;
>
> @@ -397,7 +397,7 @@ static int fwts_hwinfo_net_get(
>   			break;
>   		}
>   		memset(&buf, 0, sizeof(buf));
> -		strncpy(buf.ifr_name, d->d_name, sizeof(buf.ifr_name));
> +		strncpy(buf.ifr_name, d->d_name, sizeof(buf.ifr_name) - 1);
>   		if (ioctl(sock, SIOCGIFHWADDR, &buf) < 0) {
>   			fwts_log_error(fw, "Cannot get network information for device %s.", d->d_name);
>   			fwts_hwinfo_net_free(net_config);
> @@ -410,7 +410,7 @@ static int fwts_hwinfo_net_get(
>   			break;
>   		}
>   		memset(&buf, 0, sizeof(buf));
> -		strncpy(buf.ifr_name, d->d_name, sizeof(buf.ifr_name));
> +		strncpy(buf.ifr_name, d->d_name, sizeof(buf.ifr_name) - 1);
>   		if (ioctl(sock, SIOCGIFADDR, &buf) < 0) {
>   			if (errno != EADDRNOTAVAIL)
>   				fwts_log_error(fw, "Cannot get address for device %s.", d->d_name);
>

Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox

Patch

diff --git a/src/lib/src/fwts_hwinfo.c b/src/lib/src/fwts_hwinfo.c
index 3138485..6f0e5bf 100644
--- a/src/lib/src/fwts_hwinfo.c
+++ b/src/lib/src/fwts_hwinfo.c
@@ -380,7 +380,7 @@  static int fwts_hwinfo_net_get(
 	}
 
 	while ((d = readdir(dp)) != NULL) {
-		struct	ifreq buf;
+		struct ifreq buf;
 		struct in_addr in_addr;
 		fwts_net_config *net_config;
 
@@ -397,7 +397,7 @@  static int fwts_hwinfo_net_get(
 			break;
 		}
 		memset(&buf, 0, sizeof(buf));
-		strncpy(buf.ifr_name, d->d_name, sizeof(buf.ifr_name));
+		strncpy(buf.ifr_name, d->d_name, sizeof(buf.ifr_name) - 1);
 		if (ioctl(sock, SIOCGIFHWADDR, &buf) < 0) {
 			fwts_log_error(fw, "Cannot get network information for device %s.", d->d_name);
 			fwts_hwinfo_net_free(net_config);
@@ -410,7 +410,7 @@  static int fwts_hwinfo_net_get(
 			break;
 		}
 		memset(&buf, 0, sizeof(buf));
-		strncpy(buf.ifr_name, d->d_name, sizeof(buf.ifr_name));
+		strncpy(buf.ifr_name, d->d_name, sizeof(buf.ifr_name) - 1);
 		if (ioctl(sock, SIOCGIFADDR, &buf) < 0) {
 			if (errno != EADDRNOTAVAIL)
 				fwts_log_error(fw, "Cannot get address for device %s.", d->d_name);