静态代码分析-概念:敏感性

1. 流敏感(flow-sensitive)

程序代码执行顺序的分析

代码1:

String a = "test";
a = b;

代码2:

String a = b;
a = "test";

区别:

流不敏感无法识别代码片段a为常量,流敏感能识别到a为常量

常用于:指针别名,指向分析,常量分析

2. 路径敏感(path-sensitive)

依据条件分支语句的不同谓词,计算不同的分析信息

代码:

String name;
int x;
if (x > 0) {
    name = b;
} else {
    name = "test";
}

路径不敏感:不考虑分支,name 为test∨b

路径敏感:在考虑分支的情况下name为test常量

路径敏感保存分支条件,可对分支进行约束求解,分析分支可达性,常面对的问题:“路径爆炸”(path explosion)或“无穷搜索空间”(infinite search space)

3. 上下文敏感(context-sensitive)

过程间分析( Interprocedural Analysis),考虑函数调用的上下文信息


public static void main(String[] args) {
    String name = test(3); 
}

private static String test(int x) {
    if (x > 0) {
        return "test1";
    } else {
        return "test2";
    }
}

上下文:指在函数调用过程中所包含传递的参数,全局变量等信息

4.    域敏感(field-sensitive)

对对象属性,集合成员等进行分析

class Test {
    private String name;
}

Map<String, String> maps = new HashMap<String,String>();
maps.put("name","test");

对对象属性name, 以及maps.key:name 进行标记分析

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值