Skip to content

fix: cast char to unsigned char before passing to ctype functions - #2722

Open
pro-laxmi wants to merge 1 commit into
fastfetch-cli:devfrom
pro-laxmi:fix/ctype-unsigned-char-cast
Open

pro-laxmi wants to merge 1 commit into
fastfetch-cli:devfrom
pro-laxmi:fix/ctype-unsigned-char-cast

Conversation

@pro-laxmi

Copy link
Copy Markdown
Contributor

Summary

Standard C library <ctype.h> functions (isblank, tolower, toupper, isalpha, etc.) require their argument to be representable as an unsigned char or equal to EOF. Passing a signed char with a negative value (such as non-ASCII UTF-8 bytes $\ge 0x80$) invokes undefined behavior and can cause out-of-bounds array indexing in libc lookup tables.

This PR audits and casts char to (unsigned char) across remaining call sites:

  • src/common/impl/FFstrbuf.c: ffStrbufUpperCase and ffStrbufLowerCase
  • src/modules/media/media.c: shouldIgnoreChar and artistInSongTitle
  • src/common/impl/font.c: ffFontInitQt
  • src/common/impl/properties.c: ffParsePropLinePointer
  • src/detection/chassis/chassis_linux.c: ffDetectChassis
  • src/detection/cpu/cpu_linux.c: detectAndroid and detectPhysicalCores
  • src/modules/packages/packages.c: ffParsePackagesJsonObject
  • src/modules/player/player.c: ffPrintPlayer
  • src/logo/logo.c: logoGetBuiltin
  • src/detection/wm/wm_apple.m: ffDetectWMPlugin
  • src/detection/wmtheme/wmtheme_windows.c: ffDetectWmTheme

Testing

  • Added test coverage in tests/strbuf.c verifying ffStrbufUpperCase and ffStrbufLowerCase with non-ASCII bytes (\x80, \xff).
  • All 20 tests pass cleanly (ctest --output-on-failure).

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