From 8407ecc88c3b400eac0ae034532057bb6d82d263 Mon Sep 17 00:00:00 2001 From: Livia Zhu <37862641+livia01px2019@users.noreply.github.com> Date: Wed, 11 Oct 2023 19:50:29 -0400 Subject: [PATCH] Remove the marked_callsites function (#82) ## 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. --- crates/paralegal-policy/src/context.rs | 17 ++--------------- props/lemmy/src/main.rs | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/crates/paralegal-policy/src/context.rs b/crates/paralegal-policy/src/context.rs index d207c2caf5..feebdc08b2 100644 --- a/crates/paralegal-policy/src/context.rs +++ b/crates/paralegal-policy/src/context.rs @@ -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; @@ -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 + 'a, - marker: Marker, - ) -> impl Iterator + '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, diff --git a/props/lemmy/src/main.rs b/props/lemmy/src/main.rs index 19b37a988b..47011f98aa 100644 --- a/props/lemmy/src/main.rs +++ b/props/lemmy/src/main.rs @@ -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, }; @@ -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::>(); let mut influence_sink = c.ctrl_flow.0.iter().filter_map(|(src, dsts)| match src { @@ -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!");