Skip to content

Commit b97e35d

Browse files
committed
Y2038 fixes (Issue #1592)
- Use dateTime attribute variants. - Use CUPS_LLFMT and CUPS_LLCAST for printing and saving time_t values. - Use strtoll to read time_t values. - Update web interface to request and display dateTime values.
1 parent f820a22 commit b97e35d

20 files changed

Lines changed: 104 additions & 109 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ v2.5b1 - YYYY-MM-DD
9696
pairs for custom boolean, integer, and keyword attributes.
9797
- Updated the default "cups.conf" policies to specify the Set-Printer-Attributes
9898
operation as an administrative operation.
99+
- Updated CUPS to rely on the dateTime variants of various IPP attributes to
100+
avoid Y2038 issues (Issue #1592)
99101
- Deprecated the "page-border" Job Template attribute (Issue #1020)
100102
- Removed the `cups-config` utility (use `pkg-config` instead)
101103
- Fixed use-after-free in `cupsdAcceptClient()` when we log warning during error

cgi-bin/ipp-var.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,10 @@ cgiSetIPPObjectVars(
11831183

11841184
switch (attr->value_tag)
11851185
{
1186+
case IPP_TAG_DATE :
1187+
_cupsStrDate(valptr, sizeof(value) - (size_t)(valptr - value), ippDateToTime(ippGetDate(attr, i)));
1188+
break;
1189+
11861190
case IPP_TAG_INTEGER :
11871191
case IPP_TAG_ENUM :
11881192
if (strncmp(name, "time_at_", 8) == 0)

cups/ppd-util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* PPD utilities for CUPS.
33
*
4-
* Copyright © 2020-2025 by OpenPrinting.
4+
* Copyright © 2020-2026 by OpenPrinting.
55
* Copyright © 2007-2018 by Apple Inc.
66
* Copyright © 1997-2006 by Easy Software Products.
77
*
@@ -302,7 +302,7 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL
302302
}
303303
else
304304
{
305-
DEBUG_printf("2cupsGetPPD3: Returning ok, filename=\"%s\", modtime=%ld.", buffer, (long)ppdinfo.st_mtime);
305+
DEBUG_printf("2cupsGetPPD3: Returning ok, filename=\"%s\", modtime=" CUPS_LLFMT ".", buffer, CUPS_LLCAST ppdinfo.st_mtime);
306306
*modtime = ppdinfo.st_mtime;
307307
return (HTTP_STATUS_OK);
308308
}

cups/tls-openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ cupsGetCredentialsTrust(
10241024

10251025
time(&curtime);
10261026

1027-
DEBUG_printf("1cupsGetCredentialsTrust: curtime=%ld, notBefore=%ld, notAfter=%ld", (long)curtime, (long)openssl_get_date(cert, 0), (long)openssl_get_date(cert, 1));
1027+
DEBUG_printf("1cupsGetCredentialsTrust: curtime=" CUPS_LLFMT ", notBefore=" CUPS_LLFMT ", notAfter=" CUPS_LLFMT, CUPS_LLCAST curtime, CUPS_LLCAST openssl_get_date(cert, 0), CUPS_LLCAST openssl_get_date(cert, 1));
10281028

10291029
if ((curtime + 86400) < openssl_get_date(cert, 0) || curtime > openssl_get_date(cert, 1))
10301030
{

cups/util.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Printing utilities for CUPS.
33
*
4-
* Copyright © 2020-2025 by OpenPrinting.
4+
* Copyright © 2020-2026 by OpenPrinting.
55
* Copyright © 2007-2018 by Apple Inc.
66
* Copyright © 1997-2006 by Easy Software Products.
77
*
@@ -440,17 +440,17 @@ cupsGetJobs2(http_t *http, /* I - Connection to server or @code CUPS_HTTP_D
440440
_cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
441441
static const char * const attrs[] = /* Requested attributes */
442442
{
443+
"date-time-at-completed",
444+
"date-time-at-creation",
445+
"date-time-at-processing",
443446
"document-format",
444447
"job-id",
445448
"job-k-octets",
446449
"job-name",
447450
"job-originating-user-name",
448451
"job-printer-uri",
449452
"job-priority",
450-
"job-state",
451-
"time-at-completed",
452-
"time-at-creation",
453-
"time-at-processing"
453+
"job-state"
454454
};
455455

456456

@@ -574,15 +574,12 @@ cupsGetJobs2(http_t *http, /* I - Connection to server or @code CUPS_HTTP_D
574574
else if (!strcmp(attr->name, "job-k-octets") &&
575575
attr->value_tag == IPP_TAG_INTEGER)
576576
size = attr->values[0].integer;
577-
else if (!strcmp(attr->name, "time-at-completed") &&
578-
attr->value_tag == IPP_TAG_INTEGER)
579-
completed_time = attr->values[0].integer;
580-
else if (!strcmp(attr->name, "time-at-creation") &&
581-
attr->value_tag == IPP_TAG_INTEGER)
582-
creation_time = attr->values[0].integer;
583-
else if (!strcmp(attr->name, "time-at-processing") &&
584-
attr->value_tag == IPP_TAG_INTEGER)
585-
processing_time = attr->values[0].integer;
577+
else if (!strcmp(attr->name, "date-time-at-completed") && attr->value_tag == IPP_TAG_DATE)
578+
completed_time = ippDateToTime(ippGetDate(attr, 0));
579+
else if (!strcmp(attr->name, "date-time-at-creation") && attr->value_tag == IPP_TAG_DATE)
580+
creation_time = ippDateToTime(ippGetDate(attr, 0));
581+
else if (!strcmp(attr->name, "date-time-at-processing") && attr->value_tag == IPP_TAG_DATE)
582+
processing_time = ippDateToTime(ippGetDate(attr, 0));
586583
else if (!strcmp(attr->name, "job-printer-uri") &&
587584
attr->value_tag == IPP_TAG_URI)
588585
{

scheduler/classes.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Printer class routines for the CUPS scheduler.
33
*
4-
* Copyright © 2020-2025 by OpenPrinting.
4+
* Copyright © 2020-2026 by OpenPrinting.
55
* Copyright © 2007-2017 by Apple Inc.
66
* Copyright © 1997-2007 by Easy Software Products, all rights reserved.
77
*
@@ -475,7 +475,7 @@ cupsdLoadAllClasses(void)
475475
*/
476476

477477
if (value)
478-
p->state_time = atoi(value);
478+
p->state_time = strtoll(value, NULL, 10);
479479
}
480480
else if (!_cups_strcasecmp(line, "Accepting"))
481481
{
@@ -756,7 +756,7 @@ cupsdSaveAllClasses(void)
756756
else
757757
cupsFilePuts(fp, "State Idle\n");
758758

759-
cupsFilePrintf(fp, "StateTime %d\n", (int)pclass->state_time);
759+
cupsFilePrintf(fp, "StateTime " CUPS_LLFMT "\n", CUPS_LLCAST pclass->state_time);
760760

761761
if (pclass->accepting)
762762
cupsFilePuts(fp, "Accepting Yes\n");

scheduler/job.c

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,13 @@ cupsdCheckJobs(void)
226226

227227
curtime = time(NULL);
228228

229-
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCheckJobs: %d active jobs, sleeping=%d, ac-power=%d, reload=%d, curtime=%ld", cupsArrayCount(ActiveJobs), Sleeping, ACPower, NeedReload, (long)curtime);
229+
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCheckJobs: %d active jobs, sleeping=%d, ac-power=%d, reload=%d, curtime=" CUPS_LLFMT, cupsArrayCount(ActiveJobs), Sleeping, ACPower, NeedReload, CUPS_LLCAST curtime);
230230

231231
for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs);
232232
job;
233233
job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
234234
{
235-
cupsdLogMessage(CUPSD_LOG_DEBUG2,
236-
"cupsdCheckJobs: Job %d - dest=\"%s\", printer=%p, "
237-
"state=%d, cancel_time=%ld, hold_until=%ld, kill_time=%ld, "
238-
"pending_cost=%d, pending_timeout=%ld", job->id, job->dest,
239-
(void *)job->printer, job->state_value, (long)job->cancel_time,
240-
(long)job->hold_until, (long)job->kill_time,
241-
job->pending_cost, (long)job->pending_timeout);
235+
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCheckJobs: Job %d - dest=\"%s\", printer=%p, state=%d, cancel_time=" CUPS_LLFMT ", hold_until=" CUPS_LLFMT ", kill_time=" CUPS_LLFMT ", pending_cost=%d, pending_timeout=" CUPS_LLFMT, job->id, job->dest,(void *)job->printer, job->state_value, CUPS_LLCAST job->cancel_time, CUPS_LLCAST job->hold_until, CUPS_LLCAST job->kill_time, job->pending_cost, CUPS_LLCAST job->pending_timeout);
242236

243237
/*
244238
* Kill jobs if they are unresponsive...
@@ -433,13 +427,13 @@ cupsdCleanJobs(void)
433427
curtime = time(NULL);
434428
JobHistoryUpdate = 0;
435429

436-
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCleanJobs: curtime=%d", (int)curtime);
430+
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCleanJobs: curtime=" CUPS_LLFMT, CUPS_LLCAST curtime);
437431

438432
for (job = (cupsd_job_t *)cupsArrayFirst(Jobs);
439433
job;
440434
job = (cupsd_job_t *)cupsArrayNext(Jobs))
441435
{
442-
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCleanJobs: Job %d, state=%d, printer=%p, history_time=%d, file_time=%d, num_files=%d", job->id, (int)job->state_value, (void *)job->printer, (int)job->history_time, (int)job->file_time, (int)job->num_files);
436+
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCleanJobs: Job %d, state=%d, printer=%p, history_time=" CUPS_LLFMT ", file_time=" CUPS_LLFMT ", num_files=%d", job->id, (int)job->state_value, (void *)job->printer, CUPS_LLCAST job->history_time, CUPS_LLCAST job->file_time, (int)job->num_files);
443437

444438
if ((job->history_time && job->history_time < JobHistoryUpdate) || !JobHistoryUpdate)
445439
JobHistoryUpdate = job->history_time;
@@ -1711,21 +1705,21 @@ cupsdLoadJob(cupsd_job_t *job) /* I - Job */
17111705
goto error;
17121706
}
17131707

1714-
if ((attr = ippFindAttribute(job->attrs, "time-at-creation", IPP_TAG_INTEGER)) == NULL)
1708+
if ((attr = ippFindAttribute(job->attrs, "date-time-at-creation", IPP_TAG_DATE)) == NULL)
17151709
{
17161710
cupsdLogJob(job, CUPSD_LOG_ERROR,
17171711
"Missing or bad time-at-creation attribute in control file.");
17181712
goto error;
17191713
}
17201714

1721-
job->creation_time = attr->values[0].integer;
1722-
job->state_value = (ipp_jstate_t)job->state->values[0].integer;
1723-
job->file_time = 0;
1724-
job->history_time = 0;
1715+
job->creation_time = ippDateToTime(ippGetDate(attr, 0));
1716+
job->state_value = (ipp_jstate_t)job->state->values[0].integer;
1717+
job->file_time = 0;
1718+
job->history_time = 0;
17251719

1726-
if (job->state_value >= IPP_JSTATE_CANCELED && (attr = ippFindAttribute(job->attrs, "time-at-completed", IPP_TAG_INTEGER)) != NULL)
1720+
if (job->state_value >= IPP_JSTATE_CANCELED && (attr = ippFindAttribute(job->attrs, "date-time-at-completed", IPP_TAG_DATE)) != NULL)
17271721
{
1728-
job->completed_time = attr->values[0].integer;
1722+
job->completed_time = ippDateToTime(ippGetDate(attr, 0));
17291723

17301724
if (JobHistory < INT_MAX)
17311725
job->history_time = job->completed_time + JobHistory;
@@ -1743,7 +1737,7 @@ cupsdLoadJob(cupsd_job_t *job) /* I - Job */
17431737
else
17441738
job->file_time = INT_MAX;
17451739

1746-
cupsdLogJob(job, CUPSD_LOG_DEBUG2, "cupsdLoadJob: job->file_time=%ld, time-at-completed=%ld, JobFiles=%d", (long)job->file_time, (long)attr->values[0].integer, JobFiles);
1740+
cupsdLogJob(job, CUPSD_LOG_DEBUG2, "cupsdLoadJob: job->file_time=" CUPS_LLFMT ", time-at-completed=" CUPS_LLFMT ", JobFiles=%d", CUPS_LLCAST job->file_time, CUPS_LLCAST attr->values[0].integer, JobFiles);
17471741

17481742
if (job->file_time < JobHistoryUpdate || !JobHistoryUpdate)
17491743
JobHistoryUpdate = job->file_time;
@@ -2236,12 +2230,12 @@ cupsdSaveAllJobs(void)
22362230

22372231
cupsFilePrintf(fp, "<Job %d>\n", job->id);
22382232
cupsFilePrintf(fp, "State %d\n", job->state_value);
2239-
cupsFilePrintf(fp, "Created %ld\n", (long)job->creation_time);
2233+
cupsFilePrintf(fp, "Created " CUPS_LLFMT "\n", CUPS_LLCAST job->creation_time);
22402234
if (job->completed_time)
2241-
cupsFilePrintf(fp, "Completed %ld\n", (long)job->completed_time);
2235+
cupsFilePrintf(fp, "Completed " CUPS_LLFMT "\n", CUPS_LLCAST job->completed_time);
22422236
cupsFilePrintf(fp, "Priority %d\n", job->priority);
22432237
if (job->hold_until)
2244-
cupsFilePrintf(fp, "HoldUntil %ld\n", (long)job->hold_until);
2238+
cupsFilePrintf(fp, "HoldUntil " CUPS_LLFMT "\n", CUPS_LLCAST job->hold_until);
22452239
cupsFilePrintf(fp, "Username %s\n", job->username);
22462240
if (job->name)
22472241
cupsFilePutConf(fp, "Name", job->name);
@@ -2489,8 +2483,8 @@ cupsdSetJobHoldUntil(cupsd_job_t *job, /* I - Job */
24892483
job->hold_until += 24 * 60 * 60;
24902484
}
24912485

2492-
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSetJobHoldUntil: hold_until=%d",
2493-
(int)job->hold_until);
2486+
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSetJobHoldUntil: hold_until=" CUPS_LLFMT,
2487+
CUPS_LLCAST job->hold_until);
24942488
}
24952489

24962490

@@ -2870,14 +2864,14 @@ cupsdUpdateJobs(void)
28702864
job = (cupsd_job_t *)cupsArrayNext(Jobs))
28712865
{
28722866
if (job->state_value >= IPP_JSTATE_CANCELED &&
2873-
(attr = ippFindAttribute(job->attrs, "time-at-completed",
2874-
IPP_TAG_INTEGER)) != NULL)
2867+
(attr = ippFindAttribute(job->attrs, "date-time-at-completed",
2868+
IPP_TAG_DATE)) != NULL)
28752869
{
28762870
/*
28772871
* Update history/file expiration times...
28782872
*/
28792873

2880-
job->completed_time = attr->values[0].integer;
2874+
job->completed_time = ippDateToTime(ippGetDate(attr, 0));
28812875

28822876
if (JobHistory < INT_MAX)
28832877
job->history_time = job->completed_time + JobHistory;
@@ -2898,15 +2892,14 @@ cupsdUpdateJobs(void)
28982892
else
28992893
job->file_time = INT_MAX;
29002894

2901-
cupsdLogJob(job, CUPSD_LOG_DEBUG2, "cupsdUpdateJobs: job->file_time=%ld, time-at-completed=%ld, JobFiles=%d", (long)job->file_time, (long)attr->values[0].integer, JobFiles);
2895+
cupsdLogJob(job, CUPSD_LOG_DEBUG2, "cupsdUpdateJobs: job->file_time=" CUPS_LLFMT ", time-at-completed=" CUPS_LLFMT ", JobFiles=%d", CUPS_LLCAST job->file_time, CUPS_LLCAST job->completed_time, JobFiles);
29022896

29032897
if (job->file_time < JobHistoryUpdate || !JobHistoryUpdate)
29042898
JobHistoryUpdate = job->file_time;
29052899
}
29062900
}
29072901

2908-
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdUpdateJobs: JobHistoryUpdate=%ld",
2909-
(long)JobHistoryUpdate);
2902+
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdUpdateJobs: JobHistoryUpdate=" CUPS_LLFMT, CUPS_LLCAST JobHistoryUpdate);
29102903
}
29112904

