]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Address multiple minor issues reported by the LGTM security scanner:
authorMichael R Sweet <michael.r.sweet@gmail.com>
Sun, 17 Nov 2019 15:18:09 +0000 (10:18 -0500)
committerMichael R Sweet <michael.r.sweet@gmail.com>
Mon, 18 Nov 2019 16:19:16 +0000 (11:19 -0500)
- Lots of usage of localtime and gmtime (use _r/_s versions instead -
  Issue #5685)
- Some unnecessary comparisons
- Suppress checks that are not useful (header guards, short global names, and
  the integer overflow checks which don't reflect the actual range of values)

17 files changed:
backend/lpd.c
backend/usb-libusb.c
cgi-bin/var.c
cups/encode.c
cups/http-support.c
cups/http.c
cups/ipp.c
cups/string.c
lgtm.yaml [new file with mode: 0644]
scheduler/classes.c
scheduler/job.c
scheduler/log.c
scheduler/printers.c
scheduler/subscriptions.c
tools/ippeveprinter.c
tools/ipptool.c
vcnet/config.h

index 45cdde8e7f0a50fa488c12ca501373ff071b1b65..efc7a9acc29b87362be3eaed1f6ab6d0da5a1523 100644 (file)
@@ -71,7 +71,11 @@ static int   abort_job = 0;          /* Non-zero if we get SIGTERM */
  */
 
 static int     cups_rresvport(int *port, int family);
-static int     lpd_command(int lpd_fd, char *format, ...);
+static int     lpd_command(int lpd_fd, char *format, ...)
+#    ifdef __GNUC__
+__attribute__ ((__format__ (__printf__, 2, 3)))
+#    endif /* __GNUC__ */
+;
 static int     lpd_queue(const char *hostname, http_addrlist_t *addrlist, const char *printer, int print_fd, int snmp_fd, int mode, const char *user, const char *title, int copies, int banner, int format, int order, int reserve, int manual_copies, int timeout, int contimeout, const char *orighost) _CUPS_NONNULL((1,2,3,7,8,17));
 static ssize_t lpd_write(int lpd_fd, char *buffer, size_t length);
 static void    sigterm_handler(int sig);
@@ -1042,7 +1046,7 @@ lpd_queue(const char      *hostname,      /* I - Host to connect to */
       * Send the control file...
       */
 
-      if (lpd_command(fd, "\002%d cfA%03.3d%.15s\n", strlen(control),
+      if (lpd_command(fd, "\002%d cfA%03.3d%.15s\n", (int)strlen(control),
                       (int)getpid() % 1000, localhost))
       {
        close(fd);
@@ -1175,7 +1179,7 @@ lpd_queue(const char      *hostname,      /* I - Host to connect to */
       * Send control file...
       */
 
-      if (lpd_command(fd, "\002%d cfA%03.3d%.15s\n", strlen(control),
+      if (lpd_command(fd, "\002%d cfA%03.3d%.15s\n", (int)strlen(control),
                       (int)getpid() % 1000, localhost))
       {
        close(fd);
index 1c4d9f11721d41df3a762a3177ca3f0fcaea0a40..9740c14d563e95ef58631f09a3683224ba14ece1 100644 (file)
@@ -878,7 +878,7 @@ find_device(usb_cb_t   cb,          /* I - Callback function */
           protocol   = 0;
 
          for (altset = 0, altptr = ifaceptr->altsetting;
-              altset < ifaceptr->num_altsetting;
+              altset < (uint8_t)ifaceptr->num_altsetting;
               altset ++, altptr ++)
           {
           /*
index fb9d051c0ba7e1e83fb4998e16b659ed478ea727..c5fde01240d1e9e4cb14c8511db60f7d8e094869 100644 (file)
@@ -983,7 +983,7 @@ cgi_initialize_post(void)
   */
 
   length = (size_t)strtol(content_length, NULL, 10);
-  data   = malloc(length + 1);
+  data   = malloc(length + 1); /* lgtm [cpp/uncontrolled-allocation-size] */
 
   if (data == NULL)
     return (0);
index 2469406e2f5bda69a8afd259ff08ad8bd7cb8806..5bcbf6fe5a749011f759a4b05de18011571fd891 100644 (file)
@@ -523,7 +523,7 @@ _cupsEncodeOption(
 
          quote = *sep;
        }
-       else if (*sep == ',' && count > 1)
+       else if (*sep == ',')
          break;
        else if (*sep == '\\' && sep[1])
        {
index 824b8dcf1bc1c94681ede52758bbc5f88b9b01a5..63175145ee97acae89909529282e97032c5a96c3 100644 (file)
@@ -799,14 +799,12 @@ httpGetDateString2(time_t t,              /* I - Time in seconds */
                    char   *s,          /* I - String buffer */
                   int    slen)         /* I - Size of string buffer */
 {
-  struct tm    *tdate;                 /* UNIX date/time data */
+  struct tm    tdate;                  /* UNIX date/time data */
 
 
-  tdate = gmtime(&t);
-  if (tdate)
-    snprintf(s, (size_t)slen, "%s, %02d %s %d %02d:%02d:%02d GMT", http_days[tdate->tm_wday], tdate->tm_mday, http_months[tdate->tm_mon], tdate->tm_year + 1900, tdate->tm_hour, tdate->tm_min, tdate->tm_sec);
-  else
-    s[0] = '\0';
+  gmtime_r(&t, &tdate);
+
+  snprintf(s, (size_t)slen, "%s, %02d %s %d %02d:%02d:%02d GMT", http_days[tdate.tm_wday], tdate.tm_mday, http_months[tdate.tm_mon], tdate.tm_year + 1900, tdate.tm_hour, tdate.tm_min, tdate.tm_sec);
 
   return (s);
 }
index fbb1bf13cce520cd7438637a1661a1b8ff738c6f..8d69ce31f83f511517ef2d1452a72248013c2292 100644 (file)
@@ -1733,7 +1733,7 @@ httpPeek(http_t *http,                    /* I - HTTP connection */
 
     if (http->used > 0 && ((z_stream *)http->stream)->avail_in < HTTP_MAX_BUFFER)
     {
-      size_t buflen = buflen = HTTP_MAX_BUFFER - ((z_stream *)http->stream)->avail_in;
+      size_t buflen = HTTP_MAX_BUFFER - ((z_stream *)http->stream)->avail_in;
                                        /* Number of bytes to copy */
 
       if (((z_stream *)http->stream)->avail_in > 0 &&
index 1bd59cef112a452d2e3aae50f75ebd0997dab140..d0cac8cfe198c97bd218f661018b21a6f7e48a3d 100644 (file)
@@ -4659,7 +4659,7 @@ ippSetVersion(ipp_t *ipp,         /* I - IPP message */
 const ipp_uchar_t *                    /* O - RFC-2579 date/time data */
 ippTimeToDate(time_t t)                        /* I - Time in seconds */
 {
-  struct tm    *unixdate;              /* UNIX unixdate/time info */
+  struct tm    unixdate;               /* UNIX unixdate/time info */
   ipp_uchar_t  *date = _cupsGlobals()->ipp_date;
                                        /* RFC-2579 date/time data */
 
@@ -4681,16 +4681,16 @@ ippTimeToDate(time_t t)                 /* I - Time in seconds */
   *    10       UTC minutes (0 to 59)
   */
 
-  unixdate = gmtime(&t);
-  unixdate->tm_year += 1900;
+  gmtime_r(&t, &unixdate);
+  unixdate.tm_year += 1900;
 
-  date[0]  = (ipp_uchar_t)(unixdate->tm_year >> 8);
-  date[1]  = (ipp_uchar_t)(unixdate->tm_year);
-  date[2]  = (ipp_uchar_t)(unixdate->tm_mon + 1);
-  date[3]  = (ipp_uchar_t)unixdate->tm_mday;
-  date[4]  = (ipp_uchar_t)unixdate->tm_hour;
-  date[5]  = (ipp_uchar_t)unixdate->tm_min;
-  date[6]  = (ipp_uchar_t)unixdate->tm_sec;
+  date[0]  = (ipp_uchar_t)(unixdate.tm_year >> 8);
+  date[1]  = (ipp_uchar_t)(unixdate.tm_year);
+  date[2]  = (ipp_uchar_t)(unixdate.tm_mon + 1);
+  date[3]  = (ipp_uchar_t)unixdate.tm_mday;
+  date[4]  = (ipp_uchar_t)unixdate.tm_hour;
+  date[5]  = (ipp_uchar_t)unixdate.tm_min;
+  date[6]  = (ipp_uchar_t)unixdate.tm_sec;
   date[7]  = 0;
   date[8]  = '+';
   date[9]  = 0;
index 54f7bd0cf8e4c7928c36e0a6fafb201e4115f4b8..93cdad19d58e86fd51871cfd384d99d2325d6c89 100644 (file)
@@ -146,7 +146,7 @@ _cupsStrDate(char   *buf,           /* I - Buffer */
              size_t bufsize,           /* I - Size of buffer */
             time_t timeval)            /* I - Time value */
 {
-  struct tm    *dateval;               /* Local date/time */
+  struct tm    date;                   /* Local date/time */
   char         temp[1024];             /* Temporary buffer */
   _cups_globals_t *cg = _cupsGlobals();        /* Per-thread globals */
 
@@ -154,15 +154,15 @@ _cupsStrDate(char   *buf,         /* I - Buffer */
   if (!cg->lang_default)
     cg->lang_default = cupsLangDefault();
 
-  dateval = localtime(&timeval);
+  localtime_r(&timeval, &date);
 
   if (cg->lang_default->encoding != CUPS_UTF8)
   {
-    strftime(temp, sizeof(temp), "%c", dateval);
+    strftime(temp, sizeof(temp), "%c", &date);
     cupsCharsetToUTF8((cups_utf8_t *)buf, temp, (int)bufsize, cg->lang_default->encoding);
   }
   else
-    strftime(buf, bufsize, "%c", dateval);
+    strftime(buf, bufsize, "%c", &date);
 
   return (buf);
 }
diff --git a/lgtm.yaml b/lgtm.yaml
new file mode 100644 (file)
index 0000000..6265517
--- /dev/null
+++ b/lgtm.yaml
@@ -0,0 +1,4 @@
+queries:
+  - exclude: cpp/integer-multiplication-cast-to-long
+  - exclude: cpp/missing-header-guard
+  - exclude: cpp/short-global-name
index 776e79a913af09f4450397ab010472fd6da16a65..14d2558bf0f12a97e7d3dfea359042ac4f5e80bc 100644 (file)
@@ -664,7 +664,7 @@ cupsdSaveAllClasses(void)
   cupsd_printer_t      *pclass;        /* Current printer class */
   int                  i;              /* Looping var */
   time_t               curtime;        /* Current time */
-  struct tm            *curdate;       /* Current date */
+  struct tm            curdate;        /* Current date */
   cups_option_t                *option;        /* Current option */
 
 
@@ -683,9 +683,9 @@ cupsdSaveAllClasses(void)
   * Write a small header to the file...
   */
 
-  curtime = time(NULL);
-  curdate = localtime(&curtime);
-  strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", curdate);
+  time(&curtime);
+  localtime_r(&curtime, &curdate);
+  strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", &curdate);
 
   cupsFilePuts(fp, "# Class configuration file for " CUPS_SVERSION "\n");
   cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
index 2cfb1b03db27d3d89947c7e882fbbc9fd2b5bd47..e20e7c563edc65340155d2ad8b8882fe24e0e10e 100644 (file)
@@ -2183,7 +2183,7 @@ cupsdSaveAllJobs(void)
                temp[1024];             /* Temporary string */
   cupsd_job_t  *job;                   /* Current job */
   time_t       curtime;                /* Current time */
-  struct tm    *curdate;               /* Current date */
+  struct tm    curdate;                /* Current date */
 
 
   snprintf(filename, sizeof(filename), "%s/job.cache", CacheDir);
@@ -2196,9 +2196,9 @@ cupsdSaveAllJobs(void)
   * Write a small header to the file...
   */
 
-  curtime = time(NULL);
-  curdate = localtime(&curtime);
-  strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", curdate);
+  time(&curtime);
+  localtime_r(&curtime, &curdate);
+  strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", &curdate);
 
   cupsFilePuts(fp, "# Job cache file for " CUPS_SVERSION "\n");
   cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
@@ -2311,7 +2311,7 @@ cupsdSetJobHoldUntil(cupsd_job_t *job,    /* I - Job */
                     int         update)/* I - Update job-hold-until attr? */
 {
   time_t       curtime;                /* Current time */
-  struct tm    *curdate;               /* Current date */
+  struct tm    curdate;                /* Current date */
   int          hour;                   /* Hold hour */
   int          minute;                 /* Hold minute */
   int          second = 0;             /* Hold second */
@@ -2380,15 +2380,15 @@ cupsdSetJobHoldUntil(cupsd_job_t *job,  /* I - Job */
     * Hold to 6am the next morning unless local time is < 6pm.
     */
 
-    curtime = time(NULL);
-    curdate = localtime(&curtime);
+    time(&curtime);
+    localtime_r(&curtime, &curdate);
 
-    if (curdate->tm_hour < 18)
+    if (curdate.tm_hour < 18)
       job->hold_until = curtime;
     else
       job->hold_until = curtime +
-                        ((29 - curdate->tm_hour) * 60 + 59 -
-                        curdate->tm_min) * 60 + 60 - curdate->tm_sec;
+                        ((29 - curdate.tm_hour) * 60 + 59 -
+                        curdate.tm_min) * 60 + 60 - curdate.tm_sec;
   }
   else if (!strcmp(when, "evening") || !strcmp(when, "night"))
   {
@@ -2396,15 +2396,15 @@ cupsdSetJobHoldUntil(cupsd_job_t *job,  /* I - Job */
     * Hold to 6pm unless local time is > 6pm or < 6am.
     */
 
-    curtime = time(NULL);
-    curdate = localtime(&curtime);
+    time(&curtime);
+    localtime_r(&curtime, &curdate);
 
-    if (curdate->tm_hour < 6 || curdate->tm_hour >= 18)
+    if (curdate.tm_hour < 6 || curdate.tm_hour >= 18)
       job->hold_until = curtime;
     else
       job->hold_until = curtime +
-                        ((17 - curdate->tm_hour) * 60 + 59 -
-                        curdate->tm_min) * 60 + 60 - curdate->tm_sec;
+                        ((17 - curdate.tm_hour) * 60 + 59 -
+                        curdate.tm_min) * 60 + 60 - curdate.tm_sec;
   }
   else if (!strcmp(when, "second-shift"))
   {
@@ -2412,15 +2412,15 @@ cupsdSetJobHoldUntil(cupsd_job_t *job,  /* I - Job */
     * Hold to 4pm unless local time is > 4pm.
     */
 
-    curtime = time(NULL);
-    curdate = localtime(&curtime);
+    time(&curtime);
+    localtime_r(&curtime, &curdate);
 
-    if (curdate->tm_hour >= 16)
+    if (curdate.tm_hour >= 16)
       job->hold_until = curtime;
     else
       job->hold_until = curtime +
-                        ((15 - curdate->tm_hour) * 60 + 59 -
-                        curdate->tm_min) * 60 + 60 - curdate->tm_sec;
+                        ((15 - curdate.tm_hour) * 60 + 59 -
+                        curdate.tm_min) * 60 + 60 - curdate.tm_sec;
   }
   else if (!strcmp(when, "third-shift"))
   {
@@ -2428,15 +2428,15 @@ cupsdSetJobHoldUntil(cupsd_job_t *job,  /* I - Job */
     * Hold to 12am unless local time is < 8am.
     */
 
-    curtime = time(NULL);
-    curdate = localtime(&curtime);
+    time(&curtime);
+    localtime_r(&curtime, &curdate);
 
-    if (curdate->tm_hour < 8)
+    if (curdate.tm_hour < 8)
       job->hold_until = curtime;
     else
       job->hold_until = curtime +
-                        ((23 - curdate->tm_hour) * 60 + 59 -
-                        curdate->tm_min) * 60 + 60 - curdate->tm_sec;
+                        ((23 - curdate.tm_hour) * 60 + 59 -
+                        curdate.tm_min) * 60 + 60 - curdate.tm_sec;
   }
   else if (!strcmp(when, "weekend"))
   {
@@ -2444,16 +2444,16 @@ cupsdSetJobHoldUntil(cupsd_job_t *job,  /* I - Job */
     * Hold to weekend unless we are in the weekend.
     */
 
-    curtime = time(NULL);
-    curdate = localtime(&curtime);
+    time(&curtime);
+    localtime_r(&curtime, &curdate);
 
-    if (curdate->tm_wday == 0 || curdate->tm_wday == 6)
+    if (curdate.tm_wday == 0 || curdate.tm_wday == 6)
       job->hold_until = curtime;
     else
       job->hold_until = curtime +
-                        (((5 - curdate->tm_wday) * 24 +
-                          (17 - curdate->tm_hour)) * 60 + 59 -
-                          curdate->tm_min) * 60 + 60 - curdate->tm_sec;
+                        (((5 - curdate.tm_wday) * 24 +
+                          (17 - curdate.tm_hour)) * 60 + 59 -
+                          curdate.tm_min) * 60 + 60 - curdate.tm_sec;
   }
   else if (sscanf(when, "%d:%d:%d", &hour, &minute, &second) >= 2)
   {
@@ -2461,12 +2461,12 @@ cupsdSetJobHoldUntil(cupsd_job_t *job,  /* I - Job */
     * Hold to specified GMT time (HH:MM or HH:MM:SS)...
     */
 
-    curtime = time(NULL);
-    curdate = gmtime(&curtime);
+    time(&curtime);
+    gmtime_r(&curtime, &curdate);
 
     job->hold_until = curtime +
-                      ((hour - curdate->tm_hour) * 60 + minute -
-                      curdate->tm_min) * 60 + second - curdate->tm_sec;
+                      ((hour - curdate.tm_hour) * 60 + minute -
+                      curdate.tm_min) * 60 + second - curdate.tm_sec;
 
    /*
     * Hold until next day as needed...
@@ -2957,7 +2957,7 @@ dump_job_history(cupsd_job_t *job)        /* I - Job */
 {
   int                  i,              /* Looping var */
                        oldsize;        /* Current MaxLogSize */
-  struct tm            *date;          /* Date/time value */
+  struct tm            date;           /* Date/time value */
   cupsd_joblog_t       *message;       /* Current message */
   char                 temp[2048],     /* Log message */
                        *ptr,           /* Pointer into log message */
@@ -2985,12 +2985,12 @@ dump_job_history(cupsd_job_t *job)      /* I - Job */
   */
 
   message = (cupsd_joblog_t *)cupsArrayFirst(job->history);
-  date = localtime(&(message->time));
-  strftime(start, sizeof(start), "%X", date);
+  localtime_r(&(message->time), &date);
+  strftime(start, sizeof(start), "%X", &date);
 
   message = (cupsd_joblog_t *)cupsArrayLast(job->history);
-  date = localtime(&(message->time));
-  strftime(end, sizeof(end), "%X", date);
+  localtime_r(&(message->time), &date);
+  strftime(end, sizeof(end), "%X", &date);
 
   snprintf(temp, sizeof(temp),
            "[Job %d] The following messages were recorded from %s to %s",
index cdb5437dcf712ace4d0cdcd203bbfef5af4924b6..2bd1952f7d1decd39edf1d1a699e4795504a426b 100644 (file)
@@ -301,7 +301,7 @@ cupsdGetDateTime(struct timeval *t, /* I - Time value or NULL for current */
                  cupsd_time_t   format)        /* I - Format to use */
 {
   struct timeval       curtime;        /* Current time value */
-  struct tm            *date;          /* Date/time value */
+  struct tm            date;           /* Date/time value */
   static struct timeval        last_time = { 0, 0 };
                                        /* Last time we formatted */
   static char          s[1024];        /* Date/time string */
@@ -351,23 +351,23 @@ cupsdGetDateTime(struct timeval *t,       /* I - Time value or NULL for current */
     * (*BSD and Darwin store the timezone offset in the tm structure)
     */
 
-    date = localtime(&(t->tv_sec));
+    localtime_r(&(t->tv_sec), &date);
 
     if (format == CUPSD_TIME_STANDARD)
       snprintf(s, sizeof(s), "[%02d/%s/%04d:%02d:%02d:%02d %+03ld%02ld]",
-              date->tm_mday, months[date->tm_mon], 1900 + date->tm_year,
-              date->tm_hour, date->tm_min, date->tm_sec,
+              date.tm_mday, months[date.tm_mon], 1900 + date.tm_year,
+              date.tm_hour, date.tm_min, date.tm_sec,
 #ifdef HAVE_TM_GMTOFF
-              date->tm_gmtoff / 3600, (date->tm_gmtoff / 60) % 60);
+              date.tm_gmtoff / 3600, (date.tm_gmtoff / 60) % 60);
 #else
               timezone / 3600, (timezone / 60) % 60);
 #endif /* HAVE_TM_GMTOFF */
     else
       snprintf(s, sizeof(s), "[%02d/%s/%04d:%02d:%02d:%02d.%06d %+03ld%02ld]",
-              date->tm_mday, months[date->tm_mon], 1900 + date->tm_year,
-              date->tm_hour, date->tm_min, date->tm_sec, (int)t->tv_usec,
+              date.tm_mday, months[date.tm_mon], 1900 + date.tm_year,
+              date.tm_hour, date.tm_min, date.tm_sec, (int)t->tv_usec,
 #ifdef HAVE_TM_GMTOFF
-              date->tm_gmtoff / 3600, (date->tm_gmtoff / 60) % 60);
+              date.tm_gmtoff / 3600, (date.tm_gmtoff / 60) % 60);
 #else
               timezone / 3600, (timezone / 60) % 60);
 #endif /* HAVE_TM_GMTOFF */
index 75ef4c0d2bd8c665d742c9fe480be99644c8d157..80690397da3ef0e6a13af92f373c2daacca7c0fc 100644 (file)
@@ -1478,7 +1478,7 @@ cupsdSaveAllPrinters(void)
                        *name;          /* Current user/group name */
   cupsd_printer_t      *printer;       /* Current printer class */
   time_t               curtime;        /* Current time */
-  struct tm            *curdate;       /* Current date */
+  struct tm            curdate;        /* Current date */
   cups_option_t                *option;        /* Current option */
   ipp_attribute_t      *marker;        /* Current marker attribute */
 
@@ -1498,9 +1498,9 @@ cupsdSaveAllPrinters(void)
   * Write a small header to the file...
   */
 
-  curtime = time(NULL);
-  curdate = localtime(&curtime);
-  strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", curdate);
+  time(&curtime);
+  localtime_r(&curtime, &curdate);
+  strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", &curdate);
 
   cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n");
   cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
index 3267a2ff6375a71bccda7ab9feca29b42755942b..15acedca8d07a5b9ce6af4b23fc75aa5ac38e00c 100644 (file)
@@ -1025,7 +1025,7 @@ cupsdSaveAllSubscriptions(void)
                        temp[1024];     /* Temporary string */
   cupsd_subscription_t *sub;           /* Current subscription */
   time_t               curtime;        /* Current time */
-  struct tm            *curdate;       /* Current date */
+  struct tm            curdate;        /* Current date */
   unsigned             mask;           /* Current event mask */
   const char           *name;          /* Current event name */
   int                  hex;            /* Non-zero if we are writing hex data */
@@ -1046,9 +1046,9 @@ cupsdSaveAllSubscriptions(void)
   * Write a small header to the file...
   */
 
-  curtime = time(NULL);
-  curdate = localtime(&curtime);
-  strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", curdate);
+  time(&curtime);
+  localtime_r(&curtime, &curdate);
+  strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", &curdate);
 
   cupsFilePuts(fp, "# Subscription configuration file for " CUPS_SVERSION "\n");
   cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
index 62489430b1a1e69cb3baf883697ffd9bfeb6dc91..2b921e235410f8db876d8901aabd759a860b5bf1 100644 (file)
@@ -7645,10 +7645,12 @@ time_string(time_t tv,                  /* I - Time value */
             char   *buffer,            /* I - Buffer */
            size_t bufsize)             /* I - Size of buffer */
 {
-  struct tm    *curtime = localtime(&tv);
-                                       /* Local time */
+  struct tm    date;                   /* Local time and date */
+
+  localtime_r(&tv, &date);
+
+  strftime(buffer, bufsize, "%X", &date);
 
-  strftime(buffer, bufsize, "%X", curtime);
   return (buffer);
 }
 
index e54b78ad38a257e4db6a1147798a56dbb3f9a26e..a3a694d5fa4e312b3f3323d1930f886ac38ad5c8 100644 (file)
@@ -2162,16 +2162,16 @@ static char *                           /* O - ISO 8601 date/time string */
 iso_date(const ipp_uchar_t *date)      /* I - IPP (RFC 1903) date/time value */
 {
   time_t       utctime;                /* UTC time since 1970 */
-  struct tm    *utcdate;               /* UTC date/time */
+  struct tm    utcdate;                /* UTC date/time */
   static char  buffer[255];            /* String buffer */
 
 
   utctime = ippDateToTime(date);
-  utcdate = gmtime(&utctime);
+  gmtime_r(&utctime, &utcdate);
 
   snprintf(buffer, sizeof(buffer), "%04d-%02d-%02dT%02d:%02d:%02dZ",
-          utcdate->tm_year + 1900, utcdate->tm_mon + 1, utcdate->tm_mday,
-          utcdate->tm_hour, utcdate->tm_min, utcdate->tm_sec);
+          utcdate.tm_year + 1900, utcdate.tm_mon + 1, utcdate.tm_mday,
+          utcdate.tm_hour, utcdate.tm_min, utcdate.tm_sec);
 
   return (buffer);
 }
index d85865a6ffcddd958ca33f23812104ddee065044..4ad1dc8f13b8aa046bd8c715a8d252cd557c115b 100644 (file)
 #define write          _write
 
 
+/*
+ * Microsoft "safe" functions use a different argument order than POSIX...
+ */
+
+#define gmtime_r(t,tm) gmtime_s(tm,t)
+#define localtime_r(t,tm) localtime_s(tm,t)
+
+
 /*
  * Map the POSIX strcasecmp() and strncasecmp() functions to the Win32
  * _stricmp() and _strnicmp() functions...