The regexes for verifying SDN (controller)? IDs have implicit `length >=
2` constraints resulting in less-than-ideal error messages in case of
length mismatch.

Add explicit length checks before checking the regexes.

Signed-off-by: Arthur Bied-Charreton <[email protected]>
---
 pve-api-types/src/types/verifiers.rs | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/pve-api-types/src/types/verifiers.rs 
b/pve-api-types/src/types/verifiers.rs
index c45063b5..f731f13b 100644
--- a/pve-api-types/src/types/verifiers.rs
+++ b/pve-api-types/src/types/verifiers.rs
@@ -266,7 +266,11 @@ pub fn verify_vlan_id_or_range(s: &str) -> Result<(), 
Error> {
 
 pub fn verify_sdn_id(s: &str) -> Result<(), Error> {
     if s.len() > 8 {
-        bail!("SDN ID cannot be longer than 8 characters")
+        bail!("SDN ID cannot be longer than 8 characters");
+    }
+
+    if s.len() < 2 {
+        bail!("SDN ID cannot be shorter than 2 characters");
     }
 
     if !SDN_ID.is_match(s) {
@@ -278,7 +282,11 @@ pub fn verify_sdn_id(s: &str) -> Result<(), Error> {
 
 pub fn verify_sdn_controller_id(s: &str) -> Result<(), Error> {
     if s.len() > 64 {
-        bail!("SDN controller ID cannot be longer than 64 characters")
+        bail!("SDN controller ID cannot be longer than 64 characters");
+    }
+
+    if s.len() < 2 {
+        bail!("SDN controller ID cannot be shorter than 2 characters");
     }
 
     if !SDN_CONTROLLER_ID.is_match(s) {
-- 
2.47.3



Reply via email to