From dfb2f39d53933349cdff0a9bb18cb9e42b81d6f5 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Sun, 30 Mar 2025 19:30:13 -0400 Subject: [PATCH] Fix ippDateToTime when the timezone is not GMT/UTC (Issue #1208) --- CHANGES.md | 1 + config-scripts/cups-common.m4 | 7 ++++++- config.h.in | 9 ++++++++- configure | 19 +++++++++++++++---- cups/ipp.c | 20 ++++++++++++++++++-- vcnet/config.h | 9 ++++++++- xcode/config.h | 9 ++++++++- 7 files changed, 64 insertions(+), 10 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5227c6f118..2db76b3e91 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ Changes in CUPS v2.4.12 (YYYY-MM-DD) (Issue #1201) - Fixed attributes returned by the Create-Xxx-Subscriptions requests (Issue #1204) +- Fixed `ippDateToTime` when using a non GMT/UTC timezone (Issue #1208) Changes in CUPS v2.4.11 (2024-09-30) diff --git a/config-scripts/cups-common.m4 b/config-scripts/cups-common.m4 index 613f01ddf5..48602a8c30 100644 --- a/config-scripts/cups-common.m4 +++ b/config-scripts/cups-common.m4 @@ -1,7 +1,7 @@ dnl dnl Common configuration stuff for CUPS. dnl -dnl Copyright © 2020-2024 by OpenPrinting. +dnl Copyright © 2020-2025 by OpenPrinting. dnl Copyright © 2007-2019 by Apple Inc. dnl Copyright © 1997-2007 by Easy Software Products, all rights reserved. dnl @@ -207,6 +207,11 @@ AC_COMPILE_IFELSE([ AC_MSG_RESULT([no]) ]) +dnl See if we have the timegm function... +AC_CHECK_FUNC([timegm], [ + AC_DEFINE([HAVE_TIMEGM], [1], [Do we have the timegm function?]) +]) + dnl See if the stat structure has the st_gen member... AC_MSG_CHECKING([for st_gen member in stat structure]) AC_COMPILE_IFELSE([ diff --git a/config.h.in b/config.h.in index 6940b96044..7d655dd15c 100644 --- a/config.h.in +++ b/config.h.in @@ -1,7 +1,7 @@ /* * Configuration file for CUPS. * - * Copyright © 2020-2023 by OpenPrinting + * Copyright © 2020-2025 by OpenPrinting * Copyright © 2007-2019 by Apple Inc. * Copyright © 1997-2007 by Easy Software Products. * @@ -380,6 +380,13 @@ #undef HAVE_TM_GMTOFF +/* + * Do we have the timegm function? + */ + +#undef HAVE_TIMEGM + + /* * Do we have rresvport_af()? */ diff --git a/configure b/configure index f9037fddbc..2fb1229526 100755 --- a/configure +++ b/configure @@ -4727,11 +4727,11 @@ if test x$ac_prog_cxx_stdcxx = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++11 features" >&5 printf %s "checking for $CXX option to enable C++11 features... " >&6; } -if test ${ac_cv_prog_cxx_cxx11+y} +if test ${ac_cv_prog_cxx_11+y} then : printf %s "(cached) " >&6 else $as_nop - ac_cv_prog_cxx_cxx11=no + ac_cv_prog_cxx_11=no ac_save_CXX=$CXX cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -4773,11 +4773,11 @@ if test x$ac_prog_cxx_stdcxx = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++98 features" >&5 printf %s "checking for $CXX option to enable C++98 features... " >&6; } -if test ${ac_cv_prog_cxx_cxx98+y} +if test ${ac_cv_prog_cxx_98+y} then : printf %s "(cached) " >&6 else $as_nop - ac_cv_prog_cxx_cxx98=no + ac_cv_prog_cxx_98=no ac_save_CXX=$CXX cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -6422,6 +6422,17 @@ printf "%s\n" "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +ac_fn_c_check_func "$LINENO" "timegm" "ac_cv_func_timegm" +if test "x$ac_cv_func_timegm" = xyes +then : + + +printf "%s\n" "#define HAVE_TIMEGM 1" >>confdefs.h + + +fi + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for st_gen member in stat structure" >&5 printf %s "checking for st_gen member in stat structure... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext diff --git a/cups/ipp.c b/cups/ipp.c index 8070785846..b9f6420a56 100644 --- a/cups/ipp.c +++ b/cups/ipp.c @@ -1699,7 +1699,7 @@ ippDateToTime(const ipp_uchar_t *date) /* I - RFC 2579 date info */ * 6 Seconds (0 to 60, 60 = "leap second") * 7 Deciseconds (0 to 9) * 8 +/- UTC - * 9 UTC hours (0 to 11) + * 9 UTC hours (0 to 14) * 10 UTC minutes (0 to 59) */ @@ -1710,7 +1710,23 @@ ippDateToTime(const ipp_uchar_t *date) /* I - RFC 2579 date info */ unixdate.tm_min = date[5]; unixdate.tm_sec = date[6]; - t = mktime(&unixdate); +#if _WIN32 + if ((t = _mkgmtime(&unixdate)) < 0) + return (0); +#elif defined(HAVE_TIMEGM) + if ((t = timegm(&unixdate)) < 0) + return (0); +#else + if ((t = mktime(&unixdate)) < 0) + return (0); + +# if defined(HAVE_TM_GMTOFF) + localtime_r(&t, &unixdate); + t -= unixdate.tm_gmtoff; +# else + t -= timezone; +# endif // HAVE_TM_GMTOFF +#endif // _WIN32 if (date[8] == '-') t += date[9] * 3600 + date[10] * 60; diff --git a/vcnet/config.h b/vcnet/config.h index 7fc4592171..8d6322b664 100644 --- a/vcnet/config.h +++ b/vcnet/config.h @@ -1,7 +1,7 @@ /* * Configuration file for CUPS on Windows. * - * Copyright © 2021-2024 by OpenPrinting + * Copyright © 2021-2025 by OpenPrinting * Copyright © 2007-2019 by Apple Inc. * Copyright © 1997-2007 by Easy Software Products. * @@ -472,6 +472,13 @@ typedef unsigned long useconds_t; /* #undef HAVE_TM_GMTOFF */ +/* + * Do we have the timegm function? + */ + +/* #undef HAVE_TIMEGM */ + + /* * Do we have rresvport_af()? */ diff --git a/xcode/config.h b/xcode/config.h index c1aaa6b23d..0e4f3dae27 100644 --- a/xcode/config.h +++ b/xcode/config.h @@ -1,7 +1,7 @@ /* * Configuration file for CUPS and Xcode. * - * Copyright © 2021-2024 by OpenPrinting + * Copyright © 2021-2025 by OpenPrinting * Copyright © 2007-2019 by Apple Inc. * Copyright © 1997-2007 by Easy Software Products. * @@ -398,6 +398,13 @@ #define HAVE_TM_GMTOFF 1 +/* + * Do we have the timegm function? + */ + +#define HAVE_TIMEGM 1 + + /* * Do we have rresvport_af()? */ -- 2.47.2