From 2e79749d07dec4ce3a01dfe7f997d428d0b215bd Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Mon, 1 Feb 2021 15:26:53 -0500 Subject: [PATCH] Fix snprintf emulation function (Issue #67) --- CHANGES-OPENPRINTING.md | 1 + cups/snprintf.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGES-OPENPRINTING.md b/CHANGES-OPENPRINTING.md index c9715c07ac..f799771699 100644 --- a/CHANGES-OPENPRINTING.md +++ b/CHANGES-OPENPRINTING.md @@ -11,6 +11,7 @@ Changes in CUPS v2.3.3op2 - Fixed directory/permission defaults for Debian kfreebsd-based systems (Issue #60, Issue #61) - Fixed crash bug in `ppdOpen` (Issue #64, Issue #78) +- Fixed regression in `snprintf` emulation function (Issue #67) - The scheduler's systemd service file now waits for the nslcd service to start (Issue #69) - Fixed segfault in help.cgi when searching in man pages (Issue #81) diff --git a/cups/snprintf.c b/cups/snprintf.c index a4d17b5be3..e559ebfc4e 100644 --- a/cups/snprintf.c +++ b/cups/snprintf.c @@ -1,6 +1,7 @@ /* * snprintf functions for CUPS. * + * Copyright © 2021 by Michael R Sweet * Copyright © 2007-2019 by Apple Inc. * Copyright © 1997-2007 by Easy Software Products. * @@ -81,7 +82,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */ format ++; width = va_arg(ap, int); - snprintf(tptr, sizeof(tformat) - (tptr - tformat), "%d", width); + /* Note: Can't use snprintf here since we are implementing this function... */ + sprintf(tptr, "%d", width); tptr += strlen(tptr); } else @@ -113,7 +115,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */ format ++; prec = va_arg(ap, int); - snprintf(tptr, sizeof(tformat) - (tptr - tformat), "%d", prec); + /* Note: Can't use snprintf here since we are implementing this function... */ + sprintf(tptr, "%d", prec); tptr += strlen(tptr); } else @@ -171,7 +174,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */ if ((width + 2) > sizeof(temp)) break; - snprintf(temp, sizeof(temp), tformat, va_arg(ap, double)); + /* Note: Can't use snprintf here since we are implementing this function... */ + sprintf(temp, tformat, va_arg(ap, double)); templen = strlen(temp); bytes += (int)templen; @@ -202,7 +206,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */ if ((width + 2) > sizeof(temp)) break; - snprintf(temp, sizeof(temp), tformat, va_arg(ap, int)); + /* Note: Can't use snprintf here since we are implementing this function... */ + sprintf(temp, tformat, va_arg(ap, int)); templen = strlen(temp); bytes += (int)templen; @@ -226,7 +231,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */ if ((width + 2) > sizeof(temp)) break; - snprintf(temp, sizeof(temp), tformat, va_arg(ap, void *)); + /* Note: Can't use snprintf here since we are implementing this function... */ + sprintf(temp, tformat, va_arg(ap, void *)); templen = strlen(temp); bytes += (int)templen;