Skip to content
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

Indexing into invalid replies causes panic #5

Open
fiorematteo opened this issue Oct 18, 2022 · 0 comments
Open

Indexing into invalid replies causes panic #5

fiorematteo opened this issue Oct 18, 2022 · 0 comments

Comments

@fiorematteo
Copy link
Contributor

I'm having trouble with getting the _NET_ACTIVE_WINDOW atom right after X is started.
Most likely it's due to the fact that at that time the atom is not set.
Xcb doesn't returns an error and instead returns an invalid reply.
After that the bogus reply is passed to this from function.

impl From<xcb::x::GetPropertyReply> for GetActiveWindowReply {
    fn from(reply: xcb::x::GetPropertyReply) -> Self {
        GetActiveWindowReply {
            window: unsafe { xcb::x::Window::new(reply.value::<u32>()[0]) },
        }
    }
}

reply.value::<u32>() returns an empty slice so indexing it panics.

This is what a bad reply looks like:

&reply.bytes_after() = 0
&reply.length() = 0
&reply.r#type() = Atom { res_id: 0, }
&reply.response_type() = 1
&reply.sequence() = 167
&reply.value::<u32>() = []

Trying to debug print reply blows up with this scary error

&reply = thread 'main' panicked at 'internal error: entered unreachable code: impossible prop format: 0', /home/matteo/progetti/rust/barust/target/release/build/xcb-cc126fbef2fc4c4d/out/xproto.rs:13665:23

It looks like this should be a problem with other atoms but I didn't try.
I think this should be fixed in the caller (wait_for_reply and wait_for_reply_unchecked) by checking if the returned reply has 0 length.
Something like this:

    pub fn wait_for_reply<C>(&self, cookie: C) -> xcb::Result<C::Reply>
    where
        C: EwmhPropertyCookieChecked,
    {
        let xcb_reply = self.con.wait_for_reply(cookie.inner());
        match xcb_reply{
            Ok(reply) => {
                if reply.length() == 0{
                    return Err(/*not sure which error to use here*/)
                }
                else{
                    Ok(reply.into())
                }
            },
            Err(e) => Err(e),
        }
    }
@fiorematteo fiorematteo changed the title Indexing into invalid replies causes Indexing into invalid replies causes panic Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant