lpstat prints random data #1263

Closed
michaelrsweet opened this Issue Sep 5, 2005 · 2 comments

Comments

Projects
None yet
1 participant
Collaborator

michaelrsweet commented Sep 5, 2005

Version: 1.1.23
CUPS.org User: kssingvo.suse

Running SUSE Linux... :-)

We noticed that under certain locale variables lpstat shows garbage:

pluto:~# env LC_TIME=en_US.UTF-8 lpstat -t
scheduler is running
system default destination: laserjet2200
device for laserjet2200: hp:/usb/HP_LaserJet_2200?device=/dev/usb/lp0
laserjet2200 accepting requests since Jan 01 00:00
printer laserjet2200 disabled since Jan 01 00:00 -
Paused
laserjet2200-3 kssingvo 1024 ž¿

laserjet2200-4 kssingvo 78848 ž¿

pluto:~ # env LC_TIME=en_GB.UTF-8 lpstat -t
scheduler is running
system default destination: laserjet2200
device for laserjet2200: hp:/usb/HP_LaserJet_2200?device=/dev/usb/lp0
laserjet2200 accepting requests since Jan 01 00:00
printer laserjet2200 disabled since Jan 01 00:00 -
Paused
laserjet2200-3 kssingvo 1024 Fri 02 Sep 2005 12:52:06 CEST

laserjet2200-4 kssingvo 78848 Fri 02 Sep 2005 13:17:41 CEST

The difference is, that strftime(... "%c" ...) wants to write more than 32 characters into array date[], if called with LC_TIME=en_US.UTF-8: There is an "A.M." / "P.M." extension in the output string.

So, I think the problematic part is the limited array length of date[]:

char date[32];
[...]
strftime(date, sizeof(date), CUPS_STRFTIME_FORMAT, jobdate);

The manual of strftime(3) says:

The strftime() function returns the number of characters placed in the
array s, not including the terminating NUL character, provided the
string, including the terminating NUL, fits. Otherwise, it returns 0,
and the contents of the array is undefined. (Thus at least since libc
4.4.4; very old versions of libc, such as libc 4.4.1, would return max

if the array was too small.)

So, it looks like this is a glibc (I tested 2.3.5) specific problem. Nevertheless it is a problem for this kind of OS.

I attache our fix, but maybe it would be better to put an "unknown" into date[] array before calling strftime(), to have at least a defined value? If the later, we should do this before any call of strftime() in the CUPS code.

Related: https://bugzilla.novell.com/show_bug.cgi?id=105732

Collaborator

michaelrsweet commented Sep 15, 2005

CUPS.org User: mike

Fixed in Subversion repository.

Collaborator

michaelrsweet commented Sep 15, 2005

"cups-1.1.23-lpstat_strftime.patch":

--- cups-1.1.23/systemv/lpstat.c.orig 2005-01-03 20:29:59.000000000 +0100
+++ cups-1.1.23/systemv/lpstat.c 2005-09-02 16:01:11.000000000 +0200
@@ -1369,7 +1369,7 @@
ptr; / Pointer into printer name /
int match; /
Non-zero if this job matches /
char temp[255], /
Temporary buffer */

  •   date[32];       /\* Date buffer */
    
  •   date[256];      /\* Date buffer _/
    
    static const char *jattrs[] = /_ Attributes we need for jobs... */
    {
    "job-id",

michaelrsweet added this to the Stable milestone Mar 17, 2016

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