summaryrefslogtreecommitdiff
path: root/skip/ceph/11-parse_rfc1123_alt.patch
blob: 5b54c4e6d3c861b76b87f1ed09190f5c7af5f14a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Patch by Robin Mueller

libmusl doesn't support the z character in the format pattern for strptime this 
is a special functionality of glibc.

patch is slightly adapted version of glibc code:
https://elixir.bootlin.com/glibc/latest/source/time/strptime_l.c#L776

--- a/src/rgw/rgw_common.cc	2021-07-08 16:03:56.000000000 +0200
+++ b/src/rgw/rgw_common.cc	2021-08-18 13:08:22.938903459 +0200
@@ -531,7 +531,41 @@
 {
   // FIPS zeroization audit 20191115: this memset is not security related.
   memset(t, 0, sizeof(*t));
-  return check_str_end(strptime(s, "%a, %d %b %Y %H:%M:%S %z", t));
+  s = strptime(s, "%a, %d %b %Y %H:%M:%S", t);
+  if (s) {
+    s++;
+    int val;
+    val = 0;
+    while (isspace(*s))
+      ++s;
+    if (*s == 'Z') {
+        ++s;
+        t->tm_gmtoff = 0;
+    } else {
+      if (*s != '+' && *s != '-')
+        return 0;
+      bool neg = *s++ == '-';
+      int n = 0;
+      while (n < 4 && *s >= '0' && *s <= '9') {
+        val = val * 10 + *s++ - '0';
+        ++n;
+        if (*s == ':' && n == 2 && isdigit (*(s + 1)))
+          ++s;
+      }
+      if (n == 2)
+        val *= 100;
+      else if (n != 4)
+        /* Only two or four digits recognized.  */
+        return 0;
+      else if (val % 100 >= 60)
+        /* Minutes valid range is 0 through 59.  */
+        return 0;
+      t->tm_gmtoff = (val / 100) * 3600 + (val % 100) * 60;
+      if (neg)
+        t->tm_gmtoff = -t->tm_gmtoff;
+    }
+  }
+  return check_str_end(s);
 }
 
 bool parse_rfc2616(const char *s, struct tm *t)