Skip to content

Deduplicate matching Xauthority records#439

Open
zhangpan2001 wants to merge 1 commit into
ubuntu:mainfrom
zhangpan2001:fix/xauthority-deduplicate-matching-records
Open

Deduplicate matching Xauthority records#439
zhangpan2001 wants to merge 1 commit into
ubuntu:mainfrom
zhangpan2001:fix/xauthority-deduplicate-matching-records

Conversation

@zhangpan2001

Copy link
Copy Markdown

When replacing an Xauthority cookie, keep one matching record and remove duplicate matches. Unrelated records are preserved.

This avoids leaving stale cookies for the current display while keeping manually added Xauthority entries intact.

@zhangpan2001
zhangpan2001 force-pushed the fix/xauthority-deduplicate-matching-records branch from 91b91ed to 87a384f Compare July 8, 2026 06:21
@zhangpan2001

Copy link
Copy Markdown
Author

Could a maintainer please approve the remaining workflow to run? Thanks!

@zhangpan2001
zhangpan2001 force-pushed the fix/xauthority-deduplicate-matching-records branch from 87a384f to 76a11a8 Compare July 22, 2026 01:27
@zhangpan2001

zhangpan2001 commented Jul 22, 2026

Copy link
Copy Markdown
Author

@JPeisach Could you please approve the workflow run? The CI failure was caused by a deprecated actions/upload-artifact@v3 which has been fixed by rebasing onto the latest main. Thanks!

@JPeisach

Copy link
Copy Markdown
Collaborator

Sorry, queued them up. I'll check on this tomorrow.

@zhangpan2001

Copy link
Copy Markdown
Author

Sorry, queued them up. I'll check on this tomorrow.

Thanks! I noticed most test failures (286/322) seem pre-existing — they fail with expected "XSERVER-0 START VT=7 SEAT=seat0", likely because the container lacks VT support.

Comment thread src/x-authority.c

@JPeisach JPeisach left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#430 should fix the tests.

Is there a way to reproduce the issue that would cause "duplicate matching Xauthority records"?

I'll check the tests in another review.

Comment thread src/x-authority.c Outdated
continue;
}

if (matched)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If mode is not XAUTH_WRITE_MODE_REMOVE, this would evaluate to if(false), so this code would never run

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is false for the first match, then stays true for the rest of the loop. In replace mode, this skips the second and later matching records. I rewrote it using duplicate_record to make that clearer.

Comment thread src/x-authority.c Outdated
matched = TRUE;
if (mode == XAUTH_WRITE_MODE_REMOVE)
{
matched = TRUE;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was already matched by the top of the condition (after if(record_matches)), so shouldn't it be defined up there?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The code now saves the previous value in duplicate_record, then sets matching_record_found at the top of the block. This keeps the first match and skips later ones.

Include the authorization name when matching records. Keep the first
match when replacing a cookie and discard any duplicates. In remove mode,
delete all matches and do not add a record when none exists.

Add tests for set, replace, and remove modes.
@zhangpan2001
zhangpan2001 force-pushed the fix/xauthority-deduplicate-matching-records branch from 76a11a8 to bb4f8bf Compare July 23, 2026 02:43
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

Successfully merging this pull request may close these issues.

2 participants