Skip to content

Fix uninitialized read in cups_lang_new for short language names - #202

Closed
Carmel0 wants to merge 1 commit into
OpenPrinting:masterfrom
Carmel0:fix-cups-lang-new-short-name
Closed

Carmel0 wants to merge 1 commit into
OpenPrinting:masterfrom
Carmel0:fix-cups-lang-new-short-name

Conversation

@Carmel0

@Carmel0 Carmel0 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #196.

#196 fixed an uninitialized read found by QUniSan during fuzzing. I then asked
GPT-5.6-sol to scan for similar issues; it found this remaining instance, which
was subsequently reproduced with MemorySanitizer.

cups_lang_new() receives the langname buffer from cupsLangFind(). When a
strings directory has been set with cupsLangSetDirectory() and
<dir>/<language>.strings does not exist, it checks language[2] to decide
whether to retry with the two-letter base language. cupsCopyString() only
initializes the copied bytes and the terminating null, so for a one-character
name such as the POSIX "C" locale, language[2] is still uninitialized—the
same byte #196 guarded in cupsLangFind().

Reproducer

Build with MemorySanitizer:

./configure --enable-debug --disable-shared --with-sanitizer=memory \
    CFLAGS="-O1 -g -fno-omit-frame-pointer" CPPFLAGS=""
make -C cups libcups3.a testlang

Then call:

cupsLangSetDirectory("/nonexistent-dir");
cupsLangFind("C");

MemorySanitizer reports:

==32==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x562d32604118 in cups_lang_new /src/cups/language.c:657:29
    #1 0x562d32604118 in cupsLangFind /src/cups/language.c:132:12
    #2 0x562d32603782 in main /probe/langprobe.c:48:12

SUMMARY: MemorySanitizer: use-of-uninitialized-value
/src/cups/language.c:657:29 in cups_lang_new

Valgrind with --track-origins=yes additionally traces the value to the stack
allocation in cupsLangFind() at language.c:107.

Check the string length instead of indexing position 2. The same probe cases
are clean under MemorySanitizer and Valgrind after the change, and testlang
passes. Full cups and ippeveprinter builds also complete without warnings.

Assisted-by: OpenAI Codex:GPT-5.6-sol
Assisted-by: OpenAI Codex:GPT-5

@michaelrsweet michaelrsweet self-assigned this Oct 30, 2026
@michaelrsweet michaelrsweet added the bug Something isn't working label Oct 30, 2026
@michaelrsweet michaelrsweet added this to the Stable milestone Oct 30, 2026
@michaelrsweet

Copy link
Copy Markdown
Member

[master 137b64b] More tweaking for POSIX locale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants