From fab566d69fe33197369488a8bf040bd116bdb95c Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 19 Jun 2011 16:05:29 +0000 Subject: [PATCH] Fix Dead Store (Dead assignement/Dead increment) Warning found by Clang Use 2-space indenting svn path=/trunk/; revision=37712 --- epan/dissectors/packet-slsk.c | 4817 +++++++++++++++++---------------- 1 file changed, 2410 insertions(+), 2407 deletions(-) diff --git a/epan/dissectors/packet-slsk.c b/epan/dissectors/packet-slsk.c index b4f700f381..217d76dca3 100644 --- a/epan/dissectors/packet-slsk.c +++ b/epan/dissectors/packet-slsk.c @@ -44,6 +44,7 @@ #include "packet-tcp.h" #include #include +#include /* Initialize the protocol and registered fields */ static int proto_slsk = -1; @@ -113,9 +114,9 @@ static int hf_slsk_ranking = -1; static gint ett_slsk = -1; static gint ett_slsk_compr_packet = -1; -#define TCP_PORT_SLSK_1 2234 -#define TCP_PORT_SLSK_2 5534 -#define TCP_PORT_SLSK_3 2240 +#define TCP_PORT_SLSK_1 2234 +#define TCP_PORT_SLSK_2 5534 +#define TCP_PORT_SLSK_3 2240 /* desegmentation of SoulSeek Message over TCP */ @@ -127,176 +128,176 @@ static gboolean slsk_decompress = FALSE; #endif static const value_string slsk_tcp_msgs[] = { - { 1, "Login"}, - { 2, "Set Wait Port"}, - { 3, "Get Peer Address"}, - { 4, "Get Shared File List"}, - { 5, "User Exists / Shared File List"}, - { 7, "Get User Status"}, - { 9, "File Search Result"}, - { 13, "Say ChatRoom"}, - { 14, "Join Room"}, - { 15, "Leave Room / User Info Request"}, - { 16, "User Joined Room / User Info Reply"}, - { 17, "User Left Room"}, - { 18, "Connect To Peer"}, - { 22, "Message User"}, - { 23, "Message User Ack"}, - { 26, "File Search"}, - { 28, "Set Status"}, - { 32, "Ping"}, - { 34, "Update Upload Speed"}, - { 35, "Shared Files & Folders"}, - { 36, "Get User Stats / Folder Contents Request"}, - { 37, "Folder Contents Response"}, - { 40, "Queued Downloads / Transfer Request"}, - { 41, "Transfer Response"}, - { 42, "Placehold Upload"}, - { 43, "Queue Upload"}, - { 44, "Place In Queue"}, - { 46, "Upload Failed"}, - { 50, "Queue Failed / Own Recommendation"}, - { 51, "Add Things I like / Place In Queue Request"}, - { 52, "Remove Things I like"}, - { 54, "Get Recommendations"}, - { 55, "Type 55"}, - { 56, "Get Global Rankings"}, - { 57, "Get User Recommendations"}, - { 58, "Admin Command"}, - { 60, "Place In Line Response"}, - { 62, "Room Added"}, - { 63, "Room Removed"}, - { 64, "Room List"}, - { 65, "Exact File Search"}, - { 66, "Admin Message"}, - { 67, "Global User List"}, - { 68, "Tunneled Message"}, - { 69, "Privileged User List"}, - { 71, "Get Parent List"}, - { 73, "Type 73"}, - { 83, "Parent Min Speed"}, - { 84, "Parent Speed Connection Ratio"}, - { 86, "Parent Inactivity Before Disconnect"}, - { 87, "Server Inactivity Before Disconnect"}, - { 88, "Nodes In Cache Before Disconnect"}, - { 90, "Seconds Before Ping Children"}, - { 91, "Add To Privileged"}, - { 92, "Check Privileges"}, - { 93, "Embedded Message"}, - { 100, "Become Parent"}, - { 102, "Random Parent Addresses"}, - { 103, "Send Wishlist Entry"}, - { 104, "Type 104"}, - { 110, "Get Similar Users"}, - { 111, "Get Recommendations for Item"}, - { 112, "Get Similar Users for Item"}, - { 1001, "Can't Connect To Peer"}, - { 0, NULL } + { 1, "Login"}, + { 2, "Set Wait Port"}, + { 3, "Get Peer Address"}, + { 4, "Get Shared File List"}, + { 5, "User Exists / Shared File List"}, + { 7, "Get User Status"}, + { 9, "File Search Result"}, + { 13, "Say ChatRoom"}, + { 14, "Join Room"}, + { 15, "Leave Room / User Info Request"}, + { 16, "User Joined Room / User Info Reply"}, + { 17, "User Left Room"}, + { 18, "Connect To Peer"}, + { 22, "Message User"}, + { 23, "Message User Ack"}, + { 26, "File Search"}, + { 28, "Set Status"}, + { 32, "Ping"}, + { 34, "Update Upload Speed"}, + { 35, "Shared Files & Folders"}, + { 36, "Get User Stats / Folder Contents Request"}, + { 37, "Folder Contents Response"}, + { 40, "Queued Downloads / Transfer Request"}, + { 41, "Transfer Response"}, + { 42, "Placehold Upload"}, + { 43, "Queue Upload"}, + { 44, "Place In Queue"}, + { 46, "Upload Failed"}, + { 50, "Queue Failed / Own Recommendation"}, + { 51, "Add Things I like / Place In Queue Request"}, + { 52, "Remove Things I like"}, + { 54, "Get Recommendations"}, + { 55, "Type 55"}, + { 56, "Get Global Rankings"}, + { 57, "Get User Recommendations"}, + { 58, "Admin Command"}, + { 60, "Place In Line Response"}, + { 62, "Room Added"}, + { 63, "Room Removed"}, + { 64, "Room List"}, + { 65, "Exact File Search"}, + { 66, "Admin Message"}, + { 67, "Global User List"}, + { 68, "Tunneled Message"}, + { 69, "Privileged User List"}, + { 71, "Get Parent List"}, + { 73, "Type 73"}, + { 83, "Parent Min Speed"}, + { 84, "Parent Speed Connection Ratio"}, + { 86, "Parent Inactivity Before Disconnect"}, + { 87, "Server Inactivity Before Disconnect"}, + { 88, "Nodes In Cache Before Disconnect"}, + { 90, "Seconds Before Ping Children"}, + { 91, "Add To Privileged"}, + { 92, "Check Privileges"}, + { 93, "Embedded Message"}, + { 100, "Become Parent"}, + { 102, "Random Parent Addresses"}, + { 103, "Send Wishlist Entry"}, + { 104, "Type 104"}, + { 110, "Get Similar Users"}, + { 111, "Get Recommendations for Item"}, + { 112, "Get Similar Users for Item"}, + { 1001, "Can't Connect To Peer"}, + { 0, NULL } }; static const value_string slsk_status_codes[] = { - { -1, "Unknown"}, - { 0, "Offline"}, - { 1, "Away"}, - { 2, "Online"}, - { 0, NULL } + { -1, "Unknown"}, + { 0, "Offline"}, + { 1, "Away"}, + { 2, "Online"}, + { 0, NULL } }; static const value_string slsk_transfer_direction[] = { - { 0, "Download"}, - { 1, "Upload"}, - { 0, NULL } + { 0, "Download"}, + { 1, "Upload"}, + { 0, NULL } }; static const value_string slsk_yes_no[] = { - { 0, "No"}, - { 1, "Yes"}, - { 0, NULL } + { 0, "No"}, + { 1, "Yes"}, + { 0, NULL } }; static const value_string slsk_attr_type[] = { - { 0, "Bitrate"}, - { 1, "Length"}, - { 2, "VBR"}, - { 0, NULL } + { 0, "Bitrate"}, + { 1, "Length"}, + { 2, "VBR"}, + { 0, NULL } }; static const char* connection_type(char con_type[]) { - if (strlen(con_type) != 1) return "Unknown"; - if (con_type[0] == 'D') return "Distributed Search"; - if (con_type[0] == 'P') return "Peer Connection"; /* "File Search Result / User Info Request / Get Shared File List" */ - if (con_type[0] == 'F') return "File Transfer"; - return "Unknown"; + if (strlen(con_type) != 1) return "Unknown"; + if (con_type[0] == 'D') return "Distributed Search"; + if (con_type[0] == 'P') return "Peer Connection"; /* "File Search Result / User Info Request / Get Shared File List" */ + if (con_type[0] == 'F') return "File Transfer"; + return "Unknown"; } static gboolean check_slsk_format(tvbuff_t *tvb, int offset, const char format[]){ - /* - * Returns TRUE if tvbuff beginning at offset matches a certain format - * The format is given by an array of characters standing for a special field type - * i - integer (4 bytes) - * b - byte (1 byte) - * s - string (string_length + 4 bytes) - * - * * - can be used at the end of a format to ignore any following bytes - */ + /* + * Returns TRUE if tvbuff beginning at offset matches a certain format + * The format is given by an array of characters standing for a special field type + * i - integer (4 bytes) + * b - byte (1 byte) + * s - string (string_length + 4 bytes) + * + * * - can be used at the end of a format to ignore any following bytes + */ - switch ( format[0] ) { - case 'i': - if (tvb_length_remaining(tvb, offset) < 4) return FALSE; - offset += 4; - break; - case 'b': - if (tvb_length_remaining(tvb, offset) < 1) return FALSE; - offset += 1; - break; - case 's': - if (tvb_length_remaining(tvb, offset) < 4) return FALSE; - if (tvb_length_remaining(tvb, offset) < (int)tvb_get_letohl(tvb, offset)+4) return FALSE; - offset += tvb_get_letohl(tvb, offset)+4; - break; - case '*': - return TRUE; - default: - return FALSE; - } + switch ( format[0] ) { + case 'i': + if (tvb_length_remaining(tvb, offset) < 4) return FALSE; + offset += 4; + break; + case 'b': + if (tvb_length_remaining(tvb, offset) < 1) return FALSE; + offset += 1; + break; + case 's': + if (tvb_length_remaining(tvb, offset) < 4) return FALSE; + if (tvb_length_remaining(tvb, offset) < (int)tvb_get_letohl(tvb, offset)+4) return FALSE; + offset += tvb_get_letohl(tvb, offset)+4; + break; + case '*': + return TRUE; + default: + return FALSE; + } - if (format[1] == '\0' ) { - if (tvb_length_remaining(tvb, offset) != 0) return FALSE; /* Checks for additional bytes at the end */ - return TRUE; - } - return check_slsk_format(tvb, offset, &format[1]); + if (format[1] == '\0' ) { + if (tvb_length_remaining(tvb, offset) != 0) return FALSE; /* Checks for additional bytes at the end */ + return TRUE; + } + return check_slsk_format(tvb, offset, &format[1]); } static const char* get_message_type(tvbuff_t *tvb) { - /* - * Checks if the Message Code is known. - * If unknown checks if the Message Code is stored in a byte. - * Returns the Message Type. - */ - int msg_code = tvb_get_letohl(tvb, 4); - const gchar *message_type = match_strval(msg_code, slsk_tcp_msgs); - if (message_type == NULL) { - if (check_slsk_format(tvb, 4, "bisis")) - message_type = "Distributed Search"; - else if (check_slsk_format(tvb, 4, "bssi")) - message_type = "Peer Init"; - else if (check_slsk_format(tvb, 4, "bi")) - message_type = "Pierce Fw"; - else - message_type = "Unknown"; - } - return message_type; + /* + * Checks if the Message Code is known. + * If unknown checks if the Message Code is stored in a byte. + * Returns the Message Type. + */ + int msg_code = tvb_get_letohl(tvb, 4); + const gchar *message_type = match_strval(msg_code, slsk_tcp_msgs); + if (message_type == NULL) { + if (check_slsk_format(tvb, 4, "bisis")) + message_type = "Distributed Search"; + else if (check_slsk_format(tvb, 4, "bssi")) + message_type = "Peer Init"; + else if (check_slsk_format(tvb, 4, "bi")) + message_type = "Pierce Fw"; + else + message_type = "Unknown"; + } + return message_type; } static guint get_slsk_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset) { - guint32 msg_len; - msg_len = tvb_get_letohl(tvb, offset); - /* That length doesn't include the length field itself; add that in. */ - msg_len += 4; - return msg_len; + guint32 msg_len; + msg_len = tvb_get_letohl(tvb, offset); + /* That length doesn't include the length field itself; add that in. */ + msg_len += 4; + return msg_len; } /* Code to actually dissect the packets */ @@ -305,2083 +306,2085 @@ static void dissect_slsk_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree { /* Set up structures needed to add the protocol subtree and manage it */ - proto_item *ti; - proto_tree *slsk_tree; + proto_item *ti, *ti_len=NULL; + proto_tree *slsk_tree; - int offset, i, j; - guint32 msg_len, msg_code; - const gchar *message_type; - guint8 *str; + int offset, i, j; + guint32 msg_len, msg_code; + const gchar *message_type; + guint8 *str; - int comprlen = 0; - int uncomprlen = 0; - int uncompr_tvb_offset = 0; - int i2 = 0; - int j2 = 0; - int i3 = 0; - int j3 = 0; + int comprlen = 0; + int uncomprlen = 0; + int uncompr_tvb_offset = 0; + int i2 = 0; + int j2 = 0; + int i3 = 0; + int j3 = 0; - offset = 0; + offset = 0; - msg_len = tvb_get_letohl(tvb, offset); - msg_code = tvb_get_letohl(tvb, offset+4); - message_type = get_message_type(tvb); + msg_len = tvb_get_letohl(tvb, offset); + msg_code = tvb_get_letohl(tvb, offset+4); + message_type = get_message_type(tvb); /* Make entries in Protocol column and Info column on summary display */ - col_set_str(pinfo->cinfo, COL_PROTOCOL, "slsk"); + col_set_str(pinfo->cinfo, COL_PROTOCOL, "slsk"); /* This field shows up as the "Info" column in the display */ - col_set_str(pinfo->cinfo, COL_INFO, "SoulSeek Message"); + col_set_str(pinfo->cinfo, COL_INFO, "SoulSeek Message"); - if (check_col(pinfo->cinfo, COL_INFO)) { - col_append_fstr(pinfo->cinfo, COL_INFO, ": %s", message_type); - } + if (check_col(pinfo->cinfo, COL_INFO)) { + col_append_fstr(pinfo->cinfo, COL_INFO, ": %s", message_type); + } - if (tree) { + if (tree) { /* create display subtree for the protocol */ - ti = proto_tree_add_item(tree, proto_slsk, tvb, 0, -1, FALSE); - slsk_tree = proto_item_add_subtree(ti, ett_slsk); + ti = proto_tree_add_item(tree, proto_slsk, tvb, 0, -1, FALSE); + slsk_tree = proto_item_add_subtree(ti, ett_slsk); /* Continue adding tree items to process the packet here */ - proto_tree_add_uint(slsk_tree, hf_slsk_message_length, tvb, offset, 4, msg_len); - offset += 4; - - switch (msg_code) { - - case 1: - if (check_slsk_format(tvb, offset, "issi")) { - /* Client-to-Server */ - message_type = "Login"; - proto_tree_add_uint_format(slsk_tree, hf_slsk_message_code, tvb, offset, 4, msg_code, - "Message Type: %s (Code: %02d)", message_type, msg_code); - offset += 4; - proto_tree_add_uint(slsk_tree, hf_slsk_string_length, tvb, offset, 4, tvb_get_letohl(tvb, offset)); - proto_tree_add_item(slsk_tree, hf_slsk_username, tvb, offset+4, tvb_get_letohl(tvb, offset), FALSE); - offset += 4+tvb_get_letohl(tvb, offset); - proto_tree_add_uint(slsk_tree, hf_slsk_string_length, tvb, offset, 4, tvb_get_letohl(tvb, offset)); - proto_tree_add_item(slsk_tree, hf_slsk_password, tvb, offset+4, tvb_get_letohl(tvb, offset), FALSE); - offset += 4+tvb_get_letohl(tvb, offset); - proto_tree_add_uint(slsk_tree, hf_slsk_version, tvb, offset, 4, tvb_get_letohl(tvb, offset)); - offset += 4; - } - else if (check_slsk_format(tvb, offset, "ibs") || check_slsk_format(tvb, offset, "ibsi")) { - /* Server-to-Client */ - message_type = "Login Reply"; - proto_tree_add_uint_format(slsk_tree, hf_slsk_message_code, tvb, offset, 4, msg_code, - "Message Type: %s (Code: %02d)", message_type, msg_code); - offset += 4; - i=tvb_get_guint8(tvb, offset); - proto_tree_add_uint_format(slsk_tree, hf_slsk_login_successful, tvb, offset, 1, tvb_get_guint8(tvb, offset), - "Login successful: %s (Byte: %d)", val_to_str(tvb_get_guint8(tvb, offset), slsk_yes_no, "Unknown"), tvb_get_guint8(tvb, offset)); - offset += 1; - proto_tree_add_uint(slsk_tree, hf_slsk_string_length, tvb, offset, 4, tvb_get_letohl(tvb, offset)); - proto_tree_add_item(slsk_tree, hf_slsk_login_message, tvb, offset+4, tvb_get_letohl(tvb, offset), FALSE); - offset += 4+tvb_get_letohl(tvb, offset); - if (i == 1){ - proto_tree_add_ipv4(slsk_tree, hf_slsk_client_ip, tvb, offset, 4, tvb_get_ntohl(tvb, offset)); - offset += 4; - } - } - break; - - case 2: - if (check_slsk_format(tvb, offset, "ii")) { - /* Client-to-Server */ - message_type = "Set Wait Port"; - proto_tree_add_uint_format(slsk_tree, hf_slsk_message_code, tvb, offset, 4, msg_code, - "Message Type: %s (Code: %02d)", message_type, msg_code); - offset += 4; - proto_tree_add_uint(slsk_tree, hf_slsk_port, tvb, offset, 4, tvb_get_letohl(tvb, offset)); - offset += 4; - } - break; - - case 3: - if (check_slsk_format(tvb, offset, "isii")) { - /* Server-to-Client */ - message_type = "Get Peer Address Reply"; - proto_tree_add_uint_format(slsk_tree, hf_slsk_message_code, tvb, offset, 4, msg_code, - "Message Type: %s (Code: %02d)", message_type, msg_code); - offset += 4; - proto_tree_add_uint(slsk_tree, hf_slsk_string_length, tvb, offset, 4, tvb_get_letohl(tvb, offset)); - proto_tree_add_item(slsk_tree, hf_slsk_username, tvb, offset+4, tvb_get_letohl(tvb, offset), FALSE); - offset += 4+tvb_get_letohl(tvb, offset); - proto_tree_add_ipv4(slsk_tree, hf_slsk_ip, tvb, offset, 4, tvb_get_ntohl(tvb, offset)); - offset += 4; - proto_tree_add_uint(slsk_tree, hf_slsk_port, tvb, offset, 4, tvb_get_letohl(tvb, offset)); - offset += 4; - } - else if (check_slsk_format(tvb, offset, "is")) { - /* Client-to-Server */ - message_type = "Get Peer Address"; - proto_tree_add_uint_format(slsk_tree, hf_slsk_message_code, tvb, offset, 4, msg_code, - "Message Type: %s (Code: %02d)", message_type, msg_code); - offset += 4; - proto_tree_add_uint(slsk_tree, hf_slsk_string_length, tvb, offset, 4, tvb_get_letohl(tvb, offset)); - proto_tree_add_item(slsk_tree, hf_slsk_username, tvb, offset+4, tvb_get_letohl(tvb, offset), FALSE); - offset += 4+tvb_get_letohl(tvb, offset); - } - break; - - case 4: - if (check_slsk_format(tvb, offset, "i")) { - /* Client-to-Client */ - message_type = "Get Shared File List"; - proto_tree_add_uint_format(slsk_tree, hf_slsk_message_code, tvb, offset, 4, msg_code, - "Message Type: %s (Code: %02d)", message_type, msg_code); - offset += 4; - } - break; - - case 5: - if (check_slsk_format(tvb, offset, "isb")) { - /* Server-to-Client */ - message_type = "User Exists Reply"; - proto_tree_add_uint_format(slsk_tree, hf_slsk_message_code, tvb, offset, 4, msg_code, - "Message Type: %s (Code: %02d)", message_type, msg_code); - offset += 4; - proto_tree_add_uint(slsk_tree, hf_slsk_string_length, tvb, offset, 4, tvb_get_letohl(tvb, offset)); - proto_tree_add_item(slsk_tree, hf_slsk_username, tvb, offset+4, tvb_get_letohl(tvb, offset), FALSE); - offset += 4+tvb_get_letohl(tvb, offset); - proto_tree_add_uint_format(slsk_tree, hf_slsk_user_exists, tvb, offset, 1, tvb_get_guint8(tvb, offset), - "User exists: %s (Byte: %d)", val_to_str(tvb_get_guint8(tvb, offset), slsk_yes_no, "Unknown"), tvb_get_guint8(tvb, offset)); - offset += 1; - } - else if (check_slsk_format(tvb, offset, "is")) { - /* Client-to-Server */ - message_type = "User Exists Request"; - proto_tree_add_uint_format(slsk_tree, hf_slsk_message_code, tvb, offset, 4, msg_code, - "Message Type: %s (Code: %02d)", message_type, msg_code); - offset += 4; - proto_tree_add_uint(slsk_tree, hf_slsk_string_length, tvb, offset, 4, tvb_get_letohl(tvb, offset)); - proto_tree_add_item(slsk_tree, hf_slsk_username, tvb, offset+4, tvb_get_letohl(tvb, offset), FALSE); - offset += 4+tvb_get_letohl(tvb, offset); - } - else if (check_slsk_format(tvb, offset, "i*")) { - /* Client-to-Client */ - message_type = "Shared File List"; - proto_tree_add_uint_format(slsk_tree, hf_slsk_message_code, tvb, offset, 4, msg_code, - "Message Type: %s (Code: %02d)", message_type, msg_code); - offset += 4; - - /* [zlib compressed] */ - comprlen = tvb_length_remaining(tvb, offset); - - if (slsk_decompress == TRUE){ - - tvbuff_t *uncompr_tvb = tvb_child_uncompress(tvb, tvb, offset, comprlen); - - if (uncompr_tvb == NULL) { - proto_tree_add_text(slsk_tree, tvb, offset, -1, - "[zlib compressed packet]"); - offset += tvb_length_remaining(tvb, offset); - proto_tree_add_text(slsk_tree, tvb, 0, 0, - "(uncompression failed !)"); - } else { - - proto_item *ti2 = proto_tree_add_item(slsk_tree, hf_slsk_compr_packet, tvb, offset, -1, FALSE); - proto_tree *slsk_compr_packet_tree = proto_item_add_subtree(ti2, ett_slsk_compr_packet); - - proto_tree_add_uint_format(slsk_tree, hf_slsk_integer, tvb, offset, -1, 0, - "( compressed packet length: %d)", comprlen); - uncomprlen = tvb_reported_length_remaining(uncompr_tvb, 0); - proto_tree_add_uint_format(slsk_tree, hf_slsk_integer, tvb, offset, -1, 0, - "(uncompressed packet length: %d)", uncomprlen); - - add_new_data_source(pinfo, uncompr_tvb, - "Uncompressed SoulSeek data"); - uncompr_tvb_offset = 0; - if (check_slsk_format(uncompr_tvb, uncompr_tvb_offset, "i*")) { - i=0; - j = tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset); - proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_integer, uncompr_tvb, uncompr_tvb_offset, 4, j, - "Number of directories: %u", j); - uncompr_tvb_offset += 4; - while (i