Skip to content

Commit 29f8dbe

Browse files
committed
Fix ippDateToTime when the timezone is not GMT/UTC (Issue #1208)
1 parent 788f5db commit 29f8dbe

5 files changed

Lines changed: 96 additions & 20 deletions

File tree

config-scripts/cups-common.m4

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ AC_COMPILE_IFELSE([
194194
AC_MSG_RESULT([no])
195195
])
196196

197+
dnl See if we have the timegm function...
198+
AC_CHECK_FUNC([timegm], [
199+
AC_DEFINE([HAVE_TIMEGM], [1], [Do we have the timegm function?])
200+
])
201+
197202
dnl See if the stat structure has the st_gen member...
198203
AC_MSG_CHECKING([for st_gen member in stat structure])
199204
AC_COMPILE_IFELSE([

config.h.in

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Configuration file for CUPS.
33
*
4-
* Copyright © 2020-2024 by OpenPrinting
4+
* Copyright © 2020-2025 by OpenPrinting
55
* Copyright © 2007-2019 by Apple Inc.
66
* Copyright © 1997-2007 by Easy Software Products.
77
*
@@ -316,6 +316,13 @@
316316
#undef HAVE_TM_GMTOFF
317317

318318

319+
/*
320+
* Do we have the timegm function?
321+
*/
322+
323+
#undef HAVE_TIMEGM
324+
325+
319326
/*
320327
* Do we have getifaddrs()?
321328
*/

configure

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6338,6 +6338,17 @@ printf "%s\n" "no" >&6; }
63386338
fi
63396339
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
63406340

6341+
ac_fn_c_check_func "$LINENO" "timegm" "ac_cv_func_timegm"
6342+
if test "x$ac_cv_func_timegm" = xyes
6343+
then :
6344+
6345+
6346+
printf "%s\n" "#define HAVE_TIMEGM 1" >>confdefs.h
6347+
6348+
6349+
fi
6350+
6351+
63416352
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for st_gen member in stat structure" >&5
63426353
printf %s "checking for st_gen member in stat structure... " >&6; }
63436354
cat confdefs.h - <<_ACEOF >conftest.$ac_ext

cups/ipp.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ ippDateToTime(const ipp_uchar_t *date) // I - RFC 2579 date info
16281628
// 6 Seconds (0 to 60, 60 = "leap second")
16291629
// 7 Deciseconds (0 to 9)
16301630
// 8 +/- UTC
1631-
// 9 UTC hours (0 to 11)
1631+
// 9 UTC hours (0 to 14)
16321632
// 10 UTC minutes (0 to 59)
16331633
unixdate.tm_year = ((date[0] << 8) | date[1]) - 1900;
16341634
unixdate.tm_mon = date[2] - 1;
@@ -1637,9 +1637,24 @@ ippDateToTime(const ipp_uchar_t *date) // I - RFC 2579 date info
16371637
unixdate.tm_min = date[5];
16381638
unixdate.tm_sec = date[6];
16391639

1640+
#if _WIN32
1641+
if ((t = _mkgmtime(&unixdate)) < 0)
1642+
return (0);
1643+
#elif defined(HAVE_TIMEGM)
1644+
if ((t = timegm(&unixdate)) < 0)
1645+
return (0);
1646+
#else
16401647
if ((t = mktime(&unixdate)) < 0)
16411648
return (0);
16421649

1650+
# if defined(HAVE_TM_GMTOFF)
1651+
localtime_r(&t, &unixdate);
1652+
t -= unixdate.tm_gmtoff;
1653+
# else
1654+
t -= timezone;
1655+
# endif // HAVE_TM_GMTOFF
1656+
#endif // _WIN32
1657+
16431658
if (date[8] == '-')
16441659
t += date[9] * 3600 + date[10] * 60;
16451660
else

cups/testipp.c

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// IPP unit test program for libcups.
33
//
4-
// Copyright © 2020-2024 by OpenPrinting.
4+
// Copyright © 2020-2025 by OpenPrinting.
55
// Copyright © 2007-2019 by Apple Inc.
66
// Copyright © 1997-2005 by Easy Software Products.
77
//
@@ -295,25 +295,27 @@ ssize_t write_cb(_ippdata_t *data, ipp_uchar_t *buffer, size_t bytes);
295295
// 'main()' - Main entry.
296296
//
297297

298-
int // O - Exit status
299-
main(int argc, // I - Number of command-line arguments
300-
char *argv[]) // I - Command-line arguments
298+
int // O - Exit status
299+
main(int argc, // I - Number of command-line arguments
300+
char *argv[]) // I - Command-line arguments
301301
{
302-
_ippdata_t data; // IPP buffer
303-
ipp_uchar_t buffer[8192]; // Write buffer data
304-
ipp_t *cols[2], // Collections
305-
*size; // media-size collection
306-
ipp_t *request; // Request
307-
ipp_attribute_t *media_col, // media-col attribute
308-
*media_size, // media-size attribute
309-
*attr; // Other attribute
310-
ipp_state_t state; // State
311-
size_t length; // Length of data
312-
cups_file_t *fp; // File pointer
313-
size_t i; // Looping var
314-
int status; // Status of tests (0 = success, 1 = fail)
302+
_ippdata_t data; // IPP buffer
303+
ipp_uchar_t buffer[8192]; // Write buffer data
304+
ipp_t *cols[2], // Collections
305+
*size; // media-size collection
306+
ipp_t *request; // Request
307+
ipp_attribute_t *media_col, // media-col attribute
308+
*media_size, // media-size attribute
309+
*attr; // Other attribute
310+
ipp_state_t state; // State
311+
size_t length; // Length of data
312+
cups_file_t *fp; // File pointer
313+
size_t i; // Looping var
314+
int status; // Status of tests (0 = success, 1 = fail)
315+
time_t tv; // Time value
316+
const ipp_uchar_t *dv; // Date value
315317
#ifdef DEBUG
316-
const char *name; // Option name
318+
const char *name; // Option name
317319
#endif // DEBUG
318320

319321

@@ -758,6 +760,42 @@ main(int argc, // I - Number of command-line arguments
758760
testEnd(false);
759761
status = 1;
760762
}
763+
764+
// Test ippDateToTime and ippTimeToDate
765+
testBegin("ippDateToTime(1970/01/02T00:00:00Z)");
766+
buffer[0] = 1970 >> 8; // Year MSB
767+
buffer[1] = 1970 & 255; // Year LSB
768+
buffer[2] = 1; // Month
769+
buffer[3] = 2; // Day
770+
buffer[4] = 0; // Hour
771+
buffer[5] = 0; // Minute
772+
buffer[6] = 0; // Second
773+
buffer[7] = 0; // Deci-second
774+
buffer[8] = '+'; // Timezone +/-
775+
buffer[9] = 0; // Timezone hours
776+
buffer[10] = 0; // Timezone minutes
777+
778+
if ((tv = ippDateToTime(buffer)) == 86400)
779+
{
780+
testEnd(true);
781+
}
782+
else
783+
{
784+
testEndMessage(false, "got %ld, expected 86400", (long)tv);
785+
status = 1;
786+
}
787+
788+
testBegin("ippTimeToDate(86400)");
789+
790+
if ((dv = ippTimeToDate(86400)) != NULL && !memcmp(dv, buffer, 11))
791+
{
792+
testEnd(true);
793+
}
794+
else
795+
{
796+
testEndMessage(false, "got %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X, expected %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", dv[0], dv[1], dv[2], dv[3], dv[4], dv[5], dv[6], dv[7], dv[8], dv[9], dv[10], buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], buffer[8], buffer[9], buffer[10]);
797+
status = 1;
798+
}
761799
}
762800
else
763801
{

0 commit comments

Comments
 (0)