[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20231201104831.2195715-1-aliceryhl@google.com>
Date: Fri, 1 Dec 2023 10:48:31 +0000
From: Alice Ryhl <aliceryhl@...gle.com>
To: benno.lossin@...ton.me
Cc: a.hindborg@...sung.com, alex.gaynor@...il.com,
aliceryhl@...gle.com, arve@...roid.com, bjorn3_gh@...tonmail.com,
boqun.feng@...il.com, brauner@...nel.org, cmllamas@...gle.com,
dan.j.williams@...el.com, dxu@...uu.xyz, gary@...yguo.net,
gregkh@...uxfoundation.org, joel@...lfernandes.org,
keescook@...omium.org, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, maco@...roid.com, ojeda@...nel.org,
peterz@...radead.org, rust-for-linux@...r.kernel.org,
surenb@...gle.com, tglx@...utronix.de, tkjos@...roid.com,
viro@...iv.linux.org.uk, wedsonaf@...il.com, willy@...radead.org
Subject: Re: [PATCH 3/7] rust: security: add abstraction for secctx
Benno Lossin <benno.lossin@...ton.me> writes:
> On 11/29/23 14:11, Alice Ryhl wrote:
>> + /// Returns the bytes for this security context.
>> + pub fn as_bytes(&self) -> &[u8] {
>> + let mut ptr = self.secdata;
>> + if ptr.is_null() {
>> + // Many C APIs will use null pointers for strings of length zero, but
>
> I would just write that the secctx API uses null pointers to denote a
> string of length zero.
I don't actually know whether it can ever be null, I just wanted to stay
on the safe side.
>> + // `slice::from_raw_parts` doesn't allow the pointer to be null even if the length is
>> + // zero. Replace the pointer with a dangling but non-null pointer in this case.
>> + debug_assert_eq!(self.seclen, 0);
>
> I am feeling a bit uncomfortable with this, why can't we just return
> an empty slice in this case?
I can do that, but to be clear, what I'm doing here is also definitely
okay.
Alice
Powered by blists - more mailing lists