[wic][PATCH 4/5] ksparser: require an explicit 0x prefix for --system-id
Trevor Woerner <[email protected]> Wed, 15 Jul 2026 18:32:25 -0400
| Newsgroups | org.yoctoproject.lists.yocto-patches |
|---|---|
| Message-ID | <[email protected]> |
systemidtype() validates the MBR partition type as "hex between 0x1 and 0xFF", but it converts with int(arg, 16), which also accepts a bare "82" (parsed as hex 0x82 = 130) and a signed form like "+0x82". Those inputs contradict the documented contract and are silently returned unchanged, so the raw string later handed to sfdisk may not be what the user meant. Require an explicit 0x/0X-prefixed hex string before converting, so only the documented form is accepted and every other spelling raises the existing ArgumentTypeError. AI-Generated: codex/claude-opus 4.8 (xhigh) Signed-off-by: Trevor Woerner <[email protected]> --- src/wic/ksparser.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wic/ksparser.py b/src/wic/ksparser.py index 528a8180826f..dcf26f788083 100644 --- a/src/wic/ksparser.py +++ b/src/wic/ksparser.py @@ -132,10 +132,12 @@ def systemidtype(arg): """ error = "Invalid system type: %s. must be hex "\ "between 0x1 and 0xFF" % arg - try: - result = int(arg, 16) - except ValueError: + # int(arg, 16) also accepts a bare "82" (-> 130) and a leading sign + # like "+0x82"; the documented contract is an explicit 0x-prefixed + # hex byte, so require that form before converting. + if not re.fullmatch(r"0[xX][0-9a-fA-F]+", arg or ""): raise ArgumentTypeError(error) + result = int(arg, 16) if result <= 0 or result > 0xff: raise ArgumentTypeError(error) -- 2.50.0.173.g8b6f19ccfc3a