@@ -69,7 +69,7 @@ namespace Inet {
69
69
#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
70
70
CHIP_ERROR InterfaceId::GetInterfaceName (char * nameBuf, size_t nameBufSize) const
71
71
{
72
- if (mPlatformInterface && nameBufSize >= kMaxIfNameLength )
72
+ if (mPlatformInterface && nameBufSize >= InterfaceId:: kMaxIfNameLength )
73
73
{
74
74
nameBuf[0 ] = ' o' ;
75
75
nameBuf[1 ] = ' t' ;
@@ -84,7 +84,7 @@ CHIP_ERROR InterfaceId::GetInterfaceName(char * nameBuf, size_t nameBufSize) con
84
84
}
85
85
CHIP_ERROR InterfaceId::InterfaceNameToId (const char * intfName, InterfaceId & interface)
86
86
{
87
- if (strlen (intfName) < 3 )
87
+ if (strnlen (intfName, kMaxIfNameLength ) < 3 )
88
88
{
89
89
return INET_ERROR_UNKNOWN_INTERFACE;
90
90
}
@@ -210,7 +210,7 @@ CHIP_ERROR InterfaceId::GetInterfaceName(char * nameBuf, size_t nameBufSize) con
210
210
211
211
CHIP_ERROR InterfaceId::InterfaceNameToId (const char * intfName, InterfaceId & interface)
212
212
{
213
- if (strlen (intfName) < 3 )
213
+ if (strnlen (intfName, InterfaceId:: kMaxIfNameLength ) < 3 )
214
214
{
215
215
return INET_ERROR_UNKNOWN_INTERFACE;
216
216
}
@@ -445,7 +445,7 @@ CHIP_ERROR InterfaceId::GetInterfaceName(char * nameBuf, size_t nameBufSize) con
445
445
{
446
446
return CHIP_ERROR_POSIX (errno);
447
447
}
448
- size_t nameLength = strlen (intfName);
448
+ size_t nameLength = strnlen (intfName, IF_NAMESIZE );
449
449
if (nameLength >= nameBufSize)
450
450
{
451
451
return CHIP_ERROR_BUFFER_TOO_SMALL;
@@ -579,7 +579,8 @@ InterfaceId InterfaceIterator::GetInterfaceId()
579
579
CHIP_ERROR InterfaceIterator::GetInterfaceName (char * nameBuf, size_t nameBufSize)
580
580
{
581
581
VerifyOrReturnError (HasCurrent (), CHIP_ERROR_INCORRECT_STATE);
582
- VerifyOrReturnError (strlen (mIntfArray [mCurIntf ].if_name ) < nameBufSize, CHIP_ERROR_BUFFER_TOO_SMALL);
582
+ VerifyOrReturnError (strnlen (mIntfArray [mCurIntf ].if_name , InterfaceId::kMaxIfNameLength ) < nameBufSize,
583
+ CHIP_ERROR_BUFFER_TOO_SMALL);
583
584
Platform::CopyString (nameBuf, nameBufSize, mIntfArray [mCurIntf ].if_name );
584
585
return CHIP_NO_ERROR;
585
586
}
@@ -728,7 +729,7 @@ InterfaceId InterfaceAddressIterator::GetInterfaceId()
728
729
CHIP_ERROR InterfaceAddressIterator::GetInterfaceName (char * nameBuf, size_t nameBufSize)
729
730
{
730
731
VerifyOrReturnError (HasCurrent (), CHIP_ERROR_INCORRECT_STATE);
731
- VerifyOrReturnError (strlen (mCurAddr ->ifa_name ) < nameBufSize, CHIP_ERROR_BUFFER_TOO_SMALL);
732
+ VerifyOrReturnError (strnlen (mCurAddr ->ifa_name , InterfaceId:: kMaxIfNameLength ) < nameBufSize, CHIP_ERROR_BUFFER_TOO_SMALL);
732
733
Platform::CopyString (nameBuf, nameBufSize, mCurAddr ->ifa_name );
733
734
return CHIP_NO_ERROR;
734
735
}
@@ -802,7 +803,7 @@ CHIP_ERROR InterfaceId::GetInterfaceName(char * nameBuf, size_t nameBufSize) con
802
803
return CHIP_ERROR_INCORRECT_STATE;
803
804
}
804
805
const char * name = net_if_get_device (currentInterface)->name ;
805
- size_t nameLength = strlen (name);
806
+ size_t nameLength = strnlen (name, InterfaceId:: kMaxIfNameLength );
806
807
if (nameLength >= nameBufSize)
807
808
{
808
809
return CHIP_ERROR_BUFFER_TOO_SMALL;
@@ -825,7 +826,7 @@ CHIP_ERROR InterfaceId::InterfaceNameToId(const char * intfName, InterfaceId & i
825
826
826
827
while ((currentInterface = net_if_get_by_index (++currentId)) != nullptr )
827
828
{
828
- if (strcmp (net_if_get_device (currentInterface)->name , intfName) == 0 )
829
+ if (strncmp (net_if_get_device (currentInterface)->name , intfName, InterfaceId:: kMaxIfNameLength ) == 0 )
829
830
{
830
831
interface = InterfaceId (currentId);
831
832
return CHIP_NO_ERROR;
0 commit comments