Skip to content
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

fix security #62626

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions python/paddle/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import os
import platform
import re
import site
import sys
import warnings
Expand Down Expand Up @@ -193,8 +194,18 @@ def run_shell_command(cmd):
return out.decode('utf-8').strip()


def is_valid_filename(filename):
pattern = re.compile(r'^[a-zA-Z0-9_.-]+$')
if pattern.match(filename):
return True
else:
return False


def get_dso_path(core_so, dso_name):
if core_so and dso_name:
assert is_valid_filename(core_so), 'core_so must be a file name.'
assert is_valid_filename(dso_name), 'dso_name must be a file name.'
return run_shell_command(
f"ldd {core_so}|grep {dso_name}|awk '{{print $3}}'"
)
Expand Down