On Fri, May 10 2019, Holger Mikolon <hol...@mikolon.com> wrote:
> The comment above priv_localtime() says, the obtained localtime (from the 
> privileged process) is cached for about one minute. However, since the 
> according if statement compares the wrong variable, the caching doesn't 
> happen. This bug is there since the very first file version (from 15+ 
> years ago).

The variables could have more meaningful names, also the reuse of
variable "gt" looks hackish, but the current code looks correct to me.

Does the diff below make things clearer?


--- privsep.c.~1.53.~   Sat May 11 14:17:40 2019
+++ privsep.c   Sat May 11 14:20:30 2019
@@ -724,10 +724,12 @@ struct    tm *
 priv_localtime(const time_t *t)
 {
        static struct tm lt, gt0;
-       static struct tm *gt = NULL;
        static char zone[PATH_MAX];
+       static int cached = 0;
 
-       if (gt != NULL) {
+       if (cached) {
+               struct tm *gt;
+
                gt = gmtime(t);
                gt0.tm_sec = gt->tm_sec;
                gt0.tm_zone = gt->tm_zone;
@@ -749,7 +751,7 @@ priv_localtime(const time_t *t)
                lt.tm_zone = NULL;
 
        gt0.tm_zone = NULL;
-       gt = &gt0;
+       cached = 1;
 
        return &lt;
 }

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to