Skip to content

Fix use-before-set in inplace_XRRMonitorInfo_enlarge#3512

Merged
ptitSeb merged 1 commit intoptitSeb:mainfrom
devarajabc:0214
Feb 14, 2026
Merged

Fix use-before-set in inplace_XRRMonitorInfo_enlarge#3512
ptitSeb merged 1 commit intoptitSeb:mainfrom
devarajabc:0214

Conversation

@devarajabc
Copy link
Contributor

@devarajabc devarajabc commented Feb 14, 2026

In inplace_XRRMonitorInfo_enlarge(), dst and src alias the same memory with different struct layouts (64-bit vs 32-bit). The inner loop read dst->noutput and dst->outputs at 64-bit struct offsets before they were copied from src, so dst->noutput actually read src->x and dst->outputs read past the 32-bit struct boundary.

Additionally, the loop used from_ulong(dst->outputs[j]) which reads 8-byte unsigned long elements, but the source data contains 4-byte ulong_t XIDs packed in the 32-bit layout.

Fix by saving src->noutput and from_ptrv(src->outputs) to local variables before the conversion loop, and reading source elements as ((ulong_t*)outputs)[j] to match the 32-bit element size.

This could cause crashes or memory corruption in multi-monitor setups when enlarging XRRMonitorInfo arrays from 32-bit to 64-bit layout.

@devarajabc devarajabc marked this pull request as draft February 14, 2026 10:19
@devarajabc devarajabc marked this pull request as ready for review February 14, 2026 10:34
@ptitSeb
Copy link
Owner

ptitSeb commented Feb 14, 2026

You can also simply put the for loop in the end, instead of on top

In inplace_XRRMonitorInfo_enlarge(), dst and src alias the same memory
with different struct layouts (64-bit vs 32-bit). The inner loop read
dst->noutput and dst->outputs at 64-bit struct offsets before they were
copied from src, so dst->noutput actually read src->x (wrong field) and
dst->outputs read past the 32-bit struct boundary (garbage pointer).

Additionally, the loop used from_ulong(dst->outputs[j]) which reads
8-byte unsigned long elements, but the source data contains 4-byte
ulong_t XIDs packed in the 32-bit layout.

Fix by saving src->noutput and from_ptrv(src->outputs) to local
variables before the conversion loop, and reading source elements
as ((ulong_t*)outputs)[j] to match the 32-bit element size.

This could cause crashes or memory corruption in multi-monitor setups
when enlarging XRRMonitorInfo arrays from 32-bit to 64-bit layout.
@devarajabc
Copy link
Contributor Author

devarajabc commented Feb 14, 2026

You can also simply put the for loop in the end, instead of on top

That makes sense

@ptitSeb ptitSeb merged commit 3eed182 into ptitSeb:main Feb 14, 2026
27 checks passed
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