aboutsummaryrefslogtreecommitdiffstats
path: root/epan/tvbuff.c
diff options
context:
space:
mode:
authorJohn Thacker <johnthacker@gmail.com>2022-10-14 20:36:51 -0400
committerJohn Thacker <johnthacker@gmail.com>2022-10-16 22:43:39 +0000
commit5fd09b521dbca9beaad7b5407e2df511a6ff413f (patch)
tree84d664d4f802a2e842db526e9f93a535c75810e6 /epan/tvbuff.c
parent94b4202a99d41404b09bc85fa91e226408f3389f (diff)
ftp: deal with UTF-8
Ensure that FTP doesn't add invalid strings to the tree or columns. Also allow UTF-8 pathnames to work. According to RFC 2640, FTP supports UTF-8 for pathnames (and it MUST be supported even if the other side does not advertise support for UTF-8, unless a different character set has been explicitly configured, which is out of scope of the RFCs, and we don't have such a preference.) So in general interpret strings as UTF-8, not ASCII. Reduce the use of tvb_get_ptr by using functions directly on the original tvb and offset. This also happens to be more compliant with RFC 2640 when getting the token lengths. (RFC 2640 states that implementations MUST assume that there is only one space between a command and the pathname, and treat additional spaces as part of the pathname instead of skipping them. tvb_get_token_len() does not skip trailing spaces, but get_token_len() does.) The only place that still uses tvb_get_ptr is when processing a PWD command, because it has to deal with the double quote escaping as a custom encoding. Add a tvb_ascii_isdigit function. Fix #18439.
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r--epan/tvbuff.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index 344d811ff3..8b2ae215ec 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -3924,6 +3924,22 @@ gboolean tvb_utf_8_isprint(tvbuff_t *tvb, const gint offset, const gint length)
return isprint_utf8_string(buf, abs_length);
}
+gboolean tvb_ascii_isdigit(tvbuff_t *tvb, const gint offset, const gint length)
+{
+ const guint8* buf = tvb_get_ptr(tvb, offset, length);
+ guint abs_offset, abs_length = length;
+
+ if (length == -1) {
+ /* tvb_get_ptr has already checked for exceptions. */
+ compute_offset_and_remaining(tvb, offset, &abs_offset, &abs_length);
+ }
+ for (guint i = 0; i < abs_length; i++, buf++)
+ if (!g_ascii_isdigit(*buf))
+ return FALSE;
+
+ return TRUE;
+}
+
static ws_mempbrk_pattern pbrk_crlf;
/*
* Given a tvbuff, an offset into the tvbuff, and a length that starts