Skip to content

Commit

Permalink
Remove the marked_callsites function (#82)
Browse files Browse the repository at this point in the history
## What Changed?

Removed the `marked_callsites` function and replaced it with
`marked_sinks` and `filter` in the Lemmy property.

## Why Does It Need To?

Function is misleading and just uses `marked_sinks`.

## Checklist

- [x] Above description has been filled out so that upon quash merge we
have a
  good record of what changed.
- [x] New functions, methods, types are documented. Old documentation is
updated
  if necessary
- [x] Documentation in Notion has been updated
- [ ] Tests for new behaviors are provided
  - [ ] New test suites (if any) ave been added to the CI tests (in
`.github/workflows/rust.yml`) either as compiler test or integration
test.
*Or* justification for their omission from CI has been provided in this
PR
    description.
  • Loading branch information
livia01px2019 committed Oct 11, 2023
1 parent 3eec156 commit 8407ecc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
17 changes: 2 additions & 15 deletions crates/paralegal-policy/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{io::Write, process::exit, sync::Arc};

use paralegal_spdg::{
Annotation, CallSite, CallSiteOrDataSink, Ctrl, DataSink, DataSource, DefKind, HashMap,
HashSet, Identifier, MarkerAnnotation, MarkerRefinement, ProgramDescription,
Annotation, CallSiteOrDataSink, Ctrl, DataSink, DataSource, DefKind, HashMap, HashSet,
Identifier, MarkerAnnotation, MarkerRefinement, ProgramDescription,
};

pub use paralegal_spdg::rustc_portable::DefId;
Expand Down Expand Up @@ -241,19 +241,6 @@ impl Context {
})
}

/// Returns an iterator over all the call sites marked with `marker` out of the provided `dsts`.
pub fn marked_callsites<'a>(
&'a self,
dsts: impl IntoIterator<Item = &'a DataSink> + 'a,
marker: Marker,
) -> impl Iterator<Item = &'a CallSite> + 'a {
self.marked_sinks(dsts, marker)
.filter_map(|sink| match sink {
DataSink::Argument { function, .. } => Some(function),
_ => None,
})
}

/// Returns an iterator over the data sources within controller `c` that have type `t`.
pub fn srcs_with_type<'a>(
&self,
Expand Down
17 changes: 14 additions & 3 deletions props/lemmy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::Arc;

use paralegal_policy::{
assert_error,
paralegal_spdg::{CallSite, Ctrl, DataSource, Identifier},
paralegal_spdg::{CallSite, Ctrl, DataSink, DataSource, Identifier},
Marker, PolicyContext,
};

Expand All @@ -22,7 +22,11 @@ impl CommunityProp {
fn flow_to_auth(&self, c: &Ctrl, sink: &CallSite, marker: Marker) -> bool {
let auth_callsites = self
.cx
.marked_callsites(c.data_flow.0.values().flatten(), marker)
.marked_sinks(c.data_flow.0.values().flatten(), marker)
.filter_map(|sink| match sink {
DataSink::Argument { function, .. } => Some(function),
_ => None,
})
.collect::<HashSet<_>>();

let mut influence_sink = c.ctrl_flow.0.iter().filter_map(|(src, dsts)| match src {
Expand All @@ -40,7 +44,14 @@ impl CommunityProp {

for c in self.cx.desc().controllers.values() {
for dsts in c.data_flow.0.values() {
for write_sink in self.cx.marked_callsites(dsts, db_community_write) {
for write_sink in
self.cx
.marked_sinks(dsts, db_community_write)
.filter_map(|sink| match sink {
DataSink::Argument { function, .. } => Some(function),
_ => None,
})
{
let ok = self.flow_to_auth(c, write_sink, community_delete_check)
&& self.flow_to_auth(c, write_sink, community_ban_check);
assert_error!(self.cx, !ok, "Found a failure!");
Expand Down

0 comments on commit 8407ecc

Please sign in to comment.