diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index ada1f4bb920b..52a35c7a3949 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -2172,7 +2172,12 @@ bool PortsOrch::createVlanHostIntf(Port& vl, string hostif_name) attrs.push_back(attr); attr.id = SAI_HOSTIF_ATTR_NAME; - strncpy(attr.value.chardata, hostif_name.c_str(), sizeof(attr.value.chardata)); + if (hostif_name.length() >= SAI_HOSTIF_NAME_SIZE) + { + SWSS_LOG_WARN("Host interface name %s is too long and will be truncated to %d bytes", hostif_name.c_str(), SAI_HOSTIF_NAME_SIZE - 1); + } + strncpy(attr.value.chardata, hostif_name.c_str(), SAI_HOSTIF_NAME_SIZE); + attr.value.chardata[SAI_HOSTIF_NAME_SIZE - 1] = '\0'; attrs.push_back(attr); sai_status_t status = sai_hostif_api->create_hostif(&vl.m_vlan_info.host_intf_id, gSwitchId, (uint32_t)attrs.size(), attrs.data()); @@ -4186,6 +4191,11 @@ bool PortsOrch::addHostIntfs(Port &port, string alias, sai_object_id_t &host_int attr.id = SAI_HOSTIF_ATTR_NAME; strncpy((char *)&attr.value.chardata, alias.c_str(), SAI_HOSTIF_NAME_SIZE); + if (alias.length() >= SAI_HOSTIF_NAME_SIZE) + { + SWSS_LOG_WARN("Host interface name %s is too long and will be truncated to %d bytes", alias.c_str(), SAI_HOSTIF_NAME_SIZE - 1); + } + attr.value.chardata[SAI_HOSTIF_NAME_SIZE - 1] = '\0'; attrs.push_back(attr); sai_status_t status = sai_hostif_api->create_hostif(&host_intfs_id, gSwitchId, (uint32_t)attrs.size(), attrs.data());