Increase the valid name of the iface to IFNAMSIZ
Define MAX_IFACE_LENGTH as IFNAMSIZ instead of 10, to
prevent netd from treating an interface name 'rmnet_sdio0'
as invalid.
Also fix an off-by-one error.
Change-Id: If6b2b27d2da6eb72f01c090cbe4f7dc2b9c296ae
diff --git a/SecondaryTableController.cpp b/SecondaryTableController.cpp
index 5939924..b2c5031 100644
--- a/SecondaryTableController.cpp
+++ b/SecondaryTableController.cpp
@@ -52,7 +52,7 @@
int SecondaryTableController::findTableNumber(const char *iface) {
int i;
for (i = 0; i < INTERFACES_TRACKED; i++) {
- if (strncmp(iface, mInterfaceTable[i], MAX_IFACE_LENGTH) == 0) {
+ if (strncmp(iface, mInterfaceTable[i], IFNAMSIZ) == 0) {
return i;
}
}
@@ -70,7 +70,9 @@
cli->sendMsg(ResponseCode::OperationFailed, "Max number NATed", true);
return -1;
}
- strncpy(mInterfaceTable[tableIndex], iface, MAX_IFACE_LENGTH);
+ strncpy(mInterfaceTable[tableIndex], iface, IFNAMSIZ);
+ // Ensure null termination even if truncation happened
+ mInterfaceTable[tableIndex][IFNAMSIZ] = 0;
}
return modifyRoute(cli, ADD, iface, dest, prefix, gateway, tableIndex);