forked from mstewartgallus/rust-xcb
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undefined behaviour in xproto::change_property #94
Labels
Comments
This was referenced Feb 5, 2021
This will be fixed with #105. pub trait PropEl {
const FORMAT: u8;
}
impl PropEl for u8 {
const FORMAT: u8 = 8;
}
impl PropEl for u16 {
const FORMAT: u8 = 16;
}
impl PropEl for u32 {
const FORMAT: u8 = 32;
}
impl PropEl for Atom {
const FORMAT: u8 = 32;
}
#[derive(Clone, Debug)]
pub struct ChangeProperty<'a, P: PropEl> {
pub mode: PropMode,
pub window: Window,
pub property: Atom,
pub r#type: Atom,
pub data: &'a [P],
} |
This was referenced Nov 14, 2021
v1.0.0 is released. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
xproto::change_property<T>
takes the argumentsformat: u8
and adata: &[T]
.The currently generated code
does not check for the case
core::mem::size_of::<T>() * 8 != format
, so a user could do something like this:xcb_change_property
will assume to get 128 bits of data indata_ptr
, but instead gets only 32 bits.Reading the last 12 bytes from
data_ptr
would cause UB.Also it is not desirable to get types, that are bigger than
format
.We could make
xproto::change_property
unsafe orpanic!
in the case ofcore::mem::size_of::<T>() * 8 != format
.Another option would be to only allow
u8
,u16
andu32
, since other formats are not allowed byxcb_change_property
.The text was updated successfully, but these errors were encountered: