[REPOST PATCH xauth] Make matching algorithm mimic XauGet*AuthByAddr

Egbert Eich eich at freedesktop.org
Wed Aug 14 13:01:48 PDT 2013


On Wed, Aug 14, 2013 at 06:53:05PM +0200, walter harms wrote:
> 
> 
> Am 14.08.2013 17:10, schrieb Egbert Eich:
> > Xlib (xcb) uses XauGetBestAuthByAddr() when looking for an
> > authorization. 'xauth [n]list $DISPLAY' used a slightly
> > stricter algorithm which doesn't find a possible authorization
> > for cases where either the family is set to FamilyWild or
> > address the address length is 0.
> > 
> > Signed-off-by: Egbert Eich <eich at freedesktop.org>
> > ---
> >  process.c | 12 +++++++-----
> >  1 file changed, 7 insertions(+), 5 deletions(-)
> > 
> > diff --git a/process.c b/process.c
> > index a9466a7..0e12a56 100644
> > --- a/process.c
> > +++ b/process.c
> > @@ -1064,11 +1064,13 @@ eq_auth(Xauth *a, Xauth *b)
> >  static int
> >  match_auth_dpy(register Xauth *a, register Xauth *b)
> >  {
> > -    return ((a->family == b->family &&
> > -	     a->address_length == b->address_length &&
> > -	     a->number_length == b->number_length &&
> > -	     memcmp(a->address, b->address, a->address_length) == 0 &&
> > -	     memcmp(a->number, b->number, a->number_length) == 0) ? 1 : 0);
> > +    return (((a->family == FamilyWild || b->family == FamilyWild ||
> > +	     (a->family == b->family &&
> > +	      a->address_length == b->address_length &&
> > +	      memcmp(a->address, b->address, a->address_length) == 0)) &&
> > +	    (a->number_length == 0 || b->number_length == 0 ||
> > +	     (a->number_length == b->number_length &&
> > +	      memcmp(a->number, b->number, a->number_length) == 0))) ? 1 : 0);
> >  }
> >  
> making this a bit more readable would be a nice add on.
> here my suggestion:

I believe this is incorrect:

assume: a->family := FamilyWild       a->address_length := 0  
        b->family := FamilyInternet   b->address_length := 5
> 
> /* Families do not match */
> if ( a->family != FamilyWild && b->family != FamilyWild || a->family != b->family)
> 	return 0;

     if (0 && 1 || 1)   // = 0
              return 0
> 
> /* addresses do not match */
> if ( a->address_length != b->address_length || memcmp(a->address, b->address, a->address_length) != 0 )
> 	return 0;

     if ( 1 || 0)  //  =  1
             return 0;
		  => return 0

However the logic in the first part of above patch is:

if (a->family != FamilyWild && b->family != FamilyWild &&
         (a->family != b->family || a->address_length != b->address_length ||
          memcmp(a->address, b->address, a->address_length) != 0))
	  return 0
     if (0 && 1 && (0  || 0 || 0))  // =  0
          return 0;
                 => continue;

Ie. the logic is, as soon as one family == FamilyWild this branch is OK.

I can of course transform both branches of the outer && comparison to
the form above. Might be a bit prettier.

Cheers,
	Egbert.



More information about the xorg-devel mailing list