Ignore RtNetlinkMessage with null or empty interface names
This patch checks if interface name is null or empty for RtNetlinkMessage and ignores the message if it is. Bug: 429497348 Test: build Flag: EXEMPT bugfix Change-Id: I6000f5442f341f152b7fbd235affded0fa56fe50
This commit is contained in:
parent
29ae4e7b43
commit
16c8fd1166
2 changed files with 28 additions and 1 deletions
|
|
@ -26,6 +26,7 @@ import static com.android.net.module.util.netlink.StructNlMsgHdr.NLM_F_REQUEST_A
|
|||
|
||||
import android.net.MacAddress;
|
||||
import android.system.OsConstants;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
|
@ -122,7 +123,7 @@ public class RtNetlinkLinkMessage extends NetlinkMessage {
|
|||
return mHardwareAddress;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
public String getInterfaceName() {
|
||||
return mInterfaceName;
|
||||
}
|
||||
|
|
@ -165,6 +166,10 @@ public class RtNetlinkLinkMessage extends NetlinkMessage {
|
|||
if (nlAttr != null) {
|
||||
interfaceName = nlAttr.getValueAsString();
|
||||
}
|
||||
// Theoretically this should not happen, added a check just for safety.
|
||||
if (TextUtils.isEmpty(interfaceName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new RtNetlinkLinkMessage(header, ifinfoMsg, mtu, hardwareAddress, interfaceName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -336,4 +336,26 @@ public class RtNetlinkLinkMessageTest {
|
|||
+ "}";
|
||||
assertEquals(expected, linkMsg.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseRtNetlinkMessageWithNullInterfaceName() {
|
||||
// Invalid NetlinkMessage bytes without IFLA_IFNAME attribute.
|
||||
final String msgBytes = "34000000100000000000000000000000000001001E0000000210000000000000"
|
||||
+ "08000400DC0500000A00010092C3E3C9374E0000";
|
||||
final ByteBuffer byteBuffer = toByteBuffer(msgBytes);
|
||||
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing.
|
||||
final NetlinkMessage msg = NetlinkMessage.parse(byteBuffer, NETLINK_ROUTE);
|
||||
assertNull(msg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseRtNetlinkMessageWithEmptyInterfaceName() {
|
||||
// Invalid NetlinkMessage bytes with empty IFLA_IFNAME attribute.
|
||||
final String msgBytes = "3C000000100000000000000000000000000001001E0000000210000000000000"
|
||||
+ "08000400DC0500000A00010092C3E3C9374E00000500030000000000";
|
||||
final ByteBuffer byteBuffer = toByteBuffer(msgBytes);
|
||||
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing.
|
||||
final NetlinkMessage msg = NetlinkMessage.parse(byteBuffer, NETLINK_ROUTE);
|
||||
assertNull(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue