summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--recipes-extended/diod/diod_1.0.24.bb1
-rw-r--r--recipes-extended/diod/files/0002-Handle-various-time_t-sizes-in-printf-and-scanf.patch100
2 files changed, 101 insertions, 0 deletions
diff --git a/recipes-extended/diod/diod_1.0.24.bb b/recipes-extended/diod/diod_1.0.24.bb
index 5e191dc0..6019fbfb 100644
--- a/recipes-extended/diod/diod_1.0.24.bb
+++ b/recipes-extended/diod/diod_1.0.24.bb
@@ -14,6 +14,7 @@ SRC_URI = "git://github.com/chaos/diod.git;protocol=https;branch=master \
14 file://diod \ 14 file://diod \
15 file://diod.conf \ 15 file://diod.conf \
16 file://0001-build-Find-lua-with-pkg-config.patch \ 16 file://0001-build-Find-lua-with-pkg-config.patch \
17 file://0002-Handle-various-time_t-sizes-in-printf-and-scanf.patch \
17 " 18 "
18DEPENDS = "libcap ncurses tcp-wrappers lua" 19DEPENDS = "libcap ncurses tcp-wrappers lua"
19 20
diff --git a/recipes-extended/diod/files/0002-Handle-various-time_t-sizes-in-printf-and-scanf.patch b/recipes-extended/diod/files/0002-Handle-various-time_t-sizes-in-printf-and-scanf.patch
new file mode 100644
index 00000000..3c13c101
--- /dev/null
+++ b/recipes-extended/diod/files/0002-Handle-various-time_t-sizes-in-printf-and-scanf.patch
@@ -0,0 +1,100 @@
1From 04b0c5a5cb9e32090b177ff7327ad3260783abe0 Mon Sep 17 00:00:00 2001
2From: Ola x Nilsson <olani@axis.com>
3Date: Mon, 15 Apr 2024 17:31:44 +0200
4Subject: [PATCH] Handle various time_t sizes in printf and scanf
5
6The members of the timeval struct are both signed (defined by POSIX)
7and typically both 64 bits on a system where time_t is 64 bits. This
8is possible also on 32 bit systems where time_t is larger to handle
9the 2038 problem.
10
11It's practically impossible to find a type and printf format that
12works even on all glibc systems. Play it safe and always use printf
13with intmax_t and explict int64_t variables for scanf.
14
15Upstream-Status: Submitted [https://github.com/chaos/diod/pull/100]
16Signed-off-by: Ola x Nilsson <olani@axis.com>
17---
18 libnpfs/conn.c | 5 +++--
19 libnpfs/ctl.c | 7 ++++---
20 utils/dioddate.c | 8 +++++++-
21 3 files changed, 14 insertions(+), 6 deletions(-)
22
23diff --git a/libnpfs/conn.c b/libnpfs/conn.c
24index 6e85fff..c34c840 100644
25--- a/libnpfs/conn.c
26+++ b/libnpfs/conn.c
27@@ -16,6 +16,7 @@
28 #include <stdio.h>
29 #include <string.h>
30 #include <stdint.h>
31+#include <inttypes.h>
32 #include <stdarg.h>
33 #include <errno.h>
34 #include <pthread.h>
35@@ -133,8 +134,8 @@ _debug_trace (Npsrv *srv, Npfcall *fc)
36 (void)gettimeofday(&b, NULL);
37 (void)gettimeofday(&a, NULL);
38 timersub(&a, &b, &c);
39- np_logmsg(srv, "[%lu.%-3lu] %s",
40- c.tv_sec, c.tv_usec/1000, s);
41+ np_logmsg(srv, "[%"PRIdMAX".%-3"PRIdMAX"] %s",
42+ (intmax_t)c.tv_sec, (intmax_t)c.tv_usec/1000, s);
43 } else
44 np_logmsg(srv, "%s", s);
45 }
46diff --git a/libnpfs/ctl.c b/libnpfs/ctl.c
47index f40cde4..317a22e 100644
48--- a/libnpfs/ctl.c
49+++ b/libnpfs/ctl.c
50@@ -16,6 +16,7 @@
51 #include <stdio.h>
52 #include <string.h>
53 #include <stdint.h>
54+#include <inttypes.h>
55 #include <stdarg.h>
56 #include <pthread.h>
57 #include <errno.h>
58@@ -291,9 +292,9 @@ _ctl_get_date (char *name, void *a)
59 np_uerror (errno);
60 goto error;
61 }
62- if (aspf (&s, &len, "%lu.%lu %d.%d\n",
63- tv.tv_sec, tv.tv_usec,
64- tz.tz_minuteswest, tz.tz_dsttime) < 0) {
65+ if (aspf (&s, &len, "%"PRIdMAX".%"PRIdMAX" %d.%d\n",
66+ (uintmax_t)tv.tv_sec, (uintmax_t)tv.tv_usec,
67+ tz.tz_minuteswest, tz.tz_dsttime) < 0) {
68 np_uerror (ENOMEM);
69 goto error;
70 }
71diff --git a/utils/dioddate.c b/utils/dioddate.c
72index bde002f..f392792 100644
73--- a/utils/dioddate.c
74+++ b/utils/dioddate.c
75@@ -21,6 +21,7 @@
76 #include <unistd.h>
77 #include <stdlib.h>
78 #include <stdint.h>
79+#include <inttypes.h>
80 #include <stdarg.h>
81 #include <stdio.h>
82 #if HAVE_GETOPT_H
83@@ -142,11 +143,16 @@ main (int argc, char *argv[])
84 errn (np_rerror (), "error reading date");
85 goto done;
86 }
87- if (sscanf (buf, "%lu.%lu %d.%d", &tv.tv_sec, &tv.tv_usec,
88+
89+ int64_t sec = 0, usec = 0;
90+ if (sscanf (buf, "%"SCNd64".%"SCNd64" %d.%d", &sec, &usec,
91 &tz.tz_minuteswest, &tz.tz_dsttime) != 4) {
92 msg ("error scanning returned date: %s", buf);
93 goto done;
94 }
95+ tv.tv_sec = sec;
96+ tv.tv_usec = usec;
97+
98 if (Sopt) {
99 if (settimeofday (&tv, &tz) < 0)
100 err_exit ("settimeofday");