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

Alex Hung alex.hung at canonical.com
Tue May 6 08:30:45 UTC 2014


On 05/01/2014 10:01 PM, Colin King wrote:
> From: Colin Ian King <colin.king at 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 at 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 at canonical.com>



More information about the fwts-devel mailing list