wireless/wapi: Fix warning: 'strncpy' specified bound 16 equals destination size

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-03-22 02:31:19 +08:00 committed by Petro Karashchenko
parent c88dd4bbaf
commit 2fc7c67031
3 changed files with 29 additions and 29 deletions

View File

@ -99,7 +99,7 @@ int wpa_driver_wext_get_key_ext(int sockfd, FAR const char *ifname,
}
memset(&iwr, 0, sizeof(iwr));
strncpy(iwr.ifr_name, ifname, IFNAMSIZ);
strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
iwr.u.encoding.pointer = (caddr_t) ext;
iwr.u.encoding.length = sizeof(*ext) + *req_len;
@ -171,7 +171,7 @@ int wpa_driver_wext_set_key_ext(int sockfd, FAR const char *ifname,
}
memset(&iwr, 0, sizeof(iwr));
strncpy(iwr.ifr_name, ifname, IFNAMSIZ);
strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
iwr.u.encoding.pointer = (caddr_t) ext;
iwr.u.encoding.length = sizeof(*ext) + key_len;
@ -253,7 +253,7 @@ int wpa_driver_wext_associate(FAR struct wpa_wconfig_s *wconfig)
/* Put the driver name into the request */
strncpy(req.ifr_name, wconfig->ifname, IFNAMSIZ);
strlcpy(req.ifr_name, wconfig->ifname, IFNAMSIZ);
ret = wapi_set_mode(sockfd, wconfig->ifname, wconfig->sta_mode);
if (ret < 0)
@ -354,7 +354,7 @@ static int wpa_driver_wext_process_auth_param(int sockfd,
DEBUGASSERT(ifname != NULL);
memset(&iwr, 0, sizeof(iwr));
strncpy(iwr.ifr_name, ifname, IFNAMSIZ);
strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
iwr.u.param.flags = idx & IW_AUTH_INDEX;
iwr.u.param.value = set ? *value : 0;
@ -443,7 +443,7 @@ void wpa_driver_wext_disconnect(int sockfd, FAR const char *ifname)
*/
memset(&iwr, 0, sizeof(iwr));
strncpy(iwr.ifr_name, ifname, IFNAMSIZ);
strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
if (ioctl(sockfd, SIOCGIWMODE, (unsigned long)&iwr) < 0)
{

View File

@ -64,7 +64,7 @@ static int wapi_get_addr(int sock, FAR const char *ifname, int cmd,
WAPI_VALIDATE_PTR(addr);
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
if ((ret = ioctl(sock, cmd, (unsigned long)((uintptr_t)&ifr))) >= 0)
{
struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_addr;
@ -92,7 +92,7 @@ static int wapi_set_addr(int sock, FAR const char *ifname, int cmd,
sin.sin_family = AF_INET;
memcpy(&sin.sin_addr, addr, sizeof(struct in_addr));
memcpy(&ifr.ifr_addr, &sin, sizeof(struct sockaddr_in));
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
if ((ret = ioctl(sock, cmd, (unsigned long)((uintptr_t)&ifr))) < 0)
{
int errcode = errno;
@ -177,7 +177,7 @@ int wapi_get_ifup(int sock, FAR const char *ifname, FAR int *is_up)
WAPI_VALIDATE_PTR(is_up);
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIFFLAGS, (unsigned long)((uintptr_t)&ifr));
if (ret >= 0)
{
@ -206,7 +206,7 @@ int wapi_set_ifup(int sock, FAR const char *ifname)
struct ifreq ifr;
int ret;
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIFFLAGS, (unsigned long)((uintptr_t)&ifr));
if (ret >= 0)
{
@ -242,7 +242,7 @@ int wapi_set_ifdown(int sock, FAR const char *ifname)
struct ifreq ifr;
int ret;
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIFFLAGS, (unsigned long)((uintptr_t)&ifr));
if (ret >= 0)
{

View File

@ -476,7 +476,7 @@ int wapi_get_freq(int sock, FAR const char *ifname, FAR double *freq,
WAPI_VALIDATE_PTR(freq);
WAPI_VALIDATE_PTR(flag);
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIWFREQ, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
{
@ -544,7 +544,7 @@ int wapi_set_freq(int sock, FAR const char *ifname, double freq,
break;
}
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCSIWFREQ, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
{
@ -588,7 +588,7 @@ int wapi_freq2chan(int sock, FAR const char *ifname, double freq,
/* Get range. */
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIWRANGE, (unsigned long)((uintptr_t)&wrq));
if (ret >= 0)
{
@ -654,7 +654,7 @@ int wapi_chan2freq(int sock, FAR const char *ifname, int chan,
/* Get range. */
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIWRANGE, (unsigned long)((uintptr_t)&wrq));
if (ret >= 0)
{
@ -712,7 +712,7 @@ int wapi_get_essid(int sock, FAR const char *ifname, FAR char *essid,
wrq.u.essid.length = WAPI_ESSID_MAX_SIZE + 1;
wrq.u.essid.flags = 0;
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIWESSID, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
{
@ -755,7 +755,7 @@ int wapi_set_essid(int sock, FAR const char *ifname, FAR const char *essid,
snprintf(buf, ((WAPI_ESSID_MAX_SIZE + 1) * sizeof(char)), "%s", essid);
wrq.u.essid.flags = flag;
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCSIWESSID, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
{
@ -786,7 +786,7 @@ int wapi_get_mode(int sock, FAR const char *ifname,
WAPI_VALIDATE_PTR(mode);
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIWMODE, (unsigned long)((uintptr_t)&wrq));
if (ret >= 0)
{
@ -820,7 +820,7 @@ int wapi_set_mode(int sock, FAR const char *ifname, enum wapi_mode_e mode)
wrq.u.mode = mode;
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCSIWMODE, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
{
@ -880,7 +880,7 @@ int wapi_get_ap(int sock, FAR const char *ifname, FAR struct ether_addr *ap)
WAPI_VALIDATE_PTR(ap);
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIWAP, (unsigned long)((uintptr_t)&wrq));
if (ret >= 0)
{
@ -917,7 +917,7 @@ int wapi_set_ap(int sock, FAR const char *ifname,
wrq.u.ap_addr.sa_family = ARPHRD_ETHER;
memcpy(wrq.u.ap_addr.sa_data, ap, sizeof(struct ether_addr));
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCSIWAP, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
@ -950,7 +950,7 @@ int wapi_get_bitrate(int sock, FAR const char *ifname,
WAPI_VALIDATE_PTR(bitrate);
WAPI_VALIDATE_PTR(flag);
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIWRATE, (unsigned long)((uintptr_t)&wrq));
if (ret >= 0)
{
@ -997,7 +997,7 @@ int wapi_set_bitrate(int sock, FAR const char *ifname, int bitrate,
wrq.u.bitrate.value = bitrate;
wrq.u.bitrate.fixed = (flag == WAPI_BITRATE_FIXED);
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCSIWRATE, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
{
@ -1055,7 +1055,7 @@ int wapi_get_txpower(int sock, FAR const char *ifname, FAR int *power,
WAPI_VALIDATE_PTR(power);
WAPI_VALIDATE_PTR(flag);
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIWTXPOW, (unsigned long)((uintptr_t)&wrq));
if (ret >= 0)
{
@ -1138,7 +1138,7 @@ int wapi_set_txpower(int sock, FAR const char *ifname, int power,
/* Issue the set command. */
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCSIWTXPOW, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
{
@ -1193,7 +1193,7 @@ int wapi_scan_channel_init(int sock, FAR const char *ifname,
}
}
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCSIWSCAN, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
{
@ -1241,7 +1241,7 @@ int wapi_scan_stat(int sock, FAR const char *ifname)
wrq.u.data.pointer = &buf;
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIWSCAN, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
{
@ -1309,7 +1309,7 @@ alloc:
wrq.u.data.pointer = buf;
wrq.u.data.length = buflen;
wrq.u.data.flags = 0;
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIWSCAN, (unsigned long)((uintptr_t)&wrq));
if (ret < 0 && errno == E2BIG)
@ -1428,7 +1428,7 @@ int wapi_set_country(int sock, FAR const char *ifname,
wrq.u.data.pointer = (FAR void *)country;
wrq.u.data.length = 2;
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCSIWCOUNTRY, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
{
@ -1456,7 +1456,7 @@ int wapi_get_sensitivity(int sock, FAR const char *ifname, FAR int *sense)
int ret;
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIWSENS, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
{