1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

x11fwd.c: Handle empty display number in authfile

An empty display number matches any display number.

For example xauth list :1 returns auth cookies where the
display number matches and where the display number is empty.
This commit is contained in:
Volker Rümelin 2018-11-28 20:49:34 +01:00 committed by Simon Tatham
parent 84d5eb4287
commit dfe88e792a

View File

@ -540,7 +540,7 @@ void x11_get_auth_from_authfile(struct X11Display *disp,
family = get_uint16(src); family = get_uint16(src);
addr = get_string_xauth(src); addr = get_string_xauth(src);
displaynum_string = mkstr(get_string_xauth(src)); displaynum_string = mkstr(get_string_xauth(src));
displaynum = atoi(displaynum_string); displaynum = displaynum_string[0] ? atoi(displaynum_string) : -1;
sfree(displaynum_string); sfree(displaynum_string);
protoname = get_string_xauth(src); protoname = get_string_xauth(src);
data = get_string_xauth(src); data = get_string_xauth(src);
@ -570,9 +570,8 @@ void x11_get_auth_from_authfile(struct X11Display *disp,
* authority entries for Unix-domain displays on * authority entries for Unix-domain displays on
* several machines without them clashing). * several machines without them clashing).
* *
* - 'displaynum' is the display number. I've no idea why * - 'displaynum' is the display number. An empty display
* .Xauthority stores this as a string when it has a * number is a wildcard for any display number.
* perfectly good integer format, but there we go.
* *
* - 'protoname' is the authorisation protocol, encoded as * - 'protoname' is the authorisation protocol, encoded as
* its canonical string name (i.e. "MIT-MAGIC-COOKIE-1", * its canonical string name (i.e. "MIT-MAGIC-COOKIE-1",
@ -582,7 +581,8 @@ void x11_get_auth_from_authfile(struct X11Display *disp,
* binary form. * binary form.
*/ */
if (disp->displaynum < 0 || disp->displaynum != displaynum) if (disp->displaynum < 0 ||
(displaynum >= 0 && disp->displaynum != displaynum))
continue; /* not the one */ continue; /* not the one */
for (protocol = 1; protocol < lenof(x11_authnames); protocol++) for (protocol = 1; protocol < lenof(x11_authnames); protocol++)