Call chain analysis exception
还没有人认领这个 Issue。
评估
调研方向
从 issue 中的两个 DataFlow::ConfigSig 示例开始,将成功路径与失败的 isAdditionalFlowStep 配置进行比较。跟踪 ReadObjectSource、GetHostAddressSource、MethodCall 和 RefType 的使用方式,然后根据所示的 HashMap 和 URL 调用链验证行为。完成的标准是解释清楚路径行为,并且该配置找到预期路径,或记录其无法找到该路径的原因。
由索引模型根据 Issue 内容生成。
描述
Hello, I'm not familiar with isAdditionalFlowStep, so there might be some issues with the rule I wrote. Could you please help me take a look?
public class HashMap<K,V> extends AbstractMap<K,V>
// 4、key
implements Map<K,V>, Cloneable, Serializable {
static final int hash(Object key) {
int h;
// 5、key.hashCode()
return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}
//1、s
private void readObject(java.io.ObjectInputStream s)
throws IOException, ClassNotFoundException {
s.defaultReadObject();
reinitialize();
if (loadFactor <= 0 || Float.isNaN(loadFactor))
throw new InvalidObjectException("Illegal load factor: " +
loadFactor);
s.readInt();
int mappings = s.readInt();
if (mappings < 0)
throw new InvalidObjectException("Illegal mappings count: " +
mappings);
else if (mappings > 0) {
float lf = Math.min(Math.max(0.25f, loadFactor), 4.0f);
float fc = (float)mappings / lf + 1.0f;
int cap = ((fc < DEFAULT_INITIAL_CAPACITY) ?
DEFAULT_INITIAL_CAPACITY :
(fc >= MAXIMUM_CAPACITY) ?
MAXIMUM_CAPACITY :
tableSizeFor((int)fc));
float ft = (float)cap * lf;
threshold = ((cap < MAXIMUM_CAPACITY && ft < MAXIMUM_CAPACITY) ?
(int)ft : Integer.MAX_VALUE);
@SuppressWarnings({"rawtypes","unchecked"})
Node<K,V>[] tab = (Node<K,V>[])new Node[cap];
table = tab;
for (int i = 0; i < mappings; i++) {
@SuppressWarnings("unchecked")
// 2、keu
K key = (K) s.readObject();
@SuppressWarnings("unchecked")
V value = (V) s.readObject();
// 3、hash(key)
putVal(hash(key), key, value, false, false);
}
}
}
}
public final class URL implements java.io.Serializable {
transient URLStreamHandler handler;
// 6
public synchronized int hashCode() {
if (hashCode != -1)
return hashCode;
// 7、handler.hashCode(this)
hashCode = handler.hashCode(this);
return hashCode;
}
}
public abstract class URLStreamHandler {
// 8、u
protected int hashCode(URL u) {
int h = 0;
String protocol = u.getProtocol();
if (protocol != null)
h += protocol.hashCode();
// 9、getHostAddress(u);
InetAddress addr = getHostAddress(u);
if (addr != null) {
h += addr.hashCode();
} else {
String host = u.getHost();
if (host != null)
h += host.toLowerCase().hashCode();
}
String file = u.getFile();
if (file != null)
h += file.hashCode();
if (u.getPort() == -1)
h += getDefaultPort();
else
h += u.getPort();
String ref = u.getRef();
if (ref != null)
h += ref.hashCode();
return h;
}
}
The path query from HashMap.readObject to HashMap.hash->h = key.hashCode() has been successfully completed.
class ReadObjectSource extends DataFlow::Node {
ReadObjectSource() {
exists(Method m |
m.getDeclaringType().getASupertype() instanceof TypeSerializable and
m.hasName("readObject") and
m.getDeclaringType().hasQualifiedName("java.util", "HashMap") and
this.asParameter() = m.getParameter(0)
)
}
}
class GetHostAddressSource extends DataFlow::Node {
GetHostAddressSource() {
exists(MethodCall call |
call.getMethod().hasName("hashCode") and
call.getMethod().getDeclaringType().hasQualifiedName("java.lang", "Object") and
this.asExpr() = call.getQualifier()
)
}
}
module LiteralToURLConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
source instanceof ReadObjectSource
}
predicate isSink(DataFlow::Node sink) {
sink instanceof GetHostAddressSource
}
}

However, the path from HashMap.readObject to HashMap.hash->h = key.hashCode() cannot be found as shown below, and it directly jumps to the hashCode method in other classes.
class ReadObjectSource extends DataFlow::Node {
ReadObjectSource() {
exists(Method m |
m.getDeclaringType().getASupertype() instanceof TypeSerializable and
m.hasName("readObject") and
m.getDeclaringType().hasQualifiedName("java.util", "HashMap") and
this.asParameter() = m.getParameter(0)
)
}
}
class GetHostAddressSource extends DataFlow::Node {
GetHostAddressSource() {
exists(MethodCall call |
call.getMethod().hasName("getHostAddress") and
this.asExpr() = call.getArgument(0)
)
}
}
module LiteralToURLConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
source instanceof ReadObjectSource
}
predicate isSink(DataFlow::Node sink) {
sink instanceof GetHostAddressSource
}
predicate isAdditionalFlowStep(DataFlow::Node source, DataFlow::Node sink){
source instanceof ReadObjectSource and
exists(
MethodCall call,
RefType rt
|
source instanceof ReadObjectSource and
sink.asExpr() = call.getQualifier() and
rt = sink.getType().(RefType)
)
}
}

- 主要语言
- CodeQL
- 星标
- 10.1k
- 派生
- 2.1k
- 平均合并
- 2 天 16 小时
- 30 天内合并 PR
- 143
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
github/codeql 的其他 Issue
-
agentic-workflows
难度 2/5 1-3 小时 新手友好度 70/100
-
false-positive javascript
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 78/100
-
false-positive
难度 2/5 1-3 小时 新手友好度 70/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
palladius/rails8-app-on-gcp#145 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
elastic/gradle-plugins#156 ·
-
area:workflow bug ready-for-agent
难度 2/5 1-3 小时 新手友好度 75/100
fil-donadoni/tolaria#4409 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
dotenvx/dotenv-vscode#139 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
Fission-AI/OpenSpec#1960 ·