Use a GString to store the formatted authentication information. (This
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 24 May 2003 22:58:50 +0000 (22:58 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 24 May 2003 22:58:50 +0000 (22:58 +0000)
also fixes a bug where we were putting a null terminator past the end of
an on-the-stack string buffer.)

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@7735 f5534014-38df-0310-8fa8-9805f1628bb7

packet-isis-clv.c

index ded0558ddc848995efeca11515f4643eab8dafa5..b065a9d725711f7c9eae45715074b7bc6e75dc30 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-isis-clv.c
  * Common CLV decode routines.
  *
- * $Id: packet-isis-clv.c,v 1.26 2003/05/24 19:51:48 gerald Exp $
+ * $Id: packet-isis-clv.c,v 1.27 2003/05/24 22:58:50 guy Exp $
  * Stuart Stanley <stuarts@mxmail.net>
  *
  * Ethereal - Network traffic analyzer
@@ -145,15 +145,13 @@ isis_dissect_area_address_clv(tvbuff_t *tvb, proto_tree *tree, int offset,
  * Output:
  *     void, but we will add to proto tree if !NULL.
  */
-#define SBUF_LEN 300           /* 255 + header info area */
 void
 isis_dissect_authentication_clv(tvbuff_t *tvb, proto_tree *tree, int offset,
        int length, char *meaning)
 {
        guchar pw_type;
-       char sbuf[SBUF_LEN];
-       char *s = sbuf;
-       int auth_unsupported, ret;
+       int auth_unsupported;
+       GString *gstr;
 
        if ( length <= 0 ) {
                return;
@@ -164,43 +162,56 @@ isis_dissect_authentication_clv(tvbuff_t *tvb, proto_tree *tree, int offset,
        length--;
        auth_unsupported = FALSE;
 
+       gstr = g_string_new("");
+
+       /*
+        * Free the GString if we throw an exception.
+        */
+       CLEANUP_PUSH(free_g_string, gstr);
+
        switch (pw_type) {
        case 1:
-               ret = sprintf ( s, "clear text (1), password (length %d) = ", length );
-               s += ret;
-
+               g_string_sprintfa(gstr,
+                   "clear text (1), password (length %d) = ", length);
                if ( length > 0 ) {
-                 strncpy(s, tvb_get_ptr(tvb, offset, length), MIN(length, SBUF_LEN - ret));
+                 g_string_sprintfa(gstr, "%s",
+                   tvb_format_text(tvb, offset, length));
                 } else {
-                 strcat(s, "no clear-text password found!!!" );
+                 g_string_sprintfa(gstr, "no clear-text password found!!!");
                }
                break;
        case 54:
-               s += sprintf ( s, "hmac-md5 (54), password (length %d) = ", length );
+               g_string_sprintfa(gstr,
+                   "hmac-md5 (54), password (length %d) = ", length);
 
-                if ( length == 16 ) {
-                 s += sprintf ( s, "0x%02x", tvb_get_guint8(tvb, offset) );
+               if ( length == 16 ) {
+                 g_string_sprintfa(gstr, "0x%02x", tvb_get_guint8(tvb, offset));
                  offset += 1;
                  length--;
                  while (length > 0) {
-                   s += sprintf ( s, "%02x", tvb_get_guint8(tvb, offset) );
+                   g_string_sprintfa(gstr, "%02x", tvb_get_guint8(tvb, offset));
                    offset += 1;
                    length--;
-                   }
-                    s = 0;
-                } else {
-                  strcat(s, "illegal hmac-md5 digest format (must be 16 bytes)" );
+                 }
+               } else {
+                 g_string_sprintfa(gstr,
+                     "illegal hmac-md5 digest format (must be 16 bytes)");
                }
                break;
        default:
-               sprintf (sbuf, "type 0x%02x (0x%02x): ", pw_type, length );
+               g_string_sprintfa(gstr, "type 0x%02x (0x%02x): ", pw_type, length );
                auth_unsupported=TRUE;
                break;
        }
 
-       sbuf[SBUF_LEN] = '\0';
        proto_tree_add_text ( tree, tvb, offset - 1, length + 1,
-                       "%s %s", meaning, sbuf );
+                       "%s %s", meaning, gstr->str );
+
+       /*
+        * We're done with the GString, so delete it and get rid of
+        * the cleanup handler.
+        */
+       CLEANUP_CALL_AND_POP;
 
                if ( auth_unsupported ) {
                isis_dissect_unknown(tvb, tree, offset,