mirror of
https://gitlab.freedesktop.org/xorg/xserver.git
synced 2026-06-07 02:58:22 +02:00
pyxtest: replace numerical error values with BadValue, etc.
Let's use human-readable variables for this. Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2216>
This commit is contained in:
parent
a49dc5c7d5
commit
7e22a5cfb5
4 changed files with 39 additions and 19 deletions
|
|
@ -7,7 +7,7 @@ import struct
|
|||
import pytest
|
||||
|
||||
from proto import randr
|
||||
from xclient import Extension, X11Error, X11Reply
|
||||
from xclient import BadIDChoice, BadLength, Extension, X11Error, X11Reply
|
||||
|
||||
|
||||
def _get_first_output(xclient, opcode):
|
||||
|
|
@ -179,8 +179,8 @@ class TestRandROutputProperty:
|
|||
# server tries to allocate 4 GB, failing with BadAlloc (11)
|
||||
# instead.
|
||||
assert isinstance(resp, X11Error), f"Expected an error, got {resp}"
|
||||
assert resp.error_code == 16, (
|
||||
f"Expected BadLength (16), got error code {resp.error_code} - "
|
||||
assert resp.error_code == BadLength, (
|
||||
f"Expected BadLength ({BadLength}), got error code {resp.error_code} - "
|
||||
f"integer truncation not caught by length check"
|
||||
)
|
||||
|
||||
|
|
@ -305,6 +305,6 @@ class TestRandRCreateLease:
|
|||
# Without the fix: BadIDChoice (error code 14).
|
||||
# With the fix: either success or some other error.
|
||||
if isinstance(resp, X11Error):
|
||||
assert resp.error_code != 14, (
|
||||
"CreateLease returned BadIDChoice (error 14) - lid not byte-swapped"
|
||||
assert resp.error_code != BadIDChoice, (
|
||||
"CreateLease returned BadIDChoice - lid not byte-swapped"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import struct
|
|||
import pytest
|
||||
|
||||
from proto import xi
|
||||
from xclient import Extension, X11Error, X11Reply
|
||||
from xclient import BadLength, BadValue, Extension, X11Error, X11Reply
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -116,8 +116,8 @@ class TestXIPassiveGrab:
|
|||
)
|
||||
# The fix returns BadValue (error code 2)
|
||||
assert isinstance(resp, X11Error), f"Expected an error reply, got {resp}"
|
||||
assert resp.error_code == 2, (
|
||||
f"Expected BadValue (2), got error code {resp.error_code}"
|
||||
assert resp.error_code == BadValue, (
|
||||
f"Expected BadValue ({BadValue}), got error code {resp.error_code}"
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -168,8 +168,8 @@ class TestXIChangeProperty:
|
|||
# server tries to allocate 4 GB, failing with BadAlloc (11)
|
||||
# instead.
|
||||
assert isinstance(resp, X11Error), f"Expected an error, got {resp}"
|
||||
assert resp.error_code == 16, (
|
||||
f"Expected BadLength (16), got error code {resp.error_code} - "
|
||||
assert resp.error_code == BadLength, (
|
||||
f"Expected BadLength ({BadLength}), got error code {resp.error_code} - "
|
||||
f"integer truncation not caught by length check"
|
||||
)
|
||||
|
||||
|
|
@ -385,7 +385,7 @@ class TestXIChangeDeviceControl:
|
|||
# With the fix: either a reply (success) or BadMatch (device
|
||||
# doesn't support resolution control), but NOT BadValue.
|
||||
if isinstance(resp, X11Error):
|
||||
assert resp.error_code != 2, (
|
||||
"ChangeDeviceControl returned BadValue (error 2) - "
|
||||
assert resp.error_code != BadValue, (
|
||||
"ChangeDeviceControl returned BadValue - "
|
||||
"resolution values not byte-swapped"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import time
|
|||
import pytest
|
||||
|
||||
from proto import xkb
|
||||
from xclient import X11Error, X11Reply
|
||||
from xclient import BadLength, BadMatch, BadValue, X11Error, X11Reply
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -155,7 +155,7 @@ class TestXkbSetMapOverflows:
|
|||
# error code 0x25 in the resource_id. Without the fix, the
|
||||
# wire pointer advances past the buffer and a later check
|
||||
# returns BadLength (16).
|
||||
bad_value_errors = [e for e in errors if e.error_code == 2]
|
||||
bad_value_errors = [e for e in errors if e.error_code == BadValue]
|
||||
assert bad_value_errors, (
|
||||
"SetMap with totalActs=0 but nonzero per-key action counts "
|
||||
"was not rejected with BadValue - server is missing the "
|
||||
|
|
@ -213,8 +213,8 @@ class TestXkbSetGeometry:
|
|||
|
||||
assert xserver.is_alive, "Server crashed - truncated sections in SetGeometry"
|
||||
assert isinstance(resp, X11Error), f"Expected an error, got {resp}"
|
||||
assert resp.error_code == 16, (
|
||||
f"Expected BadLength (16), got error code {resp.error_code} - "
|
||||
assert resp.error_code == BadLength, (
|
||||
f"Expected BadLength ({BadLength}), got error code {resp.error_code} - "
|
||||
f"missing bounds check in SetGeometry section parsing"
|
||||
)
|
||||
|
||||
|
|
@ -263,7 +263,7 @@ class TestXkbSetGeometry:
|
|||
resps = xclient.flush_responses(timeout=0.5)
|
||||
errors = [r for r in resps if isinstance(r, X11Error)]
|
||||
|
||||
bad_value_errors = [e for e in errors if e.error_code == 2]
|
||||
bad_value_errors = [e for e in errors if e.error_code == BadValue]
|
||||
assert bad_value_errors, (
|
||||
f"SetGeometry with {which_ndx}=200 nOutlines=1 was not rejected "
|
||||
f"with BadValue - server is missing the {which_ndx} bounds check"
|
||||
|
|
@ -320,7 +320,7 @@ class TestXkbSetGeometry:
|
|||
# With the fix, we get BadMatch (8) from the color index check.
|
||||
# Without the fix, the OOB access happens silently and the
|
||||
# request succeeds (no error), so valgrind catches it.
|
||||
match_errors = [e for e in errors if e.error_code == 8]
|
||||
match_errors = [e for e in errors if e.error_code == BadMatch]
|
||||
assert match_errors, (
|
||||
f"SetGeometry with {which_color}ColorNdx=nColors was not rejected with "
|
||||
f"BadMatch - server is missing the off-by-one check"
|
||||
|
|
@ -384,7 +384,7 @@ class TestXkbSetGeometry:
|
|||
# With the fix, we get BadMatch (8) from the rowUnder >= num_rows check.
|
||||
# Without the fix, rowUnder == num_rows passes the '>' check and
|
||||
# the OOB access happens in XkbAddGeomOverlayRow().
|
||||
match_errors = [e for e in errors if e.error_code == 8]
|
||||
match_errors = [e for e in errors if e.error_code == BadMatch]
|
||||
assert match_errors, (
|
||||
"SetGeometry with rowUnder=1 num_rows=1 was not rejected with "
|
||||
"BadMatch - server is missing the off-by-one check"
|
||||
|
|
|
|||
|
|
@ -69,6 +69,26 @@ class Extension(StrEnum):
|
|||
XVIDEO_MC = "XVideo-MotionCompensation"
|
||||
|
||||
|
||||
# X11 core protocol error codes (from X.h)
|
||||
BadRequest = 1
|
||||
BadValue = 2
|
||||
BadWindow = 3
|
||||
BadPixmap = 4
|
||||
BadAtom = 5
|
||||
BadCursor = 6
|
||||
BadFont = 7
|
||||
BadMatch = 8
|
||||
BadDrawable = 9
|
||||
BadAccess = 10
|
||||
BadAlloc = 11
|
||||
BadColor = 12
|
||||
BadGC = 13
|
||||
BadIDChoice = 14
|
||||
BadName = 15
|
||||
BadLength = 16
|
||||
BadImplementation = 17
|
||||
|
||||
|
||||
@dataclass
|
||||
class X11Error:
|
||||
"""An X11 error reply from the server."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue