unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob 62dabd7fae8f5e8d3b9f2ebbf086d1b544308794 8802 bytes (raw)
name: gnu/packages/patches/wget-hsts-portability.patch 	 # note: path name is non-authoritative(*)

  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
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
 
From 9a3479a23c15cd7234a54296ae50c48f29c427ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tim=20R=C3=BChsen?= <tim.ruehsen@gmx.de>
Date: Sun, 20 Mar 2022 12:18:20 +0100
Subject: [PATCH] Fix HSTS portability by using int64_t instead of time_t.

* src/hsts.c: Use int64_t instead of time_t.
* src/http.c: Use int64_t for parsing Strict-Transport-Security.
---
 src/hsts.c | 41 ++++++++++++++++++++---------------------
 src/hsts.h |  2 +-
 src/http.c | 24 ++++++++++++------------
 3 files changed, 33 insertions(+), 34 deletions(-)

diff --git a/src/hsts.c b/src/hsts.c
index 0a014401..72c5e936 100644
--- a/src/hsts.c
+++ b/src/hsts.c
@@ -61,8 +61,8 @@ struct hsts_kh {
 };
 
 struct hsts_kh_info {
-  time_t created;
-  time_t max_age;
+  int64_t created;
+  int64_t max_age;
   bool include_subdomains;
 };
 
@@ -166,7 +166,7 @@ end:
 static bool
 hsts_new_entry_internal (hsts_store_t store,
                          const char *host, int port,
-                         time_t created, time_t max_age,
+                         int64_t created, int64_t max_age,
                          bool include_subdomains,
                          bool check_validity,
                          bool check_expired,
@@ -216,21 +216,21 @@ bail:
 static bool
 hsts_add_entry (hsts_store_t store,
                 const char *host, int port,
-                time_t max_age, bool include_subdomains)
+                int64_t max_age, bool include_subdomains)
 {
-  time_t t = time (NULL);
+  int64_t t = (int64_t) time (NULL);
 
   /* It might happen time() returned -1 */
-  return (t == (time_t)(-1) ?
+  return (t == -1) ?
       false :
-      hsts_new_entry_internal (store, host, port, t, max_age, include_subdomains, false, true, false));
+      hsts_new_entry_internal (store, host, port, t, max_age, include_subdomains, false, true, false);
 }
 
 /* Creates a new entry, unless an identical one already exists. */
 static bool
 hsts_new_entry (hsts_store_t store,
                 const char *host, int port,
-                time_t created, time_t max_age,
+                int64_t created, int64_t max_age,
                 bool include_subdomains)
 {
   return hsts_new_entry_internal (store, host, port, created, max_age, include_subdomains, true, true, true);
@@ -245,7 +245,7 @@ hsts_remove_entry (hsts_store_t store, struct hsts_kh *kh)
 static bool
 hsts_store_merge (hsts_store_t store,
                   const char *host, int port,
-                  time_t created, time_t max_age,
+                  int64_t created, int64_t max_age,
                   bool include_subdomains)
 {
   enum hsts_kh_match match_type = NO_MATCH;
@@ -276,11 +276,11 @@ hsts_read_database (hsts_store_t store, FILE *fp, bool merge_with_existing_entri
   size_t len = 0;
   int items_read;
   bool result = false;
-  bool (*func)(hsts_store_t, const char *, int, time_t, time_t, bool);
+  bool (*func)(hsts_store_t, const char *, int, int64_t, int64_t, bool);
 
   char host[256];
   int port;
-  time_t created, max_age;
+  int64_t created, max_age;
   int include_subdomains;
 
   func = (merge_with_existing_entries ? hsts_store_merge : hsts_new_entry);
@@ -326,10 +326,9 @@ hsts_store_dump (hsts_store_t store, FILE *fp)
       struct hsts_kh *kh = (struct hsts_kh *) it.key;
       struct hsts_kh_info *khi = (struct hsts_kh_info *) it.value;
 
-      if (fprintf (fp, "%s\t%d\t%d\t%lu\t%lu\n",
+      if (fprintf (fp, "%s\t%d\t%d\t%" PRId64 "\t%" PRId64 "\n",
                    kh->host, kh->explicit_port, khi->include_subdomains,
-                   (unsigned long) khi->created,
-                   (unsigned long) khi->max_age) < 0)
+                   khi->created, khi->max_age) < 0)
         {
           logprintf (LOG_ALWAYS, "Could not write the HSTS database correctly.\n");
           break;
@@ -439,7 +438,7 @@ hsts_match (hsts_store_t store, struct url *u)
 bool
 hsts_store_entry (hsts_store_t store,
                   enum url_scheme scheme, const char *host, int port,
-                  time_t max_age, bool include_subdomains)
+                  int64_t max_age, bool include_subdomains)
 {
   bool result = false;
   enum hsts_kh_match match = NO_MATCH;
@@ -464,9 +463,9 @@ hsts_store_entry (hsts_store_t store,
                * 'created' field too. The RFC also states that we have to
                * update the entry each time we see HSTS header.
                * See also Section 11.2. */
-              time_t t = time (NULL);
+              int64_t t = (int64_t) time (NULL);
 
-              if (t != (time_t)(-1) && t != entry->created)
+              if (t != -1 && t != entry->created)
                 {
                   entry->created = t;
                   entry->max_age = max_age;
@@ -792,7 +791,7 @@ test_hsts_read_database (void)
   hsts_store_t table;
   char *file = NULL;
   FILE *fp = NULL;
-  time_t created = time(NULL) - 10;
+  int64_t created = time(NULL) - 10;
 
   if (opt.homedir)
     {
@@ -801,9 +800,9 @@ test_hsts_read_database (void)
       if (fp)
         {
           fputs ("# dummy comment\n", fp);
-          fprintf (fp, "foo.example.com\t0\t1\t%lu\t123\n",(unsigned long) created);
-          fprintf (fp, "bar.example.com\t0\t0\t%lu\t456\n", (unsigned long) created);
-          fprintf (fp, "test.example.com\t8080\t0\t%lu\t789\n", (unsigned long) created);
+          fprintf (fp, "foo.example.com\t0\t1\t%" PRId64 "\t123\n", created);
+          fprintf (fp, "bar.example.com\t0\t0\t%" PRId64 "\t456\n", created);
+          fprintf (fp, "test.example.com\t8080\t0\t%" PRId64 "\t789\n", created);
           fclose (fp);
 
           table = hsts_store_open (file);
diff --git a/src/hsts.h b/src/hsts.h
index 6ecd5060..be048944 100644
--- a/src/hsts.h
+++ b/src/hsts.h
@@ -46,7 +46,7 @@ bool hsts_store_has_changed (hsts_store_t);
 
 bool hsts_store_entry (hsts_store_t,
                        enum url_scheme, const char *, int,
-                       time_t, bool);
+                       int64_t, bool);
 bool hsts_match (hsts_store_t, struct url *);
 
 #endif /* HAVE_HSTS */
diff --git a/src/http.c b/src/http.c
index f61c99a7..87b51b00 100644
--- a/src/http.c
+++ b/src/http.c
@@ -1300,7 +1300,7 @@ parse_content_disposition (const char *hdr, char **filename)
 
 #ifdef HAVE_HSTS
 static bool
-parse_strict_transport_security (const char *header, time_t *max_age, bool *include_subdomains)
+parse_strict_transport_security (const char *header, int64_t *max_age, bool *include_subdomains)
 {
   param_token name, value;
   const char *c_max_age = NULL;
@@ -1330,7 +1330,7 @@ parse_strict_transport_security (const char *header, time_t *max_age, bool *incl
            * Also, time_t is normally defined as a long, so this should not break.
            */
           if (max_age)
-            *max_age = (time_t) strtol (c_max_age, NULL, 10);
+            *max_age = (int64_t) strtoll (c_max_age, NULL, 10);
           if (include_subdomains)
             *include_subdomains = is;
 
@@ -3184,9 +3184,6 @@ gethttp (const struct url *u, struct url *original_url, struct http_stat *hs,
 #else
   extern hsts_store_t hsts_store;
 #endif
-  const char *hsts_params;
-  time_t max_age;
-  bool include_subdomains;
 #endif
 
   int sock = -1;
@@ -3674,21 +3671,24 @@ gethttp (const struct url *u, struct url *original_url, struct http_stat *hs,
 #ifdef HAVE_HSTS
   if (opt.hsts && hsts_store)
     {
-      hsts_params = resp_header_strdup (resp, "Strict-Transport-Security");
+      int64_t max_age;
+      const char *hsts_params = resp_header_strdup (resp, "Strict-Transport-Security");
+      bool include_subdomains;
+
       if (parse_strict_transport_security (hsts_params, &max_age, &include_subdomains))
         {
           /* process strict transport security */
           if (hsts_store_entry (hsts_store, u->scheme, u->host, u->port, max_age, include_subdomains))
-            DEBUGP(("Added new HSTS host: %s:%u (max-age: %lu, includeSubdomains: %s)\n",
+            DEBUGP(("Added new HSTS host: %s:%" PRIu32 " (max-age: %" PRId64 ", includeSubdomains: %s)\n",
                    u->host,
-                   (unsigned) u->port,
-                   (unsigned long) max_age,
+                   (uint32_t) u->port,
+                   max_age,
                    (include_subdomains ? "true" : "false")));
           else
-            DEBUGP(("Updated HSTS host: %s:%u (max-age: %lu, includeSubdomains: %s)\n",
+            DEBUGP(("Updated HSTS host: %s:%" PRIu32 " (max-age: %" PRId64 ", includeSubdomains: %s)\n",
                    u->host,
-                   (unsigned) u->port,
-                   (unsigned long) max_age,
+                   (uint32_t) u->port,
+                   max_age,
                    (include_subdomains ? "true" : "false")));
         }
       xfree (hsts_params);
-- 
GitLab


debug log:

solving 62dabd7fae ...
found 62dabd7fae in https://yhetil.org/guix-devel/ZDsQbYnPL+kUZjcN@jurong/

applying [1/1] https://yhetil.org/guix-devel/ZDsQbYnPL+kUZjcN@jurong/
diff --git a/gnu/packages/patches/wget-hsts-portability.patch b/gnu/packages/patches/wget-hsts-portability.patch
new file mode 100644
index 0000000000..62dabd7fae

1:26: trailing whitespace.
 
1:34: trailing whitespace.
 
1:53: trailing whitespace.
 
1:61: trailing whitespace.
 
1:86: trailing whitespace.
 
Checking patch gnu/packages/patches/wget-hsts-portability.patch...
Applied patch gnu/packages/patches/wget-hsts-portability.patch cleanly.
warning: squelched 12 whitespace errors
warning: 17 lines add whitespace errors.

index at:
100644 62dabd7fae8f5e8d3b9f2ebbf086d1b544308794	gnu/packages/patches/wget-hsts-portability.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).