Skip to content

Commit a9ef32e

Browse files
authored
Revert "Patch CVE-2024-42002" (#1000)
This reverts commit 644310d. Signed-off-by: Michael Carroll <[email protected]>
1 parent 644310d commit a9ef32e

File tree

4 files changed

+9
-234
lines changed

4 files changed

+9
-234
lines changed

ros2topic/package.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
<license>Apache License 2.0</license>
1414
<license>BSD-3-Clause</license> <!-- ros2topic/verb/delay.py|hz.py|bw.py are BSD -->
15-
<license>MIT License</license> <!-- ros2topic/eval uses MIT License -->
1615

1716
<author email="[email protected]">Aditya Pande</author>
1817
<author email="[email protected]">Dirk Thomas</author>

ros2topic/ros2topic/eval/__init__.py

Lines changed: 0 additions & 159 deletions
This file was deleted.

ros2topic/ros2topic/verb/hz.py

Lines changed: 9 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
from ros2topic.api import get_msg_class
4949
from ros2topic.api import positive_int
5050
from ros2topic.api import TopicNameCompleter
51-
from ros2topic.eval import base_eval_model, Expr
5251
from ros2topic.verb import VerbExtension
5352

5453
DEFAULT_WINDOW_SIZE = 10000
@@ -92,69 +91,18 @@ def main(self, *, args):
9291
return main(args)
9392

9493

95-
def _get_nested_messages(msg_class):
96-
all_attributes = list(msg_class.__slots__)
97-
for attr in msg_class.__slots__:
98-
value = getattr(msg_class, attr)
99-
if hasattr(value, '__slots__'):
100-
nested_messages = _get_nested_messages(value)
101-
all_attributes.extend(nested_messages)
102-
return all_attributes
103-
104-
105-
def _setup_base_safe_eval():
106-
safe_eval_model = base_eval_model.clone()
107-
108-
# extend base_eval_model
109-
safe_eval_model.nodes.extend(['Call', 'Attribute', 'List', 'Tuple', 'Dict', 'Set',
110-
'ListComp', 'DictComp', 'SetComp', 'comprehension',
111-
'Mult', 'Pow', 'boolop', 'mod', 'Invert',
112-
'Is', 'IsNot', 'FloorDiv', 'If', 'For'])
113-
114-
# allow-list safe Python built-in functions
115-
safe_builtins = [
116-
'abs', 'all', 'any', 'bin', 'bool', 'chr', 'cmp', 'divmod', 'enumerate',
117-
'float', 'format', 'hex', 'id', 'int', 'isinstance', 'issubclass',
118-
'len', 'list', 'long', 'max', 'min', 'ord', 'pow', 'range', 'reversed',
119-
'round', 'slice', 'sorted', 'str', 'sum', 'tuple', 'type', 'unichr',
120-
'unicode', 'xrange', 'zip', 'filter', 'dict', 'set', 'next'
121-
]
122-
123-
safe_eval_model.allowed_functions.extend(safe_builtins)
124-
return safe_eval_model
125-
126-
def _setup_safe_eval(safe_eval_model, msg_class, topic):
127-
# allow-list topic builtins, msg attributes
128-
topic_builtins = [i for i in dir(topic) if not i.startswith('_')]
129-
safe_eval_model.attributes.extend(topic_builtins)
130-
# recursively get all nested message attributes
131-
msg_attributes = _get_nested_messages(msg_class)
132-
safe_eval_model.attributes.extend(msg_attributes)
133-
return safe_eval_model
134-
135-
13694
def main(args):
137-
with DirectNode(args) as node:
138-
topics = args.topic_name
95+
topics = args.topic_name
96+
if args.filter_expr:
97+
def expr_eval(expr):
98+
def eval_fn(m):
99+
return eval(expr)
100+
return eval_fn
101+
filter_expr = expr_eval(args.filter_expr)
102+
else:
139103
filter_expr = None
140-
# set up custom safe eval model for filter expression
141-
if args.filter_expr:
142-
safe_eval_model = _setup_base_safe_eval()
143-
for topic in topics:
144-
msg_class = get_msg_class(
145-
node, topic, blocking=True, include_hidden_topics=True)
146-
if msg_class is None:
147-
continue
148-
149-
safe_eval_model = _setup_safe_eval(safe_eval_model, msg_class, topic)
150-
151-
def expr_eval(expr):
152-
def eval_fn(m):
153-
safe_expression = Expr(expr, model=safe_eval_model)
154-
return eval(safe_expression.code)
155-
return eval_fn
156-
filter_expr = expr_eval(args.filter_expr)
157104

105+
with DirectNode(args) as node:
158106
_rostopic_hz(node.node, topics, qos_args=args, window_size=args.window_size,
159107
filter_expr=filter_expr, use_wtime=args.use_wtime)
160108

ros2topic/test/test_cli.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -938,19 +938,6 @@ def test_filtered_topic_hz(self):
938938
average_rate = float(average_rate_line_pattern.match(head_line).group(1))
939939
assert math.isclose(average_rate, 0.5, rel_tol=1e-2)
940940

941-
# check that use of eval() on hz verb cannot be exploited
942-
try:
943-
self.launch_topic_command(
944-
arguments=[
945-
'hz',
946-
'--filter',
947-
'__import__("os").system("cat /etc/passwd")',
948-
'/chatter'
949-
]
950-
)
951-
except ValueError as e:
952-
self.assertIn('Attribute system is not allowed', str(e))
953-
954941
@launch_testing.markers.retry_on_failure(times=5, delay=1)
955942
def test_topic_bw(self):
956943
with self.launch_topic_command(arguments=['bw', '/defaults']) as topic_command:

0 commit comments

Comments
 (0)