summary refs log tree commit diff
path: root/ripple/minitrace
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-02-08 02:21:24 +0000
committeredef <edef@unfathomable.blue>2022-02-08 02:32:05 +0000
commit8c916a9913d8a5e49c8a41feec31eae212e04411 (patch)
tree4212a9aa34a791c10af18148e68d2ec081bed14e /ripple/minitrace
parent0c1fa0017ab4eb5f1a547e42347bb376868b60df (diff)
ripple/minitrace: enforce openat flags
Co-authored-by: V <v@unfathomable.blue>
Change-Id: Id848249e6b4a3de612d298d434c59889ba93b300
Diffstat (limited to 'ripple/minitrace')
-rw-r--r--ripple/minitrace/Cargo.toml3
-rw-r--r--ripple/minitrace/src/main.rs23
2 files changed, 20 insertions, 6 deletions
diff --git a/ripple/minitrace/Cargo.toml b/ripple/minitrace/Cargo.toml
index 8eb58f0..95de7a4 100644
--- a/ripple/minitrace/Cargo.toml
+++ b/ripple/minitrace/Cargo.toml
@@ -8,4 +8,5 @@ edition = "2018"
 
 [dependencies]
 nix = "0.23.1"
-anyhow = "1.0.43"
+anyhow = "1.0.53"
+bitflags = "1.3.2"
diff --git a/ripple/minitrace/src/main.rs b/ripple/minitrace/src/main.rs
index 6b7c044..424c6f2 100644
--- a/ripple/minitrace/src/main.rs
+++ b/ripple/minitrace/src/main.rs
@@ -4,6 +4,7 @@
 
 use {
 	anyhow::{bail, Context, Result},
+	bitflags::bitflags,
 	nix::{
 		libc,
 		sys::{
@@ -263,17 +264,19 @@ fn check_syscall(process: &Process, entry: SyscallEntry) -> bool {
 
 		// openat
 		257 => {
-			let [dirfd, pathname, _flags, _mode, _, _] = entry.args;
+			let [dirfd, pathname, flags, _mode, _, _] = entry.args;
 			const AT_FDCWD: i32 = -100;
 
 			if dirfd.try_into() == Ok(AT_FDCWD) {
 				return false;
 			}
 
-			println!(
-				"openat(AT_FDCWD, {:?}, ..)",
-				process.read_mem_cstr(pathname).unwrap()
-			);
+			let pathname = process.read_mem_cstr(pathname).unwrap();
+
+			let flags: i32 = flags.try_into().expect("openat(2) flags don't fit in i32");
+			let flags = OpenFlags::from_bits(flags).expect("unknown openat flags");
+
+			println!("openat(AT_FDCWD, {:?}, {:?}, ..)", pathname, flags);
 		}
 
 		// newfstatat
@@ -296,3 +299,13 @@ fn check_syscall(process: &Process, entry: SyscallEntry) -> bool {
 	}
 	true
 }
+
+bitflags! {
+	struct OpenFlags: i32 {
+		const WRONLY  = 0o00000001;
+		const CREAT   = 0o00000100;
+		const NOCTTY  = 0o00000400;
+		const TRUNC   = 0o00001000;
+		const CLOEXEC = 0o02000000;
+	}
+}