archlinux / alpm.rs

Rust bindings for libalpm
GNU General Public License v3.0
112 stars 21 forks source link

Possible UB in AnyQuestion::question #20

Closed nico-abram closed 3 years ago

nico-abram commented 3 years ago

Hello, I'm not an alpm user, but I got here from this reddit post and I couldn't help but worry that AnyQuestion::question might be unsound. I see it in the public documentation here https://docs.rs/alpm/2.0.2/alpm/struct.AnyQuestion.html#method.question

Is there anything stopping a user from calling question twice in succession, generating two Question<'a> at the same time, which contain &mut's to the same thing, which (Because of the &mut aliasing rules) is insta UB (As far as I know)?

I do not have time right now but I will try to come up with an example later. Basically something of the form

let any_question = unimplemented!(); //Somehow get an any_question
let q1 = any_question.question();
let q2 = any_question.question();
// Both q1 and q2 have live &mut's to the same thing, which I think is UB
nico-abram commented 3 years ago

Oh, sorry, I just realized it's being converted to a *mut so this should not be a problem. I'm closing this

(I think there might still be issues w.r.t pointer provenance but that's a lot murkier)

Morganamilo commented 3 years ago

Yep it should be fine as the user can't hold references to the data. The stuff also isn't send to no multithreading issues.

But if some one can prove something wrong feel free.