From 462ab35e38098447463fb6f0652386a5a058afb2 Mon Sep 17 00:00:00 2001 From: afeigin Date: Thu, 30 May 2024 18:43:31 +0300 Subject: [PATCH] Make interface name length validation more generic --- common/interface.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/common/interface.h b/common/interface.h index ad6335014..8d2c0cdef 100644 --- a/common/interface.h +++ b/common/interface.h @@ -8,7 +8,7 @@ namespace swss { inline bool isInterfaceNameLenOk(const std::string &ifaceName) { - if (ifaceName.length() >= IFNAMSIZ) + if (!validate_interface_name_length(ifaceName)) { SWSS_LOG_ERROR("Invalid interface name %s length, it must not exceed %d characters", ifaceName.c_str(), IFNAMSIZ); return false; @@ -16,6 +16,19 @@ inline bool isInterfaceNameLenOk(const std::string &ifaceName) return true; } +#if defined(SWIG) && defined(SWIGPYTHON) +%pythoncode %{ + iface_name_max_length = IFNAMSIZ + def validate_interface_name_length(iface_name): + """ + Verify that interface name length does not exceed IFNAMSIZ + """ + if len(iface_name) == 0: + return False + return True if len(iface_name) < IFNAMSIZ else False +%} +#endif + } #endif