diff --git a/epan/dissectors/packet-exec.c b/epan/dissectors/packet-exec.c index 9466293dd2..976d1a93e3 100644 --- a/epan/dissectors/packet-exec.c +++ b/epan/dissectors/packet-exec.c @@ -39,14 +39,11 @@ #include #include #include +#include /* The exec protocol uses TCP port 512 per its IANA assignment */ #define EXEC_PORT 512 -/* Forward declaration we need below */ -static gboolean exec_isprint_string(guchar *string); -static gboolean exec_isdigit_string(guchar *string); - /* Variables for our preferences */ static gboolean preference_info_show_username = TRUE; static gboolean preference_info_show_command = FALSE; @@ -240,7 +237,7 @@ dissect_exec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * It is optional, so it may only be 1 character long * (the NULL) */ - if(length == 1 || (exec_isdigit_string(field_stringz) + if(length == 1 || (isdigit_string(field_stringz) && length <= EXEC_STDERR_PORT_LEN)){ proto_tree_add_string(exec_tree, hf_exec_stderr_port, tvb, offset, length, (gchar*)field_stringz); /* Next field we need */ @@ -261,7 +258,7 @@ dissect_exec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* Check if this looks like the username field */ if(length != 1 && length <= EXEC_USERNAME_LEN - && exec_isprint_string(field_stringz)){ + && isprint_string(field_stringz)){ proto_tree_add_string(exec_tree, hf_exec_username, tvb, offset, length, (gchar*)field_stringz); /* Store the username so we can display it in the @@ -289,7 +286,7 @@ dissect_exec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* Check if this looks like the password field */ if(length != 1 && length <= EXEC_PASSWORD_LEN - && exec_isprint_string(field_stringz)){ + && isprint_string(field_stringz)){ proto_tree_add_string(exec_tree, hf_exec_password, tvb, offset, length, (gchar*)field_stringz); /* Next field we need */ @@ -312,7 +309,7 @@ dissect_exec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* Check if this looks like the command field */ if(length != 1 && length <= EXEC_COMMAND_LEN - && exec_isprint_string(field_stringz)){ + && isprint_string(field_stringz)){ proto_tree_add_string(exec_tree, hf_exec_command, tvb, offset, length, (gchar*)field_stringz); /* Store the username so we can display it in the @@ -412,39 +409,3 @@ proto_reg_handoff_exec(void) exec_handle = create_dissector_handle(dissect_exec, proto_exec); dissector_add_uint("tcp.port", EXEC_PORT, exec_handle); } - -/* Custom function to check if an entire string is printable. */ -static gboolean -exec_isprint_string(guchar *string) -{ - guint position; - - /* Loop until we reach the end of the string (a null) */ - for(position = 0; string[position] != '\0'; position++){ - if(!isprint(string[position])){ - /* The string contains a non-printable character */ - return FALSE; - } - } - - /* The string contains only printable characters */ - return TRUE; -} - -/* Custom function to check if an entire string is digits. */ -static gboolean -exec_isdigit_string(guchar *string) -{ - guint position; - - /* Loop until we reach the end of the string (a null) */ - for(position = 0; string[position] != '\0'; position++){ - if(!isdigit(string[position])){ - /* The string contains a non-digit character */ - return FALSE; - } - } - - /* The string contains only digits */ - return TRUE; -} diff --git a/wsutil/libwsutil.def b/wsutil/libwsutil.def index 4d811c098c..c76e646d22 100644 --- a/wsutil/libwsutil.def +++ b/wsutil/libwsutil.def @@ -88,6 +88,8 @@ strptime ; str_util.c ascii_strdown_inplace ascii_strup_inplace +isprint_string +isdigit_string ; type_util.c type_util_gdouble_to_guint64 diff --git a/wsutil/str_util.c b/wsutil/str_util.c index e94fec9046..717fcb516d 100644 --- a/wsutil/str_util.c +++ b/wsutil/str_util.c @@ -29,6 +29,8 @@ #include #include "str_util.h" +#include + /* Convert all ASCII letters to lower case, in place. */ gchar * ascii_strdown_inplace(gchar *str) @@ -52,3 +54,39 @@ ascii_strup_inplace(gchar *str) return (str); } + +/* Check if an entire string is printable. */ +gboolean +isprint_string(guchar *str) +{ + guint pos; + + /* Loop until we reach the end of the string (a null) */ + for(pos = 0; str[pos] != '\0'; pos++){ + if(!isprint(str[pos])){ + /* The string contains a non-printable character */ + return FALSE; + } + } + + /* The string contains only printable characters */ + return TRUE; +} + +/* Check if an entire string is digits. */ +gboolean +isdigit_string(guchar *str) +{ + guint pos; + + /* Loop until we reach the end of the string (a null) */ + for(pos = 0; str[pos] != '\0'; pos++){ + if(!isdigit(str[pos])){ + /* The string contains a non-digit character */ + return FALSE; + } + } + + /* The string contains only digits */ + return TRUE; +} diff --git a/wsutil/str_util.h b/wsutil/str_util.h index cbc6f2bad5..63537183fd 100644 --- a/wsutil/str_util.h +++ b/wsutil/str_util.h @@ -59,4 +59,18 @@ gchar *ascii_strdown_inplace(gchar *str); */ gchar *ascii_strup_inplace(gchar *str); +/** Check if an entire string consists of printable characters + * + * @param str The string to be checked + * @return TRUE if the entire string is printable, otherwise FALSE + */ +gboolean isprint_string(guchar *string); + +/** Check if an entire string consists of digits + * + * @param str The string to be checked + * @return TRUE if the entire string is digits, otherwise FALSE + */ +gboolean isdigit_string(guchar *string); + #endif /* __STR_UTIL_H__ */