network/stack: assume zero length ioctl requests are valid
posix ioctl calls don't provide a request length. Theorically these length checks could be removed altogether. Change-Id: Ie53f10dc8d050dd3bdf2e5a792ed79f139a24d29 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3364 Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
@@ -134,7 +134,7 @@ get_interface_name_or_index(net_domain* domain, int32 option, void* value,
|
|||||||
ASSERT(option == SIOCGIFINDEX || option == SIOCGIFNAME);
|
ASSERT(option == SIOCGIFINDEX || option == SIOCGIFNAME);
|
||||||
|
|
||||||
size_t expected = option == SIOCGIFINDEX ? IF_NAMESIZE : sizeof(ifreq);
|
size_t expected = option == SIOCGIFINDEX ? IF_NAMESIZE : sizeof(ifreq);
|
||||||
if (*_length < expected)
|
if (*_length > 0 && *_length < expected)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
ifreq request;
|
ifreq request;
|
||||||
@@ -215,7 +215,7 @@ datalink_control(net_domain* _domain, int32 option, void* value,
|
|||||||
case SIOCAIFADDR: /* same as B_SOCKET_ADD_ALIAS */
|
case SIOCAIFADDR: /* same as B_SOCKET_ADD_ALIAS */
|
||||||
{
|
{
|
||||||
// add new interface address
|
// add new interface address
|
||||||
if (*_length < sizeof(struct ifaliasreq))
|
if (*_length > 0 && *_length < sizeof(struct ifaliasreq))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
struct ifaliasreq request;
|
struct ifaliasreq request;
|
||||||
@@ -320,10 +320,9 @@ datalink_control(net_domain* _domain, int32 option, void* value,
|
|||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
// We also accept partial ifreqs as long as the name is complete.
|
// We also accept partial ifreqs as long as the name is complete.
|
||||||
if (*_length < IF_NAMESIZE)
|
size_t length = sizeof(struct ifreq);
|
||||||
return B_BAD_VALUE;
|
if (*_length > 0 && *_length >= IF_NAMESIZE)
|
||||||
|
length = min_c(length, *_length);
|
||||||
size_t length = min_c(sizeof(struct ifreq), *_length);
|
|
||||||
|
|
||||||
// try to pass the request to an existing interface
|
// try to pass the request to an existing interface
|
||||||
struct ifreq request;
|
struct ifreq request;
|
||||||
@@ -754,7 +753,9 @@ interface_protocol_control(net_datalink_protocol* _protocol, int32 option,
|
|||||||
case SIOCGIFBRDADDR:
|
case SIOCGIFBRDADDR:
|
||||||
case SIOCGIFDSTADDR:
|
case SIOCGIFDSTADDR:
|
||||||
{
|
{
|
||||||
if (length < sizeof(ifreq))
|
if (length == 0)
|
||||||
|
length = sizeof(ifreq);
|
||||||
|
else if (length < sizeof(ifreq))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
ifreq request;
|
ifreq request;
|
||||||
@@ -920,7 +921,7 @@ interface_protocol_control(net_datalink_protocol* _protocol, int32 option,
|
|||||||
case SIOCGIFMEDIA:
|
case SIOCGIFMEDIA:
|
||||||
{
|
{
|
||||||
// get media
|
// get media
|
||||||
if (length < sizeof(ifmediareq))
|
if (length > 0 && length < sizeof(ifmediareq))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
struct ifmediareq request;
|
struct ifmediareq request;
|
||||||
|
|||||||
@@ -455,7 +455,7 @@ link_control(net_protocol* _protocol, int level, int option, void* value,
|
|||||||
case SIOCGIFMEDIA:
|
case SIOCGIFMEDIA:
|
||||||
{
|
{
|
||||||
// get media
|
// get media
|
||||||
if (*_length < sizeof(ifmediareq))
|
if (*_length > 0 && *_length < sizeof(ifmediareq))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
net_device_interface* interface;
|
net_device_interface* interface;
|
||||||
|
|||||||
Reference in New Issue
Block a user