Skip to content

FEATURE: use a safer eval code, with limited arithmetic capabilities. #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

amilcarlucas
Copy link
Collaborator

No description provided.

Copy link
Contributor

github-actions bot commented Feb 6, 2025

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
5558 2730 49% 0% 🟢

New Files

File Coverage Status
ardupilot_methodic_configurator/safe_eval.py 90% 🟢
TOTAL 90% 🟢

Modified Files

No covered modified files...

updated for commit: 284b22f by action🐍

Copy link
Contributor

github-actions bot commented Feb 21, 2025

Test Results

  2 files    2 suites   1m 33s ⏱️
420 tests 419 ✅ 1 💤 0 ❌
840 runs  838 ✅ 2 💤 0 ❌

Results for commit 284b22f.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR introduces a safe_eval implementation for arithmetic expressions with limited mathematical functions and operators while adding comprehensive tests to ensure its correctness and security.

  • Introduces a secure evaluator module (safe_eval.py) that parses and evaluates arithmetic expressions
  • Provides extensive test cases (tests/test_safe_eval.py) to cover basic arithmetic, math functions, operator precedence, nested expressions, error handling, and security against code injection

Reviewed Changes

File Description
tests/test_safe_eval.py Comprehensive tests covering arithmetic, math functions, and errors
ardupilot_methodic_configurator/safe_eval.py Implementation of a secure evaluator using Python's ast module

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

ardupilot_methodic_configurator/safe_eval.py:25

  • [nitpick] Consider renaming the inner variable in the list comprehension (e.g., 'func') to avoid shadowing the parameter 'x'.
if x not in [x for x in dir(math) if "__" not in x]:

Comment on lines +42 to +43
ast.Call: checkmath,
ast.BinOp: ast.BinOp,
Copy link
Preview

Copilot AI Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'bin_ops' dictionary includes extraneous keys (ast.Call and ast.BinOp) that are not used for arithmetic operations and may lead to confusion; consider removing them.

Suggested change
ast.Call: checkmath,
ast.BinOp: ast.BinOp,
# ast.Call and ast.BinOp removed as they are not used for arithmetic operations

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant