Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/checker/taint/common-kit/source-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ function introduceFuncArgTaintByRuleConfig(scope: any, node: any, res: any, func
}
break
}
} else if (call.name === tspec.fsig) {
const args = prepareArgs(res, undefined, tspec)
for (let i = 0; i < args.length; i++) {
markTaintSource(args[i], { path: node, kind: tspec.kind })
}
break
}
Comment on lines +137 to 143
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic in this block is identical to the one in lines 131-135. This code duplication should be avoided.

Additionally, the condition call.name === tspec.fsig is suspicious. call is a CallExpression node, which typically does not have a name property. This might be a typo for call.callee.name. Please verify the logic and consider refactoring to remove the duplication.

}
}
Expand Down
10 changes: 8 additions & 2 deletions src/engine/analyzer/python/common/python-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,15 @@ class PythonAnalyzer extends (Analyzer as any) {

let targetPath = normalizedPath
if (!targetPath.endsWith('.py')) {
const mouduleFile = `${targetPath}/${modulePath}.py`
const moduleInitFile = path.join(`${targetPath}/${modulePath}`, '__init__.py')
// 可能是包目录,检查是否有 __init__.py
const initFile = path.join(targetPath, '__init__.py')
if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(initFile))) {
if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(mouduleFile))) {
targetPath = mouduleFile
} else if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(moduleInitFile))) {
targetPath = moduleInitFile
} else if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(initFile))) {
targetPath = initFile
Comment on lines +478 to 487
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a typo in the variable name mouduleFile. It should be moduleFile.

Additionally, constructing paths using string concatenation with / is not platform-independent and can cause issues on Windows. It's better to use path.join() for all path constructions to ensure portability.

Suggested change
const mouduleFile = `${targetPath}/${modulePath}.py`
const moduleInitFile = path.join(`${targetPath}/${modulePath}`, '__init__.py')
// 可能是包目录,检查是否有 __init__.py
const initFile = path.join(targetPath, '__init__.py')
if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(initFile))) {
if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(mouduleFile))) {
targetPath = mouduleFile
} else if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(moduleInitFile))) {
targetPath = moduleInitFile
} else if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(initFile))) {
targetPath = initFile
const moduleFile = path.join(targetPath, `${modulePath}.py`);
const moduleInitFile = path.join(targetPath, modulePath, '__init__.py');
// 可能是包目录,检查是否有 __init__.py
const initFile = path.join(targetPath, '__init__.py');
if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(moduleFile))) {
targetPath = moduleFile;
} else if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(moduleInitFile))) {
targetPath = moduleInitFile;
} else if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(initFile))) {
targetPath = initFile;

} else {
// 尝试添加 .py 扩展名
Expand Down Expand Up @@ -557,7 +563,7 @@ class PythonAnalyzer extends (Analyzer as any) {
} else if (prop.type !== 'Identifier' && prop.type !== 'Literal') {
resolved_prop = this.processInstruction(scope, prop, state)
}
if (prop.type === 'Identifier' && prop.name === '__init__' && prop.parent?.parent?.type === 'CallExpression') {
if (prop.type === 'Identifier' && (prop.name === '__init__' || prop.name === '__class__') && prop.parent?.parent?.type === 'CallExpression') {
resolved_prop.name = '_CTOR_'
}
if (!resolved_prop) return defscope
Expand Down