|
| 1 | +"""Example utilities with intentional issues for testing code review.""" |
| 2 | + |
| 3 | +import pickle |
| 4 | +import subprocess |
| 5 | +import os |
| 6 | + |
| 7 | + |
| 8 | +def load_user_data(serialized_data): |
| 9 | + """Load user data from serialized format.""" |
| 10 | + # Security issue: unsafe pickle deserialization |
| 11 | + return pickle.loads(serialized_data) |
| 12 | + |
| 13 | + |
| 14 | +def run_command(user_input): |
| 15 | + """Run a shell command based on user input.""" |
| 16 | + # Security issue: command injection |
| 17 | + result = subprocess.run(f"echo {user_input}", shell=True, capture_output=True) |
| 18 | + return result.stdout.decode() |
| 19 | + |
| 20 | + |
| 21 | +def read_file(filename): |
| 22 | + """Read a file from disk.""" |
| 23 | + # Security issue: path traversal |
| 24 | + path = f"/data/{filename}" |
| 25 | + with open(path, "r") as f: |
| 26 | + return f.read() |
| 27 | + |
| 28 | + |
| 29 | +def divide_numbers(a, b): |
| 30 | + """Divide two numbers.""" |
| 31 | + # Code quality issue: no zero division check |
| 32 | + return a / b |
| 33 | + |
| 34 | + |
| 35 | +def process_items(items): |
| 36 | + """Process a list of items.""" |
| 37 | + results = [] |
| 38 | + for i in range(len(items)): |
| 39 | + # Code quality issue: inefficient iteration |
| 40 | + for j in range(len(items)): |
| 41 | + if items[i] == items[j]: |
| 42 | + results.append(items[i]) |
| 43 | + return results |
| 44 | + |
| 45 | + |
| 46 | +def get_user_by_id(user_id, connection): |
| 47 | + """Get user from database.""" |
| 48 | + # Security issue: SQL injection |
| 49 | + query = f"SELECT * FROM users WHERE id = {user_id}" |
| 50 | + return connection.execute(query) |
0 commit comments