]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sourcestats: make reading/writing dump files Y2106 ready
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 19 Aug 2016 14:32:56 +0000 (16:32 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 22 Aug 2016 13:05:48 +0000 (15:05 +0200)
The sample times were written and read as unsigned long, which would
overflow in year 2016 on platforms that have 32-bit long.

sourcestats.c

index 9a6371c1dd79e33ba37a2881622620a6d68e48ee..7d3fd0f9244c9cbd812d93805612134790e894b6 100644 (file)
@@ -825,8 +825,14 @@ SST_SaveToFile(SST_Stats inst, FILE *out)
     i = get_runsbuf_index(inst, m);
     j = get_buf_index(inst, m);
 
-    fprintf(out, "%08lx %08lx %.6e %.6e %.6e %.6e %.6e %.6e %.6e %d\n",
-            (unsigned long) inst->sample_times[i].tv_sec,
+    fprintf(out,
+#ifdef HAVE_LONG_TIME_T
+            "%08"PRIx64" %08lx %.6e %.6e %.6e %.6e %.6e %.6e %.6e %d\n",
+            (uint64_t)inst->sample_times[i].tv_sec,
+#else
+            "%08lx %08lx %.6e %.6e %.6e %.6e %.6e %.6e %.6e %d\n",
+            (unsigned long)inst->sample_times[i].tv_sec,
+#endif
             (unsigned long)inst->sample_times[i].tv_nsec / 1000,
             inst->offsets[i],
             inst->orig_offsets[j],
@@ -846,9 +852,14 @@ SST_SaveToFile(SST_Stats inst, FILE *out)
 int
 SST_LoadFromFile(SST_Stats inst, FILE *in)
 {
+#ifdef HAVE_LONG_TIME_T
+  uint64_t sec;
+#else
+  unsigned long sec;
+#endif
+  unsigned long usec;
   int i, line_number;
   char line[1024];
-  unsigned long sec, usec;
   double weight;
 
   assert(!inst->n_samples);
@@ -861,7 +872,12 @@ SST_LoadFromFile(SST_Stats inst, FILE *in)
 
     for (i=0; i<inst->n_samples; i++) {
       if (!fgets(line, sizeof(line), in) ||
-          (sscanf(line, "%lx%lx%lf%lf%lf%lf%lf%lf%lf%d\n",
+          (sscanf(line,
+#ifdef HAVE_LONG_TIME_T
+                  "%"SCNx64"%lx%lf%lf%lf%lf%lf%lf%lf%d\n",
+#else
+                  "%lx%lx%lf%lf%lf%lf%lf%lf%lf%d\n",
+#endif
                   &(sec), &(usec),
                   &(inst->offsets[i]),
                   &(inst->orig_offsets[i]),