29122905

@@ -4496,15 +4489,15 @@ load_job_cache(const char *filename) /* I - job.cache filename */
44964489
}
44974490
else if (!_cups_strcasecmp(line, "Created"))
44984491
{
4499-
job->creation_time = strtol(value, NULL, 10);
4492+
job->creation_time = (time_t)strtoll(value, NULL, 10);
45004493
}
45014494
else if (!_cups_strcasecmp(line, "Completed"))
45024495
{
4503-
job->completed_time = strtol(value, NULL, 10);
4496+
job->completed_time = (time_t)strtoll(value, NULL, 10);
45044497
}
45054498
else if (!_cups_strcasecmp(line, "HoldUntil"))
45064499
{
4507-
job->hold_until = strtol(value, NULL, 10);
4500+
job->hold_until = (time_t)strtoll(value, NULL, 10);
45084501
}
45094502
else if (!_cups_strcasecmp(line, "Priority"))
45104503
{

scheduler/printers.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ cupsdLoadAllPrinters(void)
11791179
*/
11801180

11811181
if (value)
1182-
p->state_time = (time_t)strtol(value, NULL, 10);
1182+
p->state_time = (time_t)strtoll(value, NULL, 10);
11831183
}
11841184
else if (!_cups_strcasecmp(line, "ConfigTime"))
11851185
{
@@ -1188,7 +1188,7 @@ cupsdLoadAllPrinters(void)
11881188
*/
11891189

11901190
if (value)
1191-
p->config_time = (time_t)strtol(value, NULL, 10);
1191+
p->config_time = (time_t)strtoll(value, NULL, 10);
11921192
}
11931193
else if (!_cups_strcasecmp(line, "Accepting"))
11941194
{
@@ -1367,7 +1367,7 @@ cupsdLoadAllPrinters(void)
13671367
cupsdSetPrinterAttrs(p);
13681368

13691369
if (!strcmp(value, "marker-change-time"))
1370-
p->marker_time = (time_t)strtol(valueptr, NULL, 10);
1370+
p->marker_time = (time_t)strtoll(valueptr, NULL, 10);
13711371
else
13721372
cupsdSetPrinterAttr(p, value, valueptr);
13731373
}
@@ -1586,8 +1586,8 @@ cupsdSaveAllPrinters(void)
15861586
else
15871587
cupsFilePuts(fp, "State Idle\n");
15881588

