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

reading/writing xproto.SetupRequest is missing padding #24

Open
pphaneuf opened this issue Aug 3, 2014 · 11 comments
Open

reading/writing xproto.SetupRequest is missing padding #24

pphaneuf opened this issue Aug 3, 2014 · 11 comments

Comments

@pphaneuf
Copy link

pphaneuf commented Aug 3, 2014

The AuthorizationProtocolName and AuthorizationProtocolData fields are supposed to be padded to a multiple of 4, but it's not done:

b += int(v.AuthorizationProtocolNameLen)

b += int(v.AuthorizationProtocolNameLen)

I see some mentions of xgb.Pad() at line 5830, but it comes out a bit short when actually using it?

@aarzilli
Copy link
Contributor

How would one know that AuthorizationProtocolName and AuthorizationProtocolData are to be padded, short of reading xlib code?
Issue #12 was caused by strings being padded when they shouldn't have been.

Note that conn.go doesn't use SetupRequest to setup the connection (and that does pad the fields).

@pphaneuf
Copy link
Author

I did this by trying to write my own version of the connect() function that uses xproto.SetupRequestRead and xproto.SetupRequest.Bytes(), and got it wrong (server rejected the connection). I did some debugging by dumping buffers to stdout, and reading through them, as well as tracing what a normal client (I used xdpyinfo) was sending, and found some extra bytes.

I then looked at the connect() function itself, and found this:

https://github.com/BurntSushi/xgb/blob/master/conn.go#L57

It doesn't use the xproto.SetupRequest stuff (as you mention), but instead re-implement it "by hand", and there was the missing padding!

@pphaneuf
Copy link
Author

It'd be kind of nice if connect() used xproto.SetupRequest.Bytes(), no? It shouldn't be hard either (other than this bug!), would just replace lines 48 to 57 of connect() by populating a xproto.SetupRequest struct, and using xproto.SetupRequest.Bytes() at line 58...

@BurntSushi
Copy link
Owner

It's not that simple unfortunately. The xgb/xproto package depends on xgb. Copy and paste to fix it should be fine. It's not going to change.

@pphaneuf
Copy link
Author

Oh, I see... Many of those look like they're helper functions, but not all, getting the last reference out might be tricky.

I'd still like to use xproto.SetupRequestRead and xproto.SetupRequest.Bytes(), though, it'd be nice if they worked. 😉

@BurntSushi
Copy link
Owner

@pphaneuf
Copy link
Author

As in, "we already copy/paste functions wholesale, it's all right"? Sure, but if you copy/pasted xproto.SetupRequest.Bytes() and used it in connect(), you'd break it. 😃

If it wasn't going through the compiler, I'd have just sent a pull request, but I'm not as comfortable making that change to the compiler, sorry...

@aarzilli
Copy link
Contributor

If it wasn't going through the compiler, I'd have just sent a pull request, but I'm not as comfortable making that change to the compiler, sorry...

Yeah, that's exactly the problem: X11 padding rules aren't really clear (or documented at all). People will tell you that "it's just like C struct padding", except it isn't, not in any interesting place, at least.
I look at that SetupRequest definition in the XML and I see no reason why there would be padding.

@pphaneuf
Copy link
Author

Might be a bug in the XML, then? Here, it's clearly mentioned:

http://www.x.org/releases/current/doc/xproto/x11protocol.html#Encoding::Connection_Setup

I hear you on the padding rules not being the clearest!

@pphaneuf
Copy link
Author

(I'm referring to the "p" and "q" of the very first structure description there in the "Connection Setup" section)

@aarzilli
Copy link
Contributor

You may be onto something, I ran a capture myself and xcb proper seems to have similar problems. I'll inquire upstream.

ch11ng pushed a commit to ch11ng/xcb-proto that referenced this issue Feb 5, 2017
Fields  AuthorizationProtocolName and AuthorizationProtocolData of
SetupRequest should be padded:

http://www.x.org/releases/current/doc/xproto/x11protocol.html#Encoding::Connection_Setup

The problem was discovered by github user pphaneuf while trying to use xgb
to write his own implementation of the connection handshake. Neither xgb
nor xcb actually use code generated for SetupRequest for the handshake,
which is why this bug went unnoticed.

BurntSushi/xgb#24

Alessandro Arzilli.

Reviewed-by: Christian Linhart <chris@demorecorder.com>
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

3 participants