Message ID | 1398952881-27828-11-git-send-email-colin.king@canonical.com |
---|---|
State | Accepted |
Headers | show |
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>
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 --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);