From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Graham Inggs Date: May, 17 2026 15:48:54 -0700 Subject: [PATCH] cal: Fix missing ANSI terminal colors due to undefined sprintf in setcolor() Description: Fix terminal color execution by resolving undefined behavior in sprintf Modern compilers optimize out overlapping source/destination pointers in sprintf inside setcolor(), causing the ANSI escape prefix (\033[) to drop entirely from stdout. This patch writes components directly to stdout. Author: David Brown Bug: https://salsa.debian.org/salvage-team/cal/-/issues Bug-Ubuntu: https://bugs.launchpad.net/bugs/2132257 --- The information above should follow the Patch Tagging Guidelines, please checkout https://dep.debian.net/deps/dep3/ to learn about the format. Here are templates for supplementary fields that you might want to add: Origin: (upstream|backport|vendor|other), (|commit:) Bug: Bug-: Forwarded: (no|not-needed|) Applied-Upstream: , (|commit:) Reviewed-By: --- cal-4.1.orig/src/cal.c +++ cal-4.1/src/cal.c @@ -1232,7 +1232,6 @@ void ansiputs(char *l, char *a) *=========================================================================*/ void setcolor(char attr) { - char command[256]; char dos2ansi[] = { 0, 4, 2, 6, 1, 5, 3, 7, 0, 4, 2, 6, 1, 5, 3, 7}; if (!crt) return; @@ -1245,12 +1244,10 @@ void setcolor(char attr) if (attr == 0) fputs("\033[0m",stdout); else { - strcpy(command,"\033[0;"); - if (attr&0x80) strcat(command,"5;"); - if (attr&0x08) strcat(command,"1;"); - sprintf(command,"%s3%d;4%dm",command,dos2ansi[attr&0x0F], - dos2ansi[(attr&0x70)>>4]); - fputs(command,stdout); + fputs("\033[0;", stdout); + if (attr&0x80) fputs("5;", stdout); + if (attr&0x08) fputs("1;", stdout); + fprintf(stdout, "3%d;4%dm", dos2ansi[attr&0x0F], dos2ansi[(attr&0x70)>>4]); } } #endif /* USE_ANSI */