Repository navigation
fix(libc): format guest wide arguments in syslog on Linux - #4359
Merged
oneandonlydean merged 1 commit intoOct 12, 2026
Merged
Conversation
vsyslog formats the message with the host's vsnprintf on Linux, so a
%ls, %S, %lc or %C argument is read as glibc's 32-bit wchar_t instead
of the guest's 16-bit units. glibc fails the conversion and the message
is dropped: on main syslog(LOG_DEBUG, "wide %ls %d %S", u"guest", 5,
u"text") writes "[syslog:15] " with nothing after it. Windows already
formats syslog messages with the guest formatter, and the narrow printf
family does so on Linux for formats with a guest wide conversion.
FreeBSD 11.4 lib/libc/gen/syslog.c line 229 formats the message with
(void)vfprintf(fp, fmt, ap);
and lib/libc/stdio/vfprintf.c (lines 831-843) converts %S and %ls from
the guest's wchar_t:
case 'S':
flags |= LONGINT;
/*FALLTHROUGH*/
case 's':
if (flags & LONGINT) {
wchar_t *wcp;
...
convbuf = __wcsconv(wcp, prec);
vsyslog now formats through the guest's vsnprintf, which hands formats
with a guest wide conversion to the guest formatter (UTF-8 output, as
for printf) and every other format to glibc as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Windows test: head AI-assisted (Claude Code). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
On Linux,
vsyslog(andsyslog) formats the message with the host'svsnprintf, so a%ls,%S,%lcor%Cargument is read as glibc's 32-bitwchar_tinstead of the guest's 16-bit units. glibc fails the conversion and the message is dropped: on mainsyslog(LOG_DEBUG, "wide %ls %d %S", u"guest", 5, u"text")writes[syslog:15]with nothing after it. Windows already formats syslog messages with the guest formatter, and the narrow printf family does so on Linux for formats with a guest wide conversion (#1804).FreeBSD 11.4
lib/libc/gen/syslog.cline 229 formats the message withand
lib/libc/stdio/vfprintf.clines 831-843 converts%Sand%lsfrom the guest'swchar_t:vsyslognow formats through the guest'svsnprintf, which hands formats with a guest wide conversion to the guest formatter (UTF-8 output, as forprintf) and every other format to glibc as before. No title is claimed.Tested
Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags.
guest_sysloglogs"wide %ls %d %S"withu"guest", 5 andu"text"and expects[syslog:15] wide guest 5 text.[syslog:15]with an empty message).guest_*tests pass (-E '^guest_video_out_').Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)