Skip to content

init: fix unescape_string not advancing past escape characters#669

Draft
nikromen wants to merge 1 commit intocontainers:mainfrom
nikromen:fix-init-unescape-string
Draft

init: fix unescape_string not advancing past escape characters#669
nikromen wants to merge 1 commit intocontainers:mainfrom
nikromen:fix-init-unescape-string

Conversation

@nikromen
Copy link
Copy Markdown

@nikromen nikromen commented May 6, 2026

After processing a \X escape sequence in the switch block, the read
pointer (val) was not advanced past the matched character. The next
loop iteration re-processed it as a literal, producing an
extra byte for every escape sequence.

For example, JSON "\n" decoded to {0x0A, 'n'} instead of {0x0A},
and JSON "\\" decoded to {'', }
instead of {''}.

Also fix the \u case: hexToDigit was called with a pointer to 'u'
instead of the first hex digit (val++ vs ++val), and the write index
was not advanced after memcpy, so decoded Unicode characters were
silently dropped. This caused e.g. \u0026 ('&') to be lost, breaking
any container command containing '&&'.

Reproducer (on fedora 43 x86):

[jkyjovsk@fedora libkrun] (fix-init-unescape-string) ↴
$ podman run --rm --runtime krun fedora:latest /bin/bash -c "printf 'hello\nworld\n'"
hello\
nworld\
n⏎

Expected output is:

hello
world

and second & bug:

[jkyjovsk@fedora libkrun] (fix-init-unescape-string) ↴
$ podman run --rm --runtime krun fedora:latest /bin/bash -c 'echo a && echo b'
a echo b

expected outoput:

a
b

@nikromen nikromen marked this pull request as draft May 6, 2026 21:24
@nikromen nikromen force-pushed the fix-init-unescape-string branch from 606aab5 to 529cbc7 Compare May 6, 2026 21:37
After processing a \X escape sequence in the switch block, the read
pointer (val) was not advanced past the matched character. The next
loop iteration re-processed it as a literal, producing an
extra byte for every escape sequence.

For example, JSON "\n" decoded to {0x0A, 'n'} instead of {0x0A},
and JSON "\\\\" decoded to {'\', <next char interpreted as escape>}
instead of {'\'}.

Also fix the \u case: hexToDigit was called with a pointer to 'u'
instead of the first hex digit (val++ vs ++val), and the write index
was not advanced after memcpy, so decoded Unicode characters were
silently dropped. This caused e.g. \u0026 ('&') to be lost, breaking
any container command containing '&&'.
@nikromen nikromen force-pushed the fix-init-unescape-string branch from 529cbc7 to b6a5283 Compare May 6, 2026 21:40
@nikromen
Copy link
Copy Markdown
Author

nikromen commented May 6, 2026

hmmm, both this and #668 are still not working as I thought :/ will look at it later 😴

@jakecorrenti
Copy link
Copy Markdown
Member

Hi @nikromen, thanks for the contribution!

I just want to let you know this is also fixed in my latest draft PR porting the init code to Rust: #670

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