aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-02-21 12:18:41 +0100
committerPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-03-30 13:52:32 +0200
commitacf5db71524e56aef7a0071be96299b976760454 (patch)
tree559ad736cdac453f0d92d9833665d07f235f4abd
parent0f1723455cea2d51630be79aceddcfc3ed8a4771 (diff)
downloadgcc-acf5db71524e56aef7a0071be96299b976760454.zip
gcc-acf5db71524e56aef7a0071be96299b976760454.tar.gz
gcc-acf5db71524e56aef7a0071be96299b976760454.tar.bz2
libproc_macro: Custom Clone for Ident
The internal Ident structure contains a foreign allocated byte array, it's Clone trait cannot be derived automatically as the array would not be cloned correctly, only the pointer. This would lead to use after-free. ChangeLog: * librust/proc_macro/rust/bridge/ident.rs: Implement Clone for Ident. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--librust/proc_macro/rust/bridge/ident.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/librust/proc_macro/rust/bridge/ident.rs b/librust/proc_macro/rust/bridge/ident.rs
index 1c08a00..dbfa649 100644
--- a/librust/proc_macro/rust/bridge/ident.rs
+++ b/librust/proc_macro/rust/bridge/ident.rs
@@ -7,10 +7,11 @@ extern "C" {
fn Ident__new(string: *const c_uchar, len: u64) -> Ident;
fn Ident__new_raw(string: *const c_uchar, len: u64) -> Ident;
fn Ident__drop(ident: *const Ident);
+ fn Ident__clone(ident: *const Ident) -> Ident;
}
#[repr(C)]
-#[derive(Clone, Debug)]
+#[derive(Debug)]
pub struct Ident {
pub(crate) is_raw: bool,
pub(crate) val: *const c_uchar,
@@ -59,3 +60,9 @@ impl fmt::Display for Ident {
)
}
}
+
+impl Clone for Ident {
+ fn clone(&self) -> Self {
+ unsafe { Ident__clone(self as *const Ident) }
+ }
+}