Package: ccal
Version: 4.1
Severity: important

Dear Maintainer,

* What led up to the situation?
  Running ccal on a modern Linux environment with a current compiler toolchain 
(GCC 14/15).

* What exactly did you do (or not do) that was effective (or ineffective)?
  Executed the `ccal` binary from an ANSI terminal emulator.

* What was the outcome of this action?
  The terminal rendered raw ANSI attribute strings (e.g., "37;42m") as literal 
text because the escape sequence prefix (`\033[`) was completely dropped from 
stdout. 

  Inspecting `src/cal.c` revealed a classic undefined behavior bug in the 
`setcolor()` function:
  sprintf(command,"%s3%d;4%dm",command,dos2ansi[attr&0x0F],...);

  Using the destination array variable (`command`) as a source argument (`%s`) 
inside `sprintf` is undefined behavior under the ISO C standard. Modern 
aggressive compiler pointer-aliasing optimizations optimize out or strip the 
initial token entirely.

* What outcome did you expect instead?
  The monthly calendar and special days column should display with correctly 
rendered terminal background and foreground text colors.

I have attached a minimal patch (`fix-ansi-sprintf.patch`) that eliminates this 
undefined behavior by bypassing the intermediate `command` buffer entirely, 
instead streaming the ANSI tokens directly to stdout using standard `fputs` and 
`fprintf`.


-- System Information:
Debian Release: forky/sid
  APT prefers resolute-updates
  APT policy: (500, 'resolute-updates'), (500, 'resolute-security'), (500, 
'resolute')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 7.0.0-15-generic (SMP w/4 CPU threads; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages ccal depends on:
ii  libc6  2.43-2ubuntu2

ccal recommends no packages.

ccal suggests no packages.

Attachment: fix-ansi-sprintf
Description: application/mbox

Reply via email to