T09 · Insecure Skill Coding Practices
- Location
lib/unity_templates.py:35- Finding
Generated C and CMake Injection Through Unvalidated Input
- Content
View full analysis
str: """Generate a complete Unity test file""" lines = [self.header] # Add include for the module under test lines.append(f'#include "{header_file}"') lines.append('') lines.append('/* Test cases */') lines.append('') test_calls = [] for func in functions: test_cases = self._generate_test_cases(func) ``` CMake files are also generated using unescaped paths: ```python def generate_cmake_integration(self, test_files: List[str]) -> str: """Generate CMakeLists.txt content for Unity tests""" content = '''# Unity Testing Framework ... ''' for test_file in test_files: test_name = test_file.replace('.c', '').replace('/', '_') content += f'add_unity_test({test_name} {test_file})\n' return content ``` Function names, types, and parameter names are similarly inserted directly into generated C syntax: ```python for func in functions: func_upper = func.name.upper() lines.append(f'') lines.append(f'/* Mock for {func.name} */') lines.append(f'extern bool {func.name}_called;') if func.return_type != 'void': lines.append(f'extern {func.return_type} {func.name}_return_value;') for param in func.parameters: lines.append(f'extern {param.type} {func.name}_{param.name}_expected;') ``` ```python for func in test_functions: lines.append(f'extern void {func}(void);') ... for func in test_functions: lines.append(f' RUN_TEST({func});') ``` ### Technical Analysis The generator treats caller-provided header paths, source paths, function names, parameter names, and type declarations as tru ...[truncated 2032 chars]- Remediation
View remediation
