Skip to content

Fix uninitialized read in cupsLangFind - #196

Open
Carmel0 wants to merge 1 commit into
OpenPrinting:masterfrom
Carmel0:fix-cupslangfind-short-name
Open

Carmel0 wants to merge 1 commit into
OpenPrinting:masterfrom
Carmel0:fix-cupslangfind-short-name

Conversation

@Carmel0

@Carmel0 Carmel0 commented Oct 26, 2026

Copy link
Copy Markdown

cupsLangFind() copies the requested language into a 16-byte stack buffer and then checks langname[2] for '-'. cupsCopyString() only initializes the copied bytes and the terminating null. For a one-character name such as the POSIX "C" locale, langname[2] is therefore still uninitialized.

This is also reached through cupsLangDefault() whenever the process locale is "C".

Reproducer

Build the existing testlang program and run a lookup for the "C" locale under Valgrind:

./configure --enable-debug
make -C cups testlang

valgrind --tool=memcheck \
  --undef-value-errors=yes \
  --track-origins=yes \
  --error-exitcode=86 \
  cups/testlang -l C no-such-message

Memcheck reports:

Conditional jump or move depends on uninitialised value(s)
   at cupsLangFind (cups/language.c:120)

Uninitialised value was created by a stack allocation
   at cupsLangFind (cups/language.c:107)

Check the copied string length before inspecting index 2. The same command is Memcheck-clean after the change, and testlang passes.

cupsCopyString does not initialize bytes after the terminating null. For a one-character language name such as the C locale, checking langname[2] therefore branches on an uninitialized stack byte.

Check the string length before normalizing the separator.

This branch has not been deployed

No deployments
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.

1 participant