diff src/libpam/question.rs @ 105:13b4d2a19674

Support Rust v1.75.0. This is the version included in Ubuntu 24.04 LTS and Debian Trixie, so it's old enough to have wide penetration without being too old to get new features (Debian Stable, I love you but v1.63 is just not going to work out).
author Paul Fisher <paul@pfish.zone>
date Thu, 26 Jun 2025 00:48:51 -0400
parents 94b51fa4f797
children 49d9e2b5c189
line wrap: on
line diff
--- a/src/libpam/question.rs	Wed Jun 25 16:56:56 2025 -0400
+++ b/src/libpam/question.rs	Thu Jun 26 00:48:51 2025 -0400
@@ -1,5 +1,6 @@
 //! Data and types dealing with PAM messages.
 
+use std::cell::Cell;
 #[cfg(feature = "linux-pam-extensions")]
 use crate::conv::{BinaryQAndA, RadioQAndA};
 use crate::conv::{ErrorMsg, InfoMsg, MaskedQAndA, Message, QAndA};
@@ -12,7 +13,7 @@
 use num_enum::{IntoPrimitive, TryFromPrimitive};
 use std::ffi::{c_void, CStr};
 use std::pin::Pin;
-use std::slice;
+use std::{ptr, slice};
 
 /// Abstraction of a collection of questions to be sent in a PAM conversation.
 ///
@@ -91,7 +92,7 @@
     /// Points to the memory address where the meat of `questions` is.
     /// **The memory layout of Vec is not specified**, and we need to return
     /// a pointer to the pointer, hence we have to store it here.
-    pointer: *const Question,
+    pointer: Cell<*const Question>,
     questions: Vec<Question>,
     _marker: Immovable,
 }
@@ -110,14 +111,16 @@
         let questions: Result<Vec<_>> = messages.iter().map(Question::try_from).collect();
         let questions = questions?;
         Ok(Self {
-            pointer: questions.as_ptr(),
+            pointer: Cell::new(ptr::null()),
             questions,
             _marker: Default::default(),
         })
     }
 
     fn ptr(self: Pin<&Self>) -> *const *const Question {
-        &self.pointer as *const *const Question
+        let me = self.get_ref();
+        me.pointer.set(self.questions.as_ptr());
+        me.pointer.as_ptr()
     }
 
     unsafe fn borrow_ptr<'a>(