diff src/libpam/environ.rs @ 143:ebb71a412b58

Turn everything into OsString and Just Walk Out! for strings with nul. To reduce the hazard surface of the API, this replaces most uses of &str with &OsStr (and likewise with String/OsString). Also, I've decided that instead of dealing with callers putting `\0` in their parameters, I'm going to follow the example of std::env and Just Walk Out! (i.e., panic!()). This makes things a lot less annoying for both me and (hopefully) users.
author Paul Fisher <paul@pfish.zone>
date Sat, 05 Jul 2025 22:12:46 -0400
parents a508a69c068a
children 56b559b7ecea
line wrap: on
line diff
--- a/src/libpam/environ.rs	Sat Jul 05 21:49:27 2025 -0400
+++ b/src/libpam/environ.rs	Sat Jul 05 22:12:46 2025 -0400
@@ -199,7 +199,7 @@
     #[test]
     fn test_split_kv() {
         fn test(input: &str, key: &str, value: &str) {
-            let data = CHeapString::new(input).unwrap();
+            let data = CHeapString::new(input);
             let key = os(key);
             let value = os(value);
 
@@ -216,10 +216,7 @@
         let ptrs: NonNull<Option<CHeapString>> = memory::calloc(strings.len() + 1);
         unsafe {
             for (idx, &text) in strings.iter().enumerate() {
-                ptr::write(
-                    ptrs.as_ptr().add(idx),
-                    Some(CHeapString::new(text).unwrap()),
-                )
+                ptr::write(ptrs.as_ptr().add(idx), Some(CHeapString::new(text)))
             }
             ptr::write(ptrs.as_ptr().add(strings.len()), None);
             EnvList::from_ptr(ptrs.cast())