Skip to content

Commit f630d7a

Browse files
Merge pull request #33 from pushkar-hue/main
Fix pysearch command validation to only allow python scripts ( #30)
2 parents 822068b + 8daabde commit f630d7a

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

search.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,31 @@
77

88
#pysearch is a tool to debug incoming errors from python scripts
99
cmd = input("py-search > ")
10-
try:
11-
process = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE,
12-
stderr=subprocess.PIPE, cwd=".")
1310

14-
stdout, stderr = process.communicate()
11+
# Added input validation to restrict commands to only 'python' or 'python3'
12+
if not (cmd.startswith("python") or cmd.startswith("python3")):
13+
print("QuickOverflow Error: Only 'python' or 'python3' commands are allowed.")
14+
print("Use QuickOverflow’s search feature to browse directories instead.")
1515

16-
print(stdout.decode('utf-8'))
17-
print(stderr.decode('utf-8'))
16+
else:
17+
try:
18+
process = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE,
19+
stderr=subprocess.PIPE, cwd=".")
1820

19-
pyoverflow3.submit_error(str(stderr),2)
21+
stdout, stderr = process.communicate()
2022

21-
except Exception as e:
22-
print("QuickOverflow Error: " + e)
23+
print(stdout.decode('utf-8'))
24+
print(stderr.decode('utf-8'))
25+
26+
# Checking if there's an actual error
27+
error_output = stderr.decode('utf-8')
28+
if error_output:
29+
# wrapping the error in a try-except block to handle any exceptions
30+
try:
31+
pyoverflow3.submit_error(str(error_output),2)
32+
except Exception as e:
33+
print("QuickOverflow Error: " + str(e))
34+
35+
# Existing error handling retained and cleaned up to formate error messages properly
36+
except Exception as e:
37+
print("QuickOverflow Error: " + str(e))

0 commit comments

Comments
 (0)