From Pierre-Marie de Rodat: PostgreSQL Startup message not properly supported by...
authorwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 16 Sep 2011 20:08:46 +0000 (20:08 +0000)
committerwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 16 Sep 2011 20:08:46 +0000 (20:08 +0000)
"The PostgreSQL dissector do not fully support the frontend StartupMessage (see
"StartupMessage" in
http://developer.postgresql.org/pgdocs/postgres/protocol-message-formats.html).
The couples parameter name/parameter value in this kind of message are reported
as a block of text ("name: value") by the dissector whereas reporting them as
parameter name/parameter value would be more appropriate.

I've fixed it, so now the username and the database sent by the frontend can be
handled in, for instance, the CSV output of TShark.

I've also added a "val_count" field to contain the number of values (row
descriptions or row data) included in RowDescription/DataRow messages. This
information is useful when analyzing the CSV of TShark since in a CSV row, many
row descriptions or row data may be packed together."

Patch changes from me:
- No need to fetch ephemeral string anymore so just use tvb_strsize()
  to get string length;
- Change field-filtername from pgsql.val.count to pgsql.field.count

See: https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6343

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

epan/dissectors/packet-pgsql.c

index 5be51438a59911fbe01ceef74e6670a68d0f78db..814f58af39d1b054ad0eacfc0c398cae72d045f4 100644 (file)
@@ -60,6 +60,7 @@ static int hf_tableoid = -1;
 static int hf_typeoid = -1;
 static int hf_oid = -1;
 static int hf_format = -1;
+static int hf_field_count = -1;
 static int hf_val_name = -1;
 static int hf_val_idx = -1;
 static int hf_val_length = -1;
@@ -286,7 +287,7 @@ static void dissect_pgsql_fe_msg(guchar type, guint length, tvbuff_t *tvb,
 {
     guchar c;
     gint i, l;
-    char *s, *t;
+    char *s;
     proto_item *ti, *hidden_item;
     proto_tree *shrub;
 
@@ -412,13 +413,14 @@ static void dissect_pgsql_fe_msg(guchar type, guint length, tvbuff_t *tvb,
         /* Startup message */
         case 196608:
             while (length > 0) {
-                s = tvb_get_ephemeral_stringz(tvb, n, &l);
+                l = tvb_strsize(tvb, n);
                 length -= l;
                 if (length <= 0) {
                     break;
                 }
-                t = tvb_get_ephemeral_stringz(tvb, n+l, &i);
-                proto_tree_add_text(tree, tvb, n, l+i, "%s: %s", s, t);
+                proto_tree_add_item(tree, hf_parameter_name, tvb, n, l, ENC_NA);
+                i = tvb_strsize(tvb, n+l);
+                proto_tree_add_item(tree, hf_parameter_value, tvb, n + l, i, ENC_NA);
                 n += l+i;
                 length -= i;
                 if (length == 1 && tvb_get_guint8(tvb, n) == 0)
@@ -539,7 +541,7 @@ static void dissect_pgsql_be_msg(guchar type, guint length, tvbuff_t *tvb,
     /* Row description */
     case 'T':
         i = tvb_get_ntohs(tvb, n);
-        ti = proto_tree_add_text(tree, tvb, n, 2, "Columns: %d", i);
+        ti = proto_tree_add_item(tree, hf_field_count, tvb, n, 2, FALSE);
         shrub = proto_item_add_subtree(ti, ett_values);
         n += 2;
         while (i-- > 0) {
@@ -566,7 +568,7 @@ static void dissect_pgsql_be_msg(guchar type, guint length, tvbuff_t *tvb,
     /* Data row */
     case 'D':
         i = tvb_get_ntohs(tvb, n);
-        ti = proto_tree_add_text(tree, tvb, n, 2, "Columns: %d", i);
+        ti = proto_tree_add_item(tree, hf_field_count, tvb, n, 2, FALSE);
         shrub = proto_item_add_subtree(ti, ett_values);
         n += 2;
         while (i-- > 0) {
@@ -764,6 +766,10 @@ proto_register_pgsql(void)
           { "Format", "pgsql.format", FT_UINT16, BASE_DEC, VALS(format_vals),
             0, "A format specifier.", HFILL }
         },
+        { &hf_field_count,
+          { "Field count", "pgsql.field.count", FT_UINT16, BASE_DEC, NULL, 0,
+            "The number of fields within a row.", HFILL }
+        },
         { &hf_val_name,
           { "Column name", "pgsql.col.name", FT_STRINGZ, BASE_NONE, NULL, 0,
             "The name of a column.", HFILL }