This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 5ce2955e62c net/netdev: correct the ioctl command validation logic
5ce2955e62c is described below
commit 5ce2955e62c1a2cb2770b7c0d9a5836dea2963f1
Author: zhanghongyu <[email protected]>
AuthorDate: Wed Jun 4 21:18:51 2025 +0800
net/netdev: correct the ioctl command validation logic
This patch fixes the validation order in netdev ioctl handlers for
Bluetooth, IEEE 802.15.4, and packet radio devices. The command type
should be validated before checking the argument pointer to return
the correct error code (-ENOTTY vs -EINVAL).
Signed-off-by: zhanghongyu <[email protected]>
---
net/netdev/netdev_ioctl.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c
index 39217a0e9b4..3b7ccb27731 100644
--- a/net/netdev/netdev_ioctl.c
+++ b/net/netdev/netdev_ioctl.c
@@ -394,11 +394,11 @@ static int netdev_bluetooth_ioctl(FAR struct socket
*psock, int cmd,
{
FAR struct net_driver_s *dev;
FAR char *ifname;
- int ret = -EINVAL;
+ int ret = -ENOTTY;
- if (arg != 0ul)
+ if (_BLUETOOTHIOCVALID(cmd))
{
- if (_BLUETOOTHIOCVALID(cmd))
+ if (arg != 0ul)
{
/* Get the name of the Bluetooth device to receive the IOCTL
* command
@@ -411,9 +411,9 @@ static int netdev_bluetooth_ioctl(FAR struct socket *psock,
int cmd,
}
else
{
- /* Not a Bluetooth IOCTL command */
+ /* Argument is invalid */
- return -ENOTTY;
+ return -EINVAL;
}
/* Find the device with this name */
@@ -459,9 +459,9 @@ static int netdev_iee802154_ioctl(FAR struct socket *psock,
int cmd,
FAR char *ifname;
int ret = -ENOTTY;
- if (arg != 0ul)
+ if (_MAC802154IOCVALID(cmd))
{
- if (_MAC802154IOCVALID(cmd))
+ if (arg != 0ul)
{
/* Get the IEEE802.15.4 MAC device to receive the radio IOCTL
* command
@@ -474,9 +474,9 @@ static int netdev_iee802154_ioctl(FAR struct socket *psock,
int cmd,
}
else
{
- /* Not an EEE802.15.4 MAC IOCTL command */
+ /* Argument is invalid */
- return -ENOTTY;
+ return -EINVAL;
}
/* Find the device with this name */
@@ -520,9 +520,9 @@ static int netdev_pktradio_ioctl(FAR struct socket *psock,
int cmd,
FAR char *ifname;
int ret = -ENOTTY;
- if (arg != 0ul)
+ if (_PKRADIOIOCVALID(cmd))
{
- if (_PKRADIOIOCVALID(cmd))
+ if (arg != 0ul)
{
/* Get the packet radio device to receive the radio IOCTL
* command
@@ -535,10 +535,9 @@ static int netdev_pktradio_ioctl(FAR struct socket *psock,
int cmd,
}
else
{
- /* Not a packet radio IOCTL command */
+ /* Argument is invalid */
- nwarn("WARNING: Not a packet radio IOCTL command: %d\n", cmd);
- return -ENOTTY;
+ return -EINVAL;
}
/* Find the device with this name */