mirror of
https://github.com/apache/nuttx.git
synced 2026-05-26 02:36:11 +08:00
net/socket: Check on the end of the NIC name when binding device
When using usrsock to pass the network interface name, omitting "\0" will cause the host to parse extra characters. therefore, the tail section should be inspected during device binding. Signed-off-by: zhangshuai39 <zhangshuai39@xiaomi.com>
This commit is contained in:
committed by
Matteo Golin
parent
d5633f75a8
commit
1914dd0820
+20
-4
@@ -203,11 +203,27 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
|
||||
break;
|
||||
}
|
||||
|
||||
/* No, we are binding a socket to the interface
|
||||
* Find the interface device with this name.
|
||||
*/
|
||||
/* Check if the value is already null-terminated */
|
||||
|
||||
if (((FAR char *)value)[value_len - 1] != '\0')
|
||||
{
|
||||
char ifname[IFNAMSIZ];
|
||||
socklen_t len = MIN(IFNAMSIZ - 1, value_len);
|
||||
|
||||
/* Copy the data and add null terminator */
|
||||
|
||||
memcpy(ifname, value, len);
|
||||
ifname[len] = '\0';
|
||||
|
||||
dev = netdev_findbyname(ifname);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Value is already null-terminated, use it directly */
|
||||
|
||||
dev = netdev_findbyname(value);
|
||||
}
|
||||
|
||||
dev = netdev_findbyname(value);
|
||||
if (dev == NULL)
|
||||
{
|
||||
return -ENODEV;
|
||||
|
||||
Reference in New Issue
Block a user