Limit variable fields to 255 characters. user/dyrcona/add_field-conformance
authorJason Stephenson <jstephenson@mvlc.org>
Tue, 23 Oct 2012 14:36:48 +0000 (10:36 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Tue, 23 Oct 2012 14:36:48 +0000 (10:36 -0400)
The SIP2 protocol document specifies that variable fields are to be from
0 to 255 characters in length, not counting the field identifier or the
delimiter.

This branch adds some defensive coding to Sip::add_field to truncate any
field values that are longer than 255 characters to 255 characters before
adding them to the response.

Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Sip.pm

diff --git a/Sip.pm b/Sip.pm
index 9dea1c1..a687cd7 100644 (file)
--- a/Sip.pm
+++ b/Sip.pm
@@ -90,6 +90,13 @@ sub add_field {
        substr($value, $i, 1) = $ent;
     }
 
+    # SIP2 Protocol document specifies that variable fields are from 0
+    # to 255 characters in length.  We'll do a check of the field
+    # length and truncate if necessary.
+    if (length($value) > 255) {
+        $value = substr($value, 0, 255);
+    }
+
     return $field_id . $value . $field_delimiter;
 }
 #