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

'printed' question #277

Open
jsmith173 opened this issue Mar 26, 2024 · 3 comments
Open

'printed' question #277

jsmith173 opened this issue Mar 26, 2024 · 3 comments
Labels

Comments

@jsmith173
Copy link

My protection function starts this way, so I'm appended the results = printed line to my code and returning with safe_globals["results"] at the end of this function. Is this the correct way to collect the print messages? Sometimes I have got error messages like this

"Line 2: SyntaxError: invalid syntax at statement: 'results = printed'"
However results = printed is not in the original code.

For the follwing input for example
@__builtins__

def interpret(code, my_dict, enable_exec=True):
	"""Interprets the given python code inside a safe execution environment"""
	warnings.filterwarnings('ignore') 
	  
	code += "\nresults = printed"
	byte_code = compile_restricted(
		code,
		filename="<string>",
		mode="exec",
	)
@d-maurer
Copy link
Contributor

d-maurer commented Mar 26, 2024 via email

@jsmith173
Copy link
Author

I think I did it previously as you suggests.
I have a function that decides the input is vulnerable or not. This function also should return the printed output (if has). In case of vulnerability it raises an exception. To return the printed output I have added a right hand access to the source code results = printed. However in some cases the compile or the exec report problem at this line however this line is not the part of the original code. This is a syntax error in the input of course but the problem is that the reported line is the extra added line.

So is there any other way to access the printed output? For example 'PrintCollector.txt'?

@d-maurer
Copy link
Contributor

d-maurer commented Mar 26, 2024 via email

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

No branches or pull requests

3 participants