Skip to content

Commit

Permalink
add extra comment about use-after-free
Browse files Browse the repository at this point in the history
  • Loading branch information
squell committed Sep 6, 2024
1 parent 8a0a205 commit 70e2a3a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/pam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ impl<C: Converser> PamContext<C> {
}

// SAFETY: curr_str was obtained via libc::malloc() so we are responsible for freeing it.
// At this point, curr_str is also the only remaining pointer/reference to that allocated data
// (the data was copied above), so it can be deallocated without risk of use-after-free errors.
unsafe { libc::free(curr_str.as_ptr().cast()) };
// SAFETY: curr_env was not NULL, so it was not the last element in the list and so PAM
// ensures that the next offset also is a valid pointer, and points to valid data.
Expand Down

0 comments on commit 70e2a3a

Please sign in to comment.