1589-
cupsFilePrintf(fp, "StateTime %d\n", (int)printer->state_time);
1590-
cupsFilePrintf(fp, "ConfigTime %d\n", (int)printer->config_time);
1589+
cupsFilePrintf(fp, "StateTime " CUPS_LLFMT "\n", CUPS_LLCAST printer->state_time);
1590+
cupsFilePrintf(fp, "ConfigTime " CUPS_LLFMT "\n", CUPS_LLCAST printer->config_time);
15911591

15921592
for (j = 0; j < printer->num_reasons; j ++)
15931593
if (strcmp(printer->reasons[j], "connecting-to-device") &&
@@ -1733,8 +1733,7 @@ cupsdSaveAllPrinters(void)
17331733
}
17341734

17351735
if (printer->marker_time)
1736-
cupsFilePrintf(fp, "Attribute marker-change-time %ld\n",
1737-
(long)printer->marker_time);
1736+
cupsFilePrintf(fp, "Attribute marker-change-time " CUPS_LLFMT "\n", CUPS_LLCAST printer->marker_time);
17381737

17391738
if (printer == DefaultPrinter)
17401739
cupsFilePuts(fp, "</DefaultPrinter>\n");

scheduler/subscriptions.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Subscription routines for the CUPS scheduler.
33
*
4-
* Copyright © 2020-2025 by OpenPrinting.
4+
* Copyright © 2020-2026 by OpenPrinting.
55
* Copyright © 2007-2019 by Apple Inc.
66
* Copyright © 1997-2007 by Easy Software Products, all rights reserved.
77
*
@@ -1019,7 +1019,7 @@ cupsdLoadAllSubscriptions(void)
10191019
*/
10201020

10211021
if (value && isdigit(*value & 255))
1022-
sub->expire = atoi(value);
1022+
sub->expire = (time_t)strtoll(value, NULL, 10);
10231023
else
10241024
{
10251025
cupsdLogMessage(CUPSD_LOG_ERROR,
@@ -1179,7 +1179,7 @@ cupsdSaveAllSubscriptions(void)
11791179

11801180
cupsFilePrintf(fp, "LeaseDuration %d\n", sub->lease);
11811181
cupsFilePrintf(fp, "Interval %d\n", sub->interval);
1182-
cupsFilePrintf(fp, "ExpirationTime %ld\n", (long)sub->expire);
1182+
cupsFilePrintf(fp, "ExpirationTime " CUPS_LLFMT "\n", CUPS_LLCAST sub->expire);
11831183
cupsFilePrintf(fp, "NextEventId %d\n", sub->next_event_id);
11841184

11851185
cupsFilePuts(fp, "</Subscription>\n");

0 commit comments

Comments
 (0)