{"record":{"id":"5a9193cb1d3658b4","repo":"peass-ng/PEASS-ng","slug":"function-func-in-module-path-is-imported-fro","errorCode":null,"errorMessage":"Function '{func}' in module {path} is imported from itself","messagePattern":"Function '(.+?)' in module (.+?) is imported from itself","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"linPEAS/builder/src/linpeasModule.py","lineNumber":193,"sourceCode":"        self.defined_funcs = self.extract_function_names()\n\n        # Check if the indicated dependencies are actually being used\n        for func in self.functions_used:\n            if func not in self.sh_code and func not in self.initial_functions and not \"peass{\" in self.sh_code:\n                raise Exception(f\"Used function '{func}' in module {path} doesn't exist in the module code\")\n        \n        for var in self.global_variables:\n            if var not in self.sh_code and not \"peass{\" in self.sh_code:\n                raise Exception(f\"Used variable '{var}' in module {path} doesn't exist in the module code\")\n        \n        for var in self.generated_global_variables:\n            if var not in self.sh_code:\n                raise Exception(f\"Generated variable '{var}' in module {path} doesn't exist in the module code\")\n        \n        # Check for funcs and vars imported from itself\n        for func in self.defined_funcs:\n            if func in self.functions_used:\n                raise Exception(f\"Function '{func}' in module {path} is imported from itself\")\n        \n        for var in self.global_variables:\n            if var in self.generated_global_variables:\n                raise Exception(f\"Variable '{var}' in module {path} is imported from itself\")\n        \n        # Check if all variables are correctly defined\n        linux_global_vars = [\n            \"OPTARG\",\n            \"PID\",\n            \"PPID\",\n            \"AWS_CONTAINER_CREDENTIALS_RELATIVE_URI\",\n            \"AWS_LAMBDA_RUNTIME_API\",\n            \"ECS_CONTAINER_METADATA_URI\",\n            \"ECS_CONTAINER_METADATA_URI_v4\",\n            \"IDENTITY_ENDPOINT\",\n            \"IDENTITY_HEADER\",\n            \"KUBERNETES_SERVICE_PORT_HTTPS\",\n            \"KUBERNETES_SERVICE_HOST\"","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/linPEAS/builder/src/linpeasModule.py#L175-L211","documentation":"LinpeasModule validates that a module's '# Functions Used:' metadata does not overlap with functions actually defined inside the module's own shell code. If a function listed as an external dependency is defined by the module itself, the builder raises this error, since importing a function from itself is a metadata mistake that would break the dependency-based build ordering.","triggerScenarios":"Instantiating LinpeasModule(path) during the linPEAS build when a module's sh code contains a definition like 'myfunc() {' AND 'myfunc' is also listed in the module's '# Functions Used:' metadata header.","commonSituations":"Contributors write a new .sh module, copy a function name into the '# Functions Used:' list thinking it's documentation, or refactor a module to define a function locally but forget to remove it from the imported-functions metadata.","solutions":["Remove the self-defined function name from the module's '# Functions Used:' metadata header","Or rename the function defined in the module code if it actually clashes with an imported one","Re-run the linPEAS builder to confirm the module passes validation"],"exampleFix":"# before\n# Functions Used: check_critial_root_procs, exec_with_jf\ncheck_critial_root_procs() { ... }\n# after\n# Functions Used: exec_with_jf\ncheck_critial_root_procs() { ... }","handlingStrategy":"validation","validationCode":"import re\ncode = open(module_path).read()\ndefined = set(re.findall(r'\\b(\\w+)\\s*\\(\\s*\\)\\s*{', code))\nused = extract_metadata_list(code, \"Functions Used\")\nassert not (defined & set(used)), f\"Functions imported from itself: {defined & set(used)}\"","typeGuard":"def is_valid_module_metadata(meta: dict) -> bool:\n    return not (set(meta.get(\"Functions Used\", [])) & set(extract_function_names(meta[\"code\"])))","tryCatchPattern":null,"preventionTips":["Keep '# Functions Used:' limited to helpers defined in other modules/base parts","Run the linPEAS builder locally before committing new modules","Grep for duplicate function names between metadata and code during review"],"tags":["build","metadata","validation"],"backgroundTag":"module-self-import","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}