extcap_parser: remove G_REGEX_RAW from line parsing.
Check for utf8 valid line instead. Add a testcase that shows how the former code was buggy on special characters extcap sentences. Bug: 15668 Change-Id: Ic045c4791388af98705916e6ea84be8fc9b3c5b8 Reviewed-on: https://code.wireshark.org/review/32754 Petri-Dish: Dario Lombardo <lomato@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
parent
c1dcf8c3fa
commit
c442ee056b
|
@ -86,7 +86,9 @@ gdouble extcap_complex_get_double(extcap_complex *comp) {
|
|||
}
|
||||
|
||||
static gboolean matches_regex(const char *pattern, const char *subject) {
|
||||
return g_regex_match_simple(pattern, subject, (GRegexCompileFlags) (G_REGEX_CASELESS | G_REGEX_RAW), (GRegexMatchFlags)0);
|
||||
if (!g_utf8_validate(subject, -1, NULL))
|
||||
return FALSE;
|
||||
return g_regex_match_simple(pattern, subject, (GRegexCompileFlags) (G_REGEX_CASELESS), (GRegexMatchFlags)0);
|
||||
}
|
||||
|
||||
gboolean extcap_complex_get_bool(extcap_complex *comp) {
|
||||
|
@ -111,13 +113,16 @@ static extcap_token_sentence *extcap_tokenize_sentence(const gchar *s) {
|
|||
gchar *param_value = NULL;
|
||||
guint param_type = EXTCAP_PARAM_UNKNOWN;
|
||||
|
||||
if (!g_utf8_validate(s, -1, NULL))
|
||||
return FALSE;
|
||||
|
||||
extcap_token_sentence *rs = g_new0(extcap_token_sentence, 1);
|
||||
|
||||
rs->sentence = NULL;
|
||||
|
||||
/* Regex for catching just the allowed values for sentences */
|
||||
if ((regex = g_regex_new("^[\\t| ]*(arg|value|interface|extcap|dlt|control)(?=[\\t| ]+\\{)",
|
||||
(GRegexCompileFlags) (G_REGEX_CASELESS | G_REGEX_RAW),
|
||||
(GRegexCompileFlags) (G_REGEX_CASELESS),
|
||||
(GRegexMatchFlags) 0, NULL)) != NULL) {
|
||||
g_regex_match(regex, s, (GRegexMatchFlags) 0, &match_info);
|
||||
|
||||
|
@ -139,7 +144,7 @@ static extcap_token_sentence *extcap_tokenize_sentence(const gchar *s) {
|
|||
* that regex patterns given to {validation=} are parsed correctly,
|
||||
* as long as }{ does not occur within the pattern */
|
||||
regex = g_regex_new("\\{([a-zA-Z_-]*?)\\=(.*?)\\}(?=\\{|$|\\s)",
|
||||
(GRegexCompileFlags) (G_REGEX_CASELESS | G_REGEX_RAW),
|
||||
(GRegexCompileFlags) (G_REGEX_CASELESS),
|
||||
(GRegexMatchFlags) 0, NULL);
|
||||
if (regex != NULL) {
|
||||
g_regex_match_full(regex, s, -1, 0, (GRegexMatchFlags) 0, &match_info, &error);
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# Wireshark test dummy extcap
|
||||
#
|
||||
# Copyright (c) 2018-2019 Peter Wu <peter@lekensteyn.nl>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#
|
||||
import argparse, os, sys
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
# Actions
|
||||
parser.add_argument('--extcap-interfaces', action='store_true')
|
||||
parser.add_argument('--extcap-dlts', action='store_true')
|
||||
parser.add_argument('--extcap-config', action='store_true')
|
||||
parser.add_argument('--capture', action='store_true')
|
||||
parser.add_argument('--extcap-version')
|
||||
|
||||
parser.add_argument('--extcap-interface', metavar='IFACE')
|
||||
|
||||
parser.add_argument('--extcap-capture-filter', metavar='CFILTER')
|
||||
parser.add_argument('--fifo', metavar='FIFO')
|
||||
|
||||
|
||||
def extcap_interfaces():
|
||||
print("extcap {version=1.0}")
|
||||
print("interface {value=sampleif}{display=Remote dumpcap}")
|
||||
|
||||
|
||||
def extcap_dlts():
|
||||
# Required for the interface to show up in the interface list
|
||||
print("dlt {number=147}{name=USER0}{display=Remote capture dependent DLT}")
|
||||
|
||||
|
||||
def extcap_config():
|
||||
print("arg {number=0}{call=--test1}{display=Remote SSH server address}{type=string}{tooltip=bla}{required=true}{group=Server}")
|
||||
print("arg {number=1}{call=--test2}{display=[7] Urządzenie kompozytowe USB}{type=string}{tooltip=X}{group=Capture}")
|
||||
|
||||
|
||||
def main():
|
||||
args = parser.parse_args()
|
||||
if args.extcap_interfaces:
|
||||
return extcap_interfaces()
|
||||
|
||||
if args.extcap_dlts:
|
||||
return extcap_dlts()
|
||||
elif args.extcap_config:
|
||||
return extcap_config()
|
||||
else:
|
||||
parser.error('Unsupported')
|
||||
return 1
|
||||
|
||||
sys.exit(main())
|
|
@ -10,10 +10,12 @@
|
|||
'''Command line option tests'''
|
||||
|
||||
import json
|
||||
import sys
|
||||
import os.path
|
||||
import subprocess
|
||||
import subprocesstest
|
||||
import fixtures
|
||||
import shutil
|
||||
|
||||
#glossaries = ('fields', 'protocols', 'values', 'decodes', 'defaultprefs', 'currentprefs')
|
||||
|
||||
|
@ -279,3 +281,27 @@ class case_tshark_z_expert(subprocesstest.SubprocessTestCase):
|
|||
self.assertFalse(self.grepOutput('Errors'))
|
||||
self.assertFalse(self.grepOutput('Warns'))
|
||||
self.assertFalse(self.grepOutput('Chats'))
|
||||
|
||||
|
||||
@fixtures.mark_usefixtures('test_env')
|
||||
@fixtures.uses_fixtures
|
||||
class case_tshark_extcap(subprocesstest.SubprocessTestCase):
|
||||
def test_tshark_extcap_interfaces(self, cmd_tshark, program_path):
|
||||
# Script extcaps don't work with the current code on windows.
|
||||
# https://www.wireshark.org/docs/wsdg_html_chunked/ChCaptureExtcap.html
|
||||
# TODO: skip this test until it will get fixed.
|
||||
if sys.platform == 'win32':
|
||||
self.skipTest('FIXME extcap .py scripts needs special treatment on Windows')
|
||||
extcap_tool = 'sampleif.py'
|
||||
target_dir = os.path.join(program_path, 'extcap')
|
||||
target_file = os.path.join(target_dir, extcap_tool)
|
||||
source_file = os.path.join(os.path.dirname(__file__), extcap_tool)
|
||||
os.makedirs(target_dir, exist_ok=True)
|
||||
shutil.copy2(source_file, target_file)
|
||||
# Ensure the test extcap_tool is properly loaded
|
||||
self.assertRun((cmd_tshark, '-D'))
|
||||
self.assertEqual(1, self.countOutput('sampleif'))
|
||||
# Ensure tshark lists 2 interfaces in the preferences
|
||||
self.assertRun((cmd_tshark, '-G', 'currentprefs'))
|
||||
self.assertEqual(2, self.countOutput('extcap.sampleif.test'))
|
||||
os.remove(target_file)
|
||||
|
|
Loading…
Reference in New Issue