Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nullable param detection #4

Open
Medowhill opened this issue Mar 10, 2025 · 0 comments
Open

Fix nullable param detection #4

Medowhill opened this issue Mar 10, 2025 · 0 comments
Assignees

Comments

@Medowhill
Copy link
Contributor

nopcrat/src/ai/analysis.rs

Lines 506 to 536 in 97f4dc2

fn find_nullable_params(
&self,
result: &BTreeMap<Location, BTreeMap<(MustPathSet, MustPathSet), AbsState>>,
) -> BTreeSet<usize> {
let mut nonnull_locs = vec![BTreeSet::new(); self.info.inputs];
let mut null_locs = vec![BTreeSet::new(); self.info.inputs];
for (loc, sts) in result {
for (_, nulls) in sts.keys() {
for i in 0..self.info.inputs {
let path = AbsPath(vec![i + 1]);
if nulls.contains(&path) {
null_locs[i].insert(*loc);
} else {
nonnull_locs[i].insert(*loc);
}
}
}
}
nonnull_locs
.into_iter()
.zip(null_locs)
.enumerate()
.filter_map(|(i, (nonnull, null))| {
if null.is_subset(&nonnull) {
None
} else {
Some(i + 1)
}
})
.collect()
}

지금은 param value가 null일 때 도달 가능한 프로그램 지점이 null이 아닐 때 도달 가능한 프로그램 지점의 부분집합이면, 해당 param이 output param이 될 수 있음.

x가 output param이 아닌 경우:

if x.is_null() { foo(); }

x가 output param인 경우:

if !x.is_null() { *x = 0; }

그런데 사실 null이 아닐 때만 도달 가능한 프로그램 지점이 있는 것도 문제가 될 수 있음.

지금은 x를 output param으로 판단하지만 사실 그러면 안되는 경우:

if !x.is_null() { foo(); }

따라서 이 문제를 해결해야 함. 한 가지 방법은, 다음 두 개가 같을 때만 output param으로 하는 것:

  • x가 null일 때 도달 가능한 지점
  • x가 null일 아닐 때 도달 가능한 지점 중 *x = v;를 제외한 것
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants