Blame


1 a440fac0 2018-09-06 stsp /*
2 5aa81393 2020-01-06 stsp * Copyright (c) 2018, 2019, 2020 Stefan Sperling <stsp@openbsd.org>
3 a440fac0 2018-09-06 stsp *
4 a440fac0 2018-09-06 stsp * Permission to use, copy, modify, and distribute this software for any
5 a440fac0 2018-09-06 stsp * purpose with or without fee is hereby granted, provided that the above
6 a440fac0 2018-09-06 stsp * copyright notice and this permission notice appear in all copies.
7 a440fac0 2018-09-06 stsp *
8 a440fac0 2018-09-06 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 a440fac0 2018-09-06 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 a440fac0 2018-09-06 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 a440fac0 2018-09-06 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 a440fac0 2018-09-06 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 a440fac0 2018-09-06 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 a440fac0 2018-09-06 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 a440fac0 2018-09-06 stsp */
16 a440fac0 2018-09-06 stsp
17 a440fac0 2018-09-06 stsp #include <sys/types.h>
18 a440fac0 2018-09-06 stsp #include <sys/stat.h>
19 a440fac0 2018-09-06 stsp #include <sys/uio.h>
20 a440fac0 2018-09-06 stsp #include <sys/socket.h>
21 a440fac0 2018-09-06 stsp #include <sys/wait.h>
22 2b0ae357 2022-01-10 thomas #include <sys/mman.h>
23 a440fac0 2018-09-06 stsp
24 a440fac0 2018-09-06 stsp #include <errno.h>
25 a440fac0 2018-09-06 stsp #include <stdio.h>
26 a440fac0 2018-09-06 stsp #include <stdlib.h>
27 a440fac0 2018-09-06 stsp #include <string.h>
28 a440fac0 2018-09-06 stsp #include <stdint.h>
29 a440fac0 2018-09-06 stsp #include <zlib.h>
30 a440fac0 2018-09-06 stsp #include <ctype.h>
31 a440fac0 2018-09-06 stsp #include <limits.h>
32 a440fac0 2018-09-06 stsp #include <time.h>
33 ad242220 2018-09-08 stsp #include <unistd.h>
34 dd038bc6 2021-09-21 thomas.ad
35 dd038bc6 2021-09-21 thomas.ad #include "got_compat.h"
36 a440fac0 2018-09-06 stsp
37 a440fac0 2018-09-06 stsp #include "got_error.h"
38 a440fac0 2018-09-06 stsp #include "got_object.h"
39 a440fac0 2018-09-06 stsp #include "got_repository.h"
40 a440fac0 2018-09-06 stsp #include "got_opentemp.h"
41 324d37e7 2019-05-11 stsp #include "got_path.h"
42 a440fac0 2018-09-06 stsp
43 a440fac0 2018-09-06 stsp #include "got_lib_sha1.h"
44 a440fac0 2018-09-06 stsp #include "got_lib_delta.h"
45 41fa1437 2018-11-05 stsp #include "got_lib_inflate.h"
46 41fa1437 2018-11-05 stsp #include "got_lib_object.h"
47 3022d272 2019-11-14 stsp #include "got_lib_object_parse.h"
48 6bef87be 2018-09-11 stsp #include "got_lib_object_cache.h"
49 15a94983 2018-12-23 stsp #include "got_lib_pack.h"
50 15a94983 2018-12-23 stsp #include "got_lib_privsep.h"
51 ad242220 2018-09-08 stsp #include "got_lib_repository.h"
52 a440fac0 2018-09-06 stsp
53 a440fac0 2018-09-06 stsp #ifndef nitems
54 a440fac0 2018-09-06 stsp #define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
55 a440fac0 2018-09-06 stsp #endif
56 ca6e02ac 2020-01-07 stsp
57 ca6e02ac 2020-01-07 stsp struct got_object_id *
58 ca6e02ac 2020-01-07 stsp got_object_id_dup(struct got_object_id *id1)
59 ca6e02ac 2020-01-07 stsp {
60 ca6e02ac 2020-01-07 stsp struct got_object_id *id2;
61 ca6e02ac 2020-01-07 stsp
62 ca6e02ac 2020-01-07 stsp id2 = malloc(sizeof(*id2));
63 ca6e02ac 2020-01-07 stsp if (id2 == NULL)
64 ca6e02ac 2020-01-07 stsp return NULL;
65 ca6e02ac 2020-01-07 stsp memcpy(id2, id1, sizeof(*id2));
66 ca6e02ac 2020-01-07 stsp return id2;
67 ca6e02ac 2020-01-07 stsp }
68 a440fac0 2018-09-06 stsp
69 f054b67a 2018-11-05 stsp int
70 f054b67a 2018-11-05 stsp got_object_id_cmp(const struct got_object_id *id1,
71 f054b67a 2018-11-05 stsp const struct got_object_id *id2)
72 f054b67a 2018-11-05 stsp {
73 f054b67a 2018-11-05 stsp return memcmp(id1->sha1, id2->sha1, SHA1_DIGEST_LENGTH);
74 f054b67a 2018-11-05 stsp }
75 f054b67a 2018-11-05 stsp
76 2ff12563 2018-09-15 stsp const struct got_error *
77 5df4932d 2018-11-05 stsp got_object_qid_alloc_partial(struct got_object_qid **qid)
78 5df4932d 2018-11-05 stsp {
79 5df4932d 2018-11-05 stsp const struct got_error *err = NULL;
80 5df4932d 2018-11-05 stsp
81 5df4932d 2018-11-05 stsp *qid = malloc(sizeof(**qid));
82 5df4932d 2018-11-05 stsp if (*qid == NULL)
83 638f9024 2019-05-13 stsp return got_error_from_errno("malloc");
84 5df4932d 2018-11-05 stsp
85 5df4932d 2018-11-05 stsp (*qid)->id = malloc(sizeof(*((*qid)->id)));
86 5df4932d 2018-11-05 stsp if ((*qid)->id == NULL) {
87 638f9024 2019-05-13 stsp err = got_error_from_errno("malloc");
88 5df4932d 2018-11-05 stsp got_object_qid_free(*qid);
89 5df4932d 2018-11-05 stsp *qid = NULL;
90 5df4932d 2018-11-05 stsp return err;
91 5df4932d 2018-11-05 stsp }
92 74a2356f 2021-06-18 stsp (*qid)->data = NULL;
93 5df4932d 2018-11-05 stsp
94 5df4932d 2018-11-05 stsp return NULL;
95 5df4932d 2018-11-05 stsp }
96 5df4932d 2018-11-05 stsp
97 5df4932d 2018-11-05 stsp const struct got_error *
98 2ff12563 2018-09-15 stsp got_object_id_str(char **outbuf, struct got_object_id *id)
99 2ff12563 2018-09-15 stsp {
100 2ff12563 2018-09-15 stsp static const size_t len = SHA1_DIGEST_STRING_LENGTH;
101 2ff12563 2018-09-15 stsp
102 2ff12563 2018-09-15 stsp *outbuf = malloc(len);
103 2ff12563 2018-09-15 stsp if (*outbuf == NULL)
104 638f9024 2019-05-13 stsp return got_error_from_errno("malloc");
105 2ff12563 2018-09-15 stsp
106 2ff12563 2018-09-15 stsp if (got_sha1_digest_to_str(id->sha1, *outbuf, len) == NULL) {
107 2ff12563 2018-09-15 stsp free(*outbuf);
108 2ff12563 2018-09-15 stsp *outbuf = NULL;
109 2ff12563 2018-09-15 stsp return got_error(GOT_ERR_BAD_OBJ_ID_STR);
110 2ff12563 2018-09-15 stsp }
111 a440fac0 2018-09-06 stsp
112 2ff12563 2018-09-15 stsp return NULL;
113 2ff12563 2018-09-15 stsp }
114 2ff12563 2018-09-15 stsp
115 03fa71c8 2018-09-06 stsp void
116 03fa71c8 2018-09-06 stsp got_object_close(struct got_object *obj)
117 03fa71c8 2018-09-06 stsp {
118 03fa71c8 2018-09-06 stsp if (obj->refcnt > 0) {
119 03fa71c8 2018-09-06 stsp obj->refcnt--;
120 03fa71c8 2018-09-06 stsp if (obj->refcnt > 0)
121 03fa71c8 2018-09-06 stsp return;
122 03fa71c8 2018-09-06 stsp }
123 03fa71c8 2018-09-06 stsp
124 03fa71c8 2018-09-06 stsp if (obj->flags & GOT_OBJ_FLAG_DELTIFIED) {
125 03fa71c8 2018-09-06 stsp struct got_delta *delta;
126 dbdddfee 2021-06-23 naddy while (!STAILQ_EMPTY(&obj->deltas.entries)) {
127 dbdddfee 2021-06-23 naddy delta = STAILQ_FIRST(&obj->deltas.entries);
128 dbdddfee 2021-06-23 naddy STAILQ_REMOVE_HEAD(&obj->deltas.entries, entry);
129 2256993b 2019-07-15 stsp free(delta);
130 03fa71c8 2018-09-06 stsp }
131 03fa71c8 2018-09-06 stsp }
132 03fa71c8 2018-09-06 stsp free(obj);
133 03fa71c8 2018-09-06 stsp }
134 03fa71c8 2018-09-06 stsp
135 8ab9215c 2021-10-15 thomas const struct got_error *
136 8ab9215c 2021-10-15 thomas got_object_raw_close(struct got_raw_object *obj)
137 8ab9215c 2021-10-15 thomas {
138 8ab9215c 2021-10-15 thomas const struct got_error *err = NULL;
139 8ab9215c 2021-10-15 thomas
140 8ab9215c 2021-10-15 thomas if (obj->refcnt > 0) {
141 8ab9215c 2021-10-15 thomas obj->refcnt--;
142 8ab9215c 2021-10-15 thomas if (obj->refcnt > 0)
143 8ab9215c 2021-10-15 thomas return NULL;
144 8ab9215c 2021-10-15 thomas }
145 8ab9215c 2021-10-15 thomas
146 2b0ae357 2022-01-10 thomas if (obj->f == NULL) {
147 2b0ae357 2022-01-10 thomas if (obj->fd != -1) {
148 2b0ae357 2022-01-10 thomas if (munmap(obj->data, obj->hdrlen + obj->size) == -1)
149 2b0ae357 2022-01-10 thomas err = got_error_from_errno("munmap");
150 2b0ae357 2022-01-10 thomas if (close(obj->fd) == -1 && err == NULL)
151 2b0ae357 2022-01-10 thomas err = got_error_from_errno("close");
152 2b0ae357 2022-01-10 thomas } else
153 2b0ae357 2022-01-10 thomas free(obj->data);
154 2b0ae357 2022-01-10 thomas } else {
155 2b0ae357 2022-01-10 thomas if (fclose(obj->f) == EOF && err == NULL)
156 2b0ae357 2022-01-10 thomas err = got_error_from_errno("fclose");
157 2b0ae357 2022-01-10 thomas }
158 8ab9215c 2021-10-15 thomas free(obj);
159 8ab9215c 2021-10-15 thomas return err;
160 8ab9215c 2021-10-15 thomas }
161 8ab9215c 2021-10-15 thomas
162 03fa71c8 2018-09-06 stsp void
163 03fa71c8 2018-09-06 stsp got_object_qid_free(struct got_object_qid *qid)
164 03fa71c8 2018-09-06 stsp {
165 03fa71c8 2018-09-06 stsp free(qid->id);
166 03fa71c8 2018-09-06 stsp free(qid);
167 1785f84a 2018-12-23 stsp }
168 1785f84a 2018-12-23 stsp
169 dd88155e 2019-06-29 stsp void
170 dd88155e 2019-06-29 stsp got_object_id_queue_free(struct got_object_id_queue *ids)
171 dd88155e 2019-06-29 stsp {
172 dd88155e 2019-06-29 stsp struct got_object_qid *qid;
173 dd88155e 2019-06-29 stsp
174 dbdddfee 2021-06-23 naddy while (!STAILQ_EMPTY(ids)) {
175 dbdddfee 2021-06-23 naddy qid = STAILQ_FIRST(ids);
176 dbdddfee 2021-06-23 naddy STAILQ_REMOVE_HEAD(ids, entry);
177 dd88155e 2019-06-29 stsp got_object_qid_free(qid);
178 dd88155e 2019-06-29 stsp }
179 dd88155e 2019-06-29 stsp }
180 dd88155e 2019-06-29 stsp
181 1785f84a 2018-12-23 stsp const struct got_error *
182 1785f84a 2018-12-23 stsp got_object_parse_header(struct got_object **obj, char *buf, size_t len)
183 1785f84a 2018-12-23 stsp {
184 ff2a4428 2019-03-19 stsp const char *obj_labels[] = {
185 ff2a4428 2019-03-19 stsp GOT_OBJ_LABEL_COMMIT,
186 ff2a4428 2019-03-19 stsp GOT_OBJ_LABEL_TREE,
187 ff2a4428 2019-03-19 stsp GOT_OBJ_LABEL_BLOB,
188 ff2a4428 2019-03-19 stsp GOT_OBJ_LABEL_TAG,
189 1785f84a 2018-12-23 stsp };
190 1785f84a 2018-12-23 stsp const int obj_types[] = {
191 1785f84a 2018-12-23 stsp GOT_OBJ_TYPE_COMMIT,
192 1785f84a 2018-12-23 stsp GOT_OBJ_TYPE_TREE,
193 1785f84a 2018-12-23 stsp GOT_OBJ_TYPE_BLOB,
194 1785f84a 2018-12-23 stsp GOT_OBJ_TYPE_TAG,
195 1785f84a 2018-12-23 stsp };
196 1785f84a 2018-12-23 stsp int type = 0;
197 9b31ed65 2022-02-12 thomas size_t size = 0;
198 16aeacf7 2020-11-26 stsp size_t i;
199 9b31ed65 2022-02-12 thomas char *end;
200 1785f84a 2018-12-23 stsp
201 1785f84a 2018-12-23 stsp *obj = NULL;
202 1785f84a 2018-12-23 stsp
203 9b31ed65 2022-02-12 thomas end = memchr(buf, '\0', len);
204 9b31ed65 2022-02-12 thomas if (end == NULL)
205 9ef4ac16 2019-04-13 stsp return got_error(GOT_ERR_BAD_OBJ_HDR);
206 1785f84a 2018-12-23 stsp
207 ff2a4428 2019-03-19 stsp for (i = 0; i < nitems(obj_labels); i++) {
208 ff2a4428 2019-03-19 stsp const char *label = obj_labels[i];
209 ff2a4428 2019-03-19 stsp size_t label_len = strlen(label);
210 1785f84a 2018-12-23 stsp const char *errstr;
211 1785f84a 2018-12-23 stsp
212 9b31ed65 2022-02-12 thomas if (len <= label_len || buf + label_len >= end ||
213 9b31ed65 2022-02-12 thomas strncmp(buf, label, label_len) != 0)
214 1785f84a 2018-12-23 stsp continue;
215 1785f84a 2018-12-23 stsp
216 1785f84a 2018-12-23 stsp type = obj_types[i];
217 ff2a4428 2019-03-19 stsp size = strtonum(buf + label_len, 0, LONG_MAX, &errstr);
218 1785f84a 2018-12-23 stsp if (errstr != NULL)
219 1785f84a 2018-12-23 stsp return got_error(GOT_ERR_BAD_OBJ_HDR);
220 1785f84a 2018-12-23 stsp break;
221 1785f84a 2018-12-23 stsp }
222 1785f84a 2018-12-23 stsp
223 1785f84a 2018-12-23 stsp if (type == 0)
224 1785f84a 2018-12-23 stsp return got_error(GOT_ERR_BAD_OBJ_HDR);
225 1785f84a 2018-12-23 stsp
226 1785f84a 2018-12-23 stsp *obj = calloc(1, sizeof(**obj));
227 1785f84a 2018-12-23 stsp if (*obj == NULL)
228 638f9024 2019-05-13 stsp return got_error_from_errno("calloc");
229 1785f84a 2018-12-23 stsp (*obj)->type = type;
230 9b31ed65 2022-02-12 thomas (*obj)->hdrlen = end - buf + 1;
231 1785f84a 2018-12-23 stsp (*obj)->size = size;
232 1785f84a 2018-12-23 stsp return NULL;
233 1785f84a 2018-12-23 stsp }
234 1785f84a 2018-12-23 stsp
235 1785f84a 2018-12-23 stsp const struct got_error *
236 1785f84a 2018-12-23 stsp got_object_read_header(struct got_object **obj, int fd)
237 1785f84a 2018-12-23 stsp {
238 1785f84a 2018-12-23 stsp const struct got_error *err;
239 23bc48a9 2019-03-19 stsp struct got_inflate_buf zb;
240 dbaa2362 2021-09-28 thomas uint8_t *buf;
241 1785f84a 2018-12-23 stsp const size_t zbsize = 64;
242 1785f84a 2018-12-23 stsp size_t outlen, totlen;
243 1785f84a 2018-12-23 stsp int nbuf = 1;
244 1785f84a 2018-12-23 stsp
245 1785f84a 2018-12-23 stsp *obj = NULL;
246 1785f84a 2018-12-23 stsp
247 1785f84a 2018-12-23 stsp buf = malloc(zbsize);
248 1785f84a 2018-12-23 stsp if (buf == NULL)
249 638f9024 2019-05-13 stsp return got_error_from_errno("malloc");
250 9b31ed65 2022-02-12 thomas buf[0] = '\0';
251 1785f84a 2018-12-23 stsp
252 1e87a3c3 2020-03-18 stsp err = got_inflate_init(&zb, buf, zbsize, NULL);
253 1785f84a 2018-12-23 stsp if (err)
254 1785f84a 2018-12-23 stsp return err;
255 1785f84a 2018-12-23 stsp
256 1785f84a 2018-12-23 stsp totlen = 0;
257 1785f84a 2018-12-23 stsp do {
258 3ab5e33c 2020-03-18 stsp err = got_inflate_read_fd(&zb, fd, &outlen, NULL);
259 1785f84a 2018-12-23 stsp if (err)
260 1785f84a 2018-12-23 stsp goto done;
261 1785f84a 2018-12-23 stsp if (outlen == 0)
262 1785f84a 2018-12-23 stsp break;
263 1785f84a 2018-12-23 stsp totlen += outlen;
264 dedbbd9d 2019-04-13 stsp if (memchr(zb.outbuf, '\0', outlen) == NULL) {
265 dbaa2362 2021-09-28 thomas uint8_t *newbuf;
266 1785f84a 2018-12-23 stsp nbuf++;
267 1785f84a 2018-12-23 stsp newbuf = recallocarray(buf, nbuf - 1, nbuf, zbsize);
268 1785f84a 2018-12-23 stsp if (newbuf == NULL) {
269 638f9024 2019-05-13 stsp err = got_error_from_errno("recallocarray");
270 1785f84a 2018-12-23 stsp goto done;
271 1785f84a 2018-12-23 stsp }
272 1785f84a 2018-12-23 stsp buf = newbuf;
273 1785f84a 2018-12-23 stsp zb.outbuf = newbuf + totlen;
274 1785f84a 2018-12-23 stsp zb.outlen = (nbuf * zbsize) - totlen;
275 1785f84a 2018-12-23 stsp }
276 dedbbd9d 2019-04-13 stsp } while (memchr(zb.outbuf, '\0', outlen) == NULL);
277 1785f84a 2018-12-23 stsp
278 1785f84a 2018-12-23 stsp err = got_object_parse_header(obj, buf, totlen);
279 1785f84a 2018-12-23 stsp done:
280 1785f84a 2018-12-23 stsp free(buf);
281 1785f84a 2018-12-23 stsp got_inflate_end(&zb);
282 1785f84a 2018-12-23 stsp return err;
283 876c234b 2018-09-10 stsp }
284 876c234b 2018-09-10 stsp
285 a440fac0 2018-09-06 stsp struct got_commit_object *
286 a440fac0 2018-09-06 stsp got_object_commit_alloc_partial(void)
287 a440fac0 2018-09-06 stsp {
288 a440fac0 2018-09-06 stsp struct got_commit_object *commit;
289 a440fac0 2018-09-06 stsp
290 a440fac0 2018-09-06 stsp commit = calloc(1, sizeof(*commit));
291 a440fac0 2018-09-06 stsp if (commit == NULL)
292 a440fac0 2018-09-06 stsp return NULL;
293 acf0c7c6 2018-11-05 stsp commit->tree_id = malloc(sizeof(*commit->tree_id));
294 a440fac0 2018-09-06 stsp if (commit->tree_id == NULL) {
295 a440fac0 2018-09-06 stsp free(commit);
296 a440fac0 2018-09-06 stsp return NULL;
297 a440fac0 2018-09-06 stsp }
298 a440fac0 2018-09-06 stsp
299 dbdddfee 2021-06-23 naddy STAILQ_INIT(&commit->parent_ids);
300 a440fac0 2018-09-06 stsp
301 a440fac0 2018-09-06 stsp return commit;
302 a440fac0 2018-09-06 stsp }
303 a440fac0 2018-09-06 stsp
304 a440fac0 2018-09-06 stsp const struct got_error *
305 a440fac0 2018-09-06 stsp got_object_commit_add_parent(struct got_commit_object *commit,
306 a440fac0 2018-09-06 stsp const char *id_str)
307 a440fac0 2018-09-06 stsp {
308 a440fac0 2018-09-06 stsp const struct got_error *err = NULL;
309 a440fac0 2018-09-06 stsp struct got_object_qid *qid;
310 a440fac0 2018-09-06 stsp
311 5df4932d 2018-11-05 stsp err = got_object_qid_alloc_partial(&qid);
312 5df4932d 2018-11-05 stsp if (err)
313 7762fe12 2018-11-05 stsp return err;
314 a440fac0 2018-09-06 stsp
315 a440fac0 2018-09-06 stsp if (!got_parse_sha1_digest(qid->id->sha1, id_str)) {
316 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
317 00eb6a1f 2019-07-15 stsp got_object_qid_free(qid);
318 a440fac0 2018-09-06 stsp return err;
319 a440fac0 2018-09-06 stsp }
320 a440fac0 2018-09-06 stsp
321 dbdddfee 2021-06-23 naddy STAILQ_INSERT_TAIL(&commit->parent_ids, qid, entry);
322 a440fac0 2018-09-06 stsp commit->nparents++;
323 a440fac0 2018-09-06 stsp
324 a440fac0 2018-09-06 stsp return NULL;
325 a440fac0 2018-09-06 stsp }
326 a440fac0 2018-09-06 stsp
327 a440fac0 2018-09-06 stsp static const struct got_error *
328 a440fac0 2018-09-06 stsp parse_gmtoff(time_t *gmtoff, const char *tzstr)
329 a440fac0 2018-09-06 stsp {
330 a440fac0 2018-09-06 stsp int sign = 1;
331 a440fac0 2018-09-06 stsp const char *p = tzstr;
332 a440fac0 2018-09-06 stsp time_t h, m;
333 a440fac0 2018-09-06 stsp
334 a440fac0 2018-09-06 stsp *gmtoff = 0;
335 a440fac0 2018-09-06 stsp
336 a440fac0 2018-09-06 stsp if (*p == '-')
337 a440fac0 2018-09-06 stsp sign = -1;
338 a440fac0 2018-09-06 stsp else if (*p != '+')
339 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
340 a440fac0 2018-09-06 stsp p++;
341 a440fac0 2018-09-06 stsp if (!isdigit(*p) && !isdigit(*(p + 1)))
342 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
343 a440fac0 2018-09-06 stsp h = (((*p - '0') * 10) + (*(p + 1) - '0'));
344 a440fac0 2018-09-06 stsp
345 a440fac0 2018-09-06 stsp p += 2;
346 a440fac0 2018-09-06 stsp if (!isdigit(*p) && !isdigit(*(p + 1)))
347 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
348 a440fac0 2018-09-06 stsp m = ((*p - '0') * 10) + (*(p + 1) - '0');
349 a440fac0 2018-09-06 stsp
350 a440fac0 2018-09-06 stsp *gmtoff = (h * 60 * 60 + m * 60) * sign;
351 a440fac0 2018-09-06 stsp return NULL;
352 a440fac0 2018-09-06 stsp }
353 a440fac0 2018-09-06 stsp
354 a440fac0 2018-09-06 stsp static const struct got_error *
355 ccb26ccd 2018-11-05 stsp parse_commit_time(time_t *time, time_t *gmtoff, char *committer)
356 a440fac0 2018-09-06 stsp {
357 a440fac0 2018-09-06 stsp const struct got_error *err = NULL;
358 a440fac0 2018-09-06 stsp const char *errstr;
359 a440fac0 2018-09-06 stsp char *space, *tzstr;
360 a440fac0 2018-09-06 stsp
361 a440fac0 2018-09-06 stsp /* Parse and strip off trailing timezone indicator string. */
362 a440fac0 2018-09-06 stsp space = strrchr(committer, ' ');
363 a440fac0 2018-09-06 stsp if (space == NULL)
364 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
365 a440fac0 2018-09-06 stsp tzstr = strdup(space + 1);
366 a440fac0 2018-09-06 stsp if (tzstr == NULL)
367 638f9024 2019-05-13 stsp return got_error_from_errno("strdup");
368 ccb26ccd 2018-11-05 stsp err = parse_gmtoff(gmtoff, tzstr);
369 a440fac0 2018-09-06 stsp free(tzstr);
370 9dbd8627 2021-02-04 stsp if (err) {
371 9dbd8627 2021-02-04 stsp if (err->code != GOT_ERR_BAD_OBJ_DATA)
372 9dbd8627 2021-02-04 stsp return err;
373 9dbd8627 2021-02-04 stsp /* Old versions of Git omitted the timestamp. */
374 9dbd8627 2021-02-04 stsp *time = 0;
375 9dbd8627 2021-02-04 stsp *gmtoff = 0;
376 9dbd8627 2021-02-04 stsp return NULL;
377 9dbd8627 2021-02-04 stsp }
378 a440fac0 2018-09-06 stsp *space = '\0';
379 a440fac0 2018-09-06 stsp
380 a440fac0 2018-09-06 stsp /* Timestamp is separated from committer name + email by space. */
381 a440fac0 2018-09-06 stsp space = strrchr(committer, ' ');
382 a440fac0 2018-09-06 stsp if (space == NULL)
383 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
384 a440fac0 2018-09-06 stsp
385 09867e48 2019-08-13 stsp /* Timestamp parsed here is expressed as UNIX timestamp (UTC). */
386 ccb26ccd 2018-11-05 stsp *time = strtonum(space + 1, 0, INT64_MAX, &errstr);
387 a440fac0 2018-09-06 stsp if (errstr)
388 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
389 a440fac0 2018-09-06 stsp
390 a440fac0 2018-09-06 stsp /* Strip off parsed time information, leaving just author and email. */
391 a440fac0 2018-09-06 stsp *space = '\0';
392 a440fac0 2018-09-06 stsp
393 a440fac0 2018-09-06 stsp return NULL;
394 a440fac0 2018-09-06 stsp }
395 a440fac0 2018-09-06 stsp
396 03fa71c8 2018-09-06 stsp void
397 03fa71c8 2018-09-06 stsp got_object_commit_close(struct got_commit_object *commit)
398 03fa71c8 2018-09-06 stsp {
399 03fa71c8 2018-09-06 stsp if (commit->refcnt > 0) {
400 03fa71c8 2018-09-06 stsp commit->refcnt--;
401 03fa71c8 2018-09-06 stsp if (commit->refcnt > 0)
402 03fa71c8 2018-09-06 stsp return;
403 03fa71c8 2018-09-06 stsp }
404 03fa71c8 2018-09-06 stsp
405 dd88155e 2019-06-29 stsp got_object_id_queue_free(&commit->parent_ids);
406 03fa71c8 2018-09-06 stsp free(commit->tree_id);
407 03fa71c8 2018-09-06 stsp free(commit->author);
408 03fa71c8 2018-09-06 stsp free(commit->committer);
409 03fa71c8 2018-09-06 stsp free(commit->logmsg);
410 03fa71c8 2018-09-06 stsp free(commit);
411 45d799e2 2018-12-23 stsp }
412 45d799e2 2018-12-23 stsp
413 45d799e2 2018-12-23 stsp struct got_object_id *
414 45d799e2 2018-12-23 stsp got_object_commit_get_tree_id(struct got_commit_object *commit)
415 45d799e2 2018-12-23 stsp {
416 45d799e2 2018-12-23 stsp return commit->tree_id;
417 45d799e2 2018-12-23 stsp }
418 45d799e2 2018-12-23 stsp
419 45d799e2 2018-12-23 stsp int
420 45d799e2 2018-12-23 stsp got_object_commit_get_nparents(struct got_commit_object *commit)
421 45d799e2 2018-12-23 stsp {
422 45d799e2 2018-12-23 stsp return commit->nparents;
423 03fa71c8 2018-09-06 stsp }
424 03fa71c8 2018-09-06 stsp
425 45d799e2 2018-12-23 stsp const struct got_object_id_queue *
426 45d799e2 2018-12-23 stsp got_object_commit_get_parent_ids(struct got_commit_object *commit)
427 45d799e2 2018-12-23 stsp {
428 45d799e2 2018-12-23 stsp return &commit->parent_ids;
429 45d799e2 2018-12-23 stsp }
430 45d799e2 2018-12-23 stsp
431 45d799e2 2018-12-23 stsp const char *
432 45d799e2 2018-12-23 stsp got_object_commit_get_author(struct got_commit_object *commit)
433 45d799e2 2018-12-23 stsp {
434 45d799e2 2018-12-23 stsp return commit->author;
435 45d799e2 2018-12-23 stsp }
436 45d799e2 2018-12-23 stsp
437 45d799e2 2018-12-23 stsp time_t
438 45d799e2 2018-12-23 stsp got_object_commit_get_author_time(struct got_commit_object *commit)
439 45d799e2 2018-12-23 stsp {
440 45d799e2 2018-12-23 stsp return commit->author_time;
441 45d799e2 2018-12-23 stsp }
442 45d799e2 2018-12-23 stsp
443 45d799e2 2018-12-23 stsp time_t got_object_commit_get_author_gmtoff(struct got_commit_object *commit)
444 45d799e2 2018-12-23 stsp {
445 45d799e2 2018-12-23 stsp return commit->author_gmtoff;
446 45d799e2 2018-12-23 stsp }
447 45d799e2 2018-12-23 stsp
448 45d799e2 2018-12-23 stsp const char *
449 45d799e2 2018-12-23 stsp got_object_commit_get_committer(struct got_commit_object *commit)
450 45d799e2 2018-12-23 stsp {
451 45d799e2 2018-12-23 stsp return commit->committer;
452 45d799e2 2018-12-23 stsp }
453 45d799e2 2018-12-23 stsp
454 45d799e2 2018-12-23 stsp time_t
455 45d799e2 2018-12-23 stsp got_object_commit_get_committer_time(struct got_commit_object *commit)
456 45d799e2 2018-12-23 stsp {
457 45d799e2 2018-12-23 stsp return commit->committer_time;
458 45d799e2 2018-12-23 stsp }
459 45d799e2 2018-12-23 stsp
460 45d799e2 2018-12-23 stsp time_t
461 45d799e2 2018-12-23 stsp got_object_commit_get_committer_gmtoff(struct got_commit_object *commit)
462 45d799e2 2018-12-23 stsp {
463 45d799e2 2018-12-23 stsp return commit->committer_gmtoff;
464 45d799e2 2018-12-23 stsp }
465 5943eee2 2019-08-13 stsp
466 5943eee2 2019-08-13 stsp const struct got_error *
467 5943eee2 2019-08-13 stsp got_object_commit_get_logmsg(char **logmsg, struct got_commit_object *commit)
468 45d799e2 2018-12-23 stsp {
469 5943eee2 2019-08-13 stsp const struct got_error *err = NULL;
470 b9c41b54 2021-08-03 stsp const char *src;
471 b9c41b54 2021-08-03 stsp char *dst;
472 5943eee2 2019-08-13 stsp size_t len;
473 5943eee2 2019-08-13 stsp
474 b9c41b54 2021-08-03 stsp len = strlen(commit->logmsg);
475 b9c41b54 2021-08-03 stsp *logmsg = malloc(len + 2); /* leave room for a trailing \n and \0 */
476 b9c41b54 2021-08-03 stsp if (*logmsg == NULL)
477 b9c41b54 2021-08-03 stsp return got_error_from_errno("malloc");
478 5943eee2 2019-08-13 stsp
479 b9c41b54 2021-08-03 stsp /*
480 b9c41b54 2021-08-03 stsp * Strip out unusual headers. Headers are separated from the commit
481 b9c41b54 2021-08-03 stsp * message body by a single empty line.
482 b9c41b54 2021-08-03 stsp */
483 b9c41b54 2021-08-03 stsp src = commit->logmsg;
484 b9c41b54 2021-08-03 stsp dst = *logmsg;
485 b9c41b54 2021-08-03 stsp while (*src != '\0' && *src != '\n') {
486 b9c41b54 2021-08-03 stsp int copy_header = 1, eol = 0;
487 b9c41b54 2021-08-03 stsp if (strncmp(src, GOT_COMMIT_LABEL_TREE,
488 b9c41b54 2021-08-03 stsp strlen(GOT_COMMIT_LABEL_TREE)) != 0 &&
489 b9c41b54 2021-08-03 stsp strncmp(src, GOT_COMMIT_LABEL_AUTHOR,
490 b9c41b54 2021-08-03 stsp strlen(GOT_COMMIT_LABEL_AUTHOR)) != 0 &&
491 b9c41b54 2021-08-03 stsp strncmp(src, GOT_COMMIT_LABEL_PARENT,
492 b9c41b54 2021-08-03 stsp strlen(GOT_COMMIT_LABEL_PARENT)) != 0 &&
493 b9c41b54 2021-08-03 stsp strncmp(src, GOT_COMMIT_LABEL_COMMITTER,
494 b9c41b54 2021-08-03 stsp strlen(GOT_COMMIT_LABEL_COMMITTER)) != 0)
495 b9c41b54 2021-08-03 stsp copy_header = 0;
496 13555e04 2019-09-28 semarie
497 b9c41b54 2021-08-03 stsp while (*src != '\0' && !eol) {
498 b9c41b54 2021-08-03 stsp if (copy_header) {
499 b9c41b54 2021-08-03 stsp *dst = *src;
500 b9c41b54 2021-08-03 stsp dst++;
501 b9c41b54 2021-08-03 stsp }
502 b9c41b54 2021-08-03 stsp if (*src == '\n')
503 b9c41b54 2021-08-03 stsp eol = 1;
504 b9c41b54 2021-08-03 stsp src++;
505 5943eee2 2019-08-13 stsp }
506 b9c41b54 2021-08-03 stsp }
507 b9c41b54 2021-08-03 stsp *dst = '\0';
508 13555e04 2019-09-28 semarie
509 b9c41b54 2021-08-03 stsp if (strlcat(*logmsg, src, len + 1) >= len + 1) {
510 b9c41b54 2021-08-03 stsp err = got_error(GOT_ERR_NO_SPACE);
511 b9c41b54 2021-08-03 stsp goto done;
512 ef744db3 2020-08-27 stsp }
513 ef744db3 2020-08-27 stsp
514 5943eee2 2019-08-13 stsp /* Trim redundant trailing whitespace. */
515 5943eee2 2019-08-13 stsp len = strlen(*logmsg);
516 5943eee2 2019-08-13 stsp while (len > 1 && isspace((unsigned char)(*logmsg)[len - 2]) &&
517 5943eee2 2019-08-13 stsp isspace((unsigned char)(*logmsg)[len - 1])) {
518 5943eee2 2019-08-13 stsp (*logmsg)[len - 1] = '\0';
519 5943eee2 2019-08-13 stsp len--;
520 5943eee2 2019-08-13 stsp }
521 b9c41b54 2021-08-03 stsp
522 b9c41b54 2021-08-03 stsp /* Append a trailing newline if missing. */
523 b9c41b54 2021-08-03 stsp if (len > 0 && (*logmsg)[len - 1] != '\n') {
524 b9c41b54 2021-08-03 stsp (*logmsg)[len] = '\n';
525 b9c41b54 2021-08-03 stsp (*logmsg)[len + 1] = '\0';
526 b9c41b54 2021-08-03 stsp }
527 5943eee2 2019-08-13 stsp done:
528 5943eee2 2019-08-13 stsp if (err) {
529 5943eee2 2019-08-13 stsp free(*logmsg);
530 5943eee2 2019-08-13 stsp *logmsg = NULL;
531 5943eee2 2019-08-13 stsp }
532 5943eee2 2019-08-13 stsp return err;
533 24ea5512 2019-08-22 stsp }
534 24ea5512 2019-08-22 stsp
535 24ea5512 2019-08-22 stsp const char *
536 24ea5512 2019-08-22 stsp got_object_commit_get_logmsg_raw(struct got_commit_object *commit)
537 24ea5512 2019-08-22 stsp {
538 24ea5512 2019-08-22 stsp return commit->logmsg;
539 45d799e2 2018-12-23 stsp }
540 45d799e2 2018-12-23 stsp
541 a440fac0 2018-09-06 stsp const struct got_error *
542 5e0b25c4 2018-12-24 stsp got_object_parse_commit(struct got_commit_object **commit, char *buf,
543 5e0b25c4 2018-12-24 stsp size_t len)
544 a440fac0 2018-09-06 stsp {
545 a440fac0 2018-09-06 stsp const struct got_error *err = NULL;
546 a440fac0 2018-09-06 stsp char *s = buf;
547 ff2a4428 2019-03-19 stsp size_t label_len;
548 a440fac0 2018-09-06 stsp ssize_t remain = (ssize_t)len;
549 4793d91b 2019-09-22 stsp
550 4793d91b 2019-09-22 stsp if (remain == 0)
551 4793d91b 2019-09-22 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
552 230a42bd 2019-05-11 jcs
553 a440fac0 2018-09-06 stsp *commit = got_object_commit_alloc_partial();
554 a440fac0 2018-09-06 stsp if (*commit == NULL)
555 638f9024 2019-05-13 stsp return got_error_from_errno("got_object_commit_alloc_partial");
556 a440fac0 2018-09-06 stsp
557 ff2a4428 2019-03-19 stsp label_len = strlen(GOT_COMMIT_LABEL_TREE);
558 ff2a4428 2019-03-19 stsp if (strncmp(s, GOT_COMMIT_LABEL_TREE, label_len) == 0) {
559 ff2a4428 2019-03-19 stsp remain -= label_len;
560 a440fac0 2018-09-06 stsp if (remain < SHA1_DIGEST_STRING_LENGTH) {
561 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
562 a440fac0 2018-09-06 stsp goto done;
563 a440fac0 2018-09-06 stsp }
564 ff2a4428 2019-03-19 stsp s += label_len;
565 a440fac0 2018-09-06 stsp if (!got_parse_sha1_digest((*commit)->tree_id->sha1, s)) {
566 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
567 a440fac0 2018-09-06 stsp goto done;
568 a440fac0 2018-09-06 stsp }
569 a440fac0 2018-09-06 stsp remain -= SHA1_DIGEST_STRING_LENGTH;
570 a440fac0 2018-09-06 stsp s += SHA1_DIGEST_STRING_LENGTH;
571 a440fac0 2018-09-06 stsp } else {
572 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
573 a440fac0 2018-09-06 stsp goto done;
574 a440fac0 2018-09-06 stsp }
575 a440fac0 2018-09-06 stsp
576 ff2a4428 2019-03-19 stsp label_len = strlen(GOT_COMMIT_LABEL_PARENT);
577 ff2a4428 2019-03-19 stsp while (strncmp(s, GOT_COMMIT_LABEL_PARENT, label_len) == 0) {
578 ff2a4428 2019-03-19 stsp remain -= label_len;
579 a440fac0 2018-09-06 stsp if (remain < SHA1_DIGEST_STRING_LENGTH) {
580 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
581 a440fac0 2018-09-06 stsp goto done;
582 a440fac0 2018-09-06 stsp }
583 ff2a4428 2019-03-19 stsp s += label_len;
584 a440fac0 2018-09-06 stsp err = got_object_commit_add_parent(*commit, s);
585 a440fac0 2018-09-06 stsp if (err)
586 a440fac0 2018-09-06 stsp goto done;
587 a440fac0 2018-09-06 stsp
588 a440fac0 2018-09-06 stsp remain -= SHA1_DIGEST_STRING_LENGTH;
589 a440fac0 2018-09-06 stsp s += SHA1_DIGEST_STRING_LENGTH;
590 a440fac0 2018-09-06 stsp }
591 a440fac0 2018-09-06 stsp
592 ff2a4428 2019-03-19 stsp label_len = strlen(GOT_COMMIT_LABEL_AUTHOR);
593 ff2a4428 2019-03-19 stsp if (strncmp(s, GOT_COMMIT_LABEL_AUTHOR, label_len) == 0) {
594 a440fac0 2018-09-06 stsp char *p;
595 a440fac0 2018-09-06 stsp size_t slen;
596 a440fac0 2018-09-06 stsp
597 ff2a4428 2019-03-19 stsp remain -= label_len;
598 a440fac0 2018-09-06 stsp if (remain <= 0) {
599 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
600 a440fac0 2018-09-06 stsp goto done;
601 a440fac0 2018-09-06 stsp }
602 ff2a4428 2019-03-19 stsp s += label_len;
603 dedbbd9d 2019-04-13 stsp p = memchr(s, '\n', remain);
604 a440fac0 2018-09-06 stsp if (p == NULL) {
605 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
606 a440fac0 2018-09-06 stsp goto done;
607 a440fac0 2018-09-06 stsp }
608 a440fac0 2018-09-06 stsp *p = '\0';
609 a440fac0 2018-09-06 stsp slen = strlen(s);
610 ccb26ccd 2018-11-05 stsp err = parse_commit_time(&(*commit)->author_time,
611 ccb26ccd 2018-11-05 stsp &(*commit)->author_gmtoff, s);
612 a440fac0 2018-09-06 stsp if (err)
613 a440fac0 2018-09-06 stsp goto done;
614 a440fac0 2018-09-06 stsp (*commit)->author = strdup(s);
615 a440fac0 2018-09-06 stsp if ((*commit)->author == NULL) {
616 638f9024 2019-05-13 stsp err = got_error_from_errno("strdup");
617 a440fac0 2018-09-06 stsp goto done;
618 a440fac0 2018-09-06 stsp }
619 a440fac0 2018-09-06 stsp s += slen + 1;
620 a440fac0 2018-09-06 stsp remain -= slen + 1;
621 a440fac0 2018-09-06 stsp }
622 a440fac0 2018-09-06 stsp
623 ff2a4428 2019-03-19 stsp label_len = strlen(GOT_COMMIT_LABEL_COMMITTER);
624 ff2a4428 2019-03-19 stsp if (strncmp(s, GOT_COMMIT_LABEL_COMMITTER, label_len) == 0) {
625 a440fac0 2018-09-06 stsp char *p;
626 a440fac0 2018-09-06 stsp size_t slen;
627 a440fac0 2018-09-06 stsp
628 ff2a4428 2019-03-19 stsp remain -= label_len;
629 a440fac0 2018-09-06 stsp if (remain <= 0) {
630 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
631 a440fac0 2018-09-06 stsp goto done;
632 a440fac0 2018-09-06 stsp }
633 ff2a4428 2019-03-19 stsp s += label_len;
634 dedbbd9d 2019-04-13 stsp p = memchr(s, '\n', remain);
635 a440fac0 2018-09-06 stsp if (p == NULL) {
636 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
637 a440fac0 2018-09-06 stsp goto done;
638 a440fac0 2018-09-06 stsp }
639 a440fac0 2018-09-06 stsp *p = '\0';
640 a440fac0 2018-09-06 stsp slen = strlen(s);
641 ccb26ccd 2018-11-05 stsp err = parse_commit_time(&(*commit)->committer_time,
642 ccb26ccd 2018-11-05 stsp &(*commit)->committer_gmtoff, s);
643 a440fac0 2018-09-06 stsp if (err)
644 a440fac0 2018-09-06 stsp goto done;
645 a440fac0 2018-09-06 stsp (*commit)->committer = strdup(s);
646 a440fac0 2018-09-06 stsp if ((*commit)->committer == NULL) {
647 638f9024 2019-05-13 stsp err = got_error_from_errno("strdup");
648 a440fac0 2018-09-06 stsp goto done;
649 a440fac0 2018-09-06 stsp }
650 a440fac0 2018-09-06 stsp s += slen + 1;
651 a440fac0 2018-09-06 stsp remain -= slen + 1;
652 a440fac0 2018-09-06 stsp }
653 a440fac0 2018-09-06 stsp
654 a440fac0 2018-09-06 stsp (*commit)->logmsg = strndup(s, remain);
655 a440fac0 2018-09-06 stsp if ((*commit)->logmsg == NULL) {
656 638f9024 2019-05-13 stsp err = got_error_from_errno("strndup");
657 a440fac0 2018-09-06 stsp goto done;
658 a440fac0 2018-09-06 stsp }
659 a440fac0 2018-09-06 stsp done:
660 a440fac0 2018-09-06 stsp if (err) {
661 a440fac0 2018-09-06 stsp got_object_commit_close(*commit);
662 a440fac0 2018-09-06 stsp *commit = NULL;
663 a440fac0 2018-09-06 stsp }
664 a440fac0 2018-09-06 stsp return err;
665 ed175427 2019-05-09 stsp }
666 ed175427 2019-05-09 stsp
667 ed175427 2019-05-09 stsp void
668 ed175427 2019-05-09 stsp got_object_tree_close(struct got_tree_object *tree)
669 ed175427 2019-05-09 stsp {
670 03fa71c8 2018-09-06 stsp if (tree->refcnt > 0) {
671 03fa71c8 2018-09-06 stsp tree->refcnt--;
672 03fa71c8 2018-09-06 stsp if (tree->refcnt > 0)
673 03fa71c8 2018-09-06 stsp return;
674 03fa71c8 2018-09-06 stsp }
675 03fa71c8 2018-09-06 stsp
676 56e0773d 2019-11-28 stsp free(tree->entries);
677 03fa71c8 2018-09-06 stsp free(tree);
678 03fa71c8 2018-09-06 stsp }
679 03fa71c8 2018-09-06 stsp
680 a440fac0 2018-09-06 stsp static const struct got_error *
681 3022d272 2019-11-14 stsp parse_tree_entry(struct got_parsed_tree_entry **pte, const char **name,
682 3022d272 2019-11-14 stsp size_t *elen, char *buf,
683 a440fac0 2018-09-06 stsp size_t maxlen)
684 a440fac0 2018-09-06 stsp {
685 8914529d 2019-04-13 stsp char *p, *space;
686 a440fac0 2018-09-06 stsp const struct got_error *err = NULL;
687 a0de39f3 2019-08-09 stsp
688 3022d272 2019-11-14 stsp *name = NULL;
689 a0de39f3 2019-08-09 stsp *elen = 0;
690 a440fac0 2018-09-06 stsp
691 3022d272 2019-11-14 stsp *pte = malloc(sizeof(**pte));
692 3022d272 2019-11-14 stsp if (*pte == NULL)
693 3022d272 2019-11-14 stsp return got_error_from_errno("malloc");
694 a440fac0 2018-09-06 stsp
695 9ef4ac16 2019-04-13 stsp *elen = strnlen(buf, maxlen) + 1;
696 a440fac0 2018-09-06 stsp if (*elen > maxlen) {
697 3022d272 2019-11-14 stsp free(*pte);
698 3022d272 2019-11-14 stsp *pte = NULL;
699 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
700 a440fac0 2018-09-06 stsp }
701 a440fac0 2018-09-06 stsp
702 dedbbd9d 2019-04-13 stsp space = memchr(buf, ' ', *elen);
703 8914529d 2019-04-13 stsp if (space == NULL || space <= buf) {
704 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
705 3022d272 2019-11-14 stsp free(*pte);
706 3022d272 2019-11-14 stsp *pte = NULL;
707 a440fac0 2018-09-06 stsp return err;
708 a440fac0 2018-09-06 stsp }
709 3022d272 2019-11-14 stsp (*pte)->mode = 0;
710 8914529d 2019-04-13 stsp p = buf;
711 8914529d 2019-04-13 stsp while (p < space) {
712 a440fac0 2018-09-06 stsp if (*p < '0' && *p > '7') {
713 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
714 a440fac0 2018-09-06 stsp goto done;
715 a440fac0 2018-09-06 stsp }
716 3022d272 2019-11-14 stsp (*pte)->mode <<= 3;
717 3022d272 2019-11-14 stsp (*pte)->mode |= *p - '0';
718 a440fac0 2018-09-06 stsp p++;
719 a440fac0 2018-09-06 stsp }
720 a440fac0 2018-09-06 stsp
721 a440fac0 2018-09-06 stsp if (*elen > maxlen || maxlen - *elen < SHA1_DIGEST_LENGTH) {
722 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
723 a440fac0 2018-09-06 stsp goto done;
724 a440fac0 2018-09-06 stsp }
725 3022d272 2019-11-14 stsp *name = space + 1;
726 68bf1b1e 2018-11-07 stsp buf += *elen;
727 3022d272 2019-11-14 stsp (*pte)->id = buf;
728 a440fac0 2018-09-06 stsp *elen += SHA1_DIGEST_LENGTH;
729 a440fac0 2018-09-06 stsp done:
730 a440fac0 2018-09-06 stsp if (err) {
731 3022d272 2019-11-14 stsp free(*pte);
732 3022d272 2019-11-14 stsp *pte = NULL;
733 a440fac0 2018-09-06 stsp }
734 a440fac0 2018-09-06 stsp return err;
735 a440fac0 2018-09-06 stsp }
736 a440fac0 2018-09-06 stsp
737 a440fac0 2018-09-06 stsp const struct got_error *
738 3022d272 2019-11-14 stsp got_object_parse_tree(struct got_pathlist_head *entries, int *nentries,
739 3022d272 2019-11-14 stsp uint8_t *buf, size_t len)
740 a440fac0 2018-09-06 stsp {
741 3022d272 2019-11-14 stsp const struct got_error *err = NULL;
742 a440fac0 2018-09-06 stsp size_t remain = len;
743 f5d3d7af 2019-02-05 stsp
744 3022d272 2019-11-14 stsp *nentries = 0;
745 db1d3576 2019-10-04 stsp if (remain == 0)
746 db1d3576 2019-10-04 stsp return NULL; /* tree is empty */
747 db1d3576 2019-10-04 stsp
748 a440fac0 2018-09-06 stsp while (remain > 0) {
749 3022d272 2019-11-14 stsp struct got_parsed_tree_entry *pte;
750 f5d3d7af 2019-02-05 stsp struct got_pathlist_entry *new = NULL;
751 3022d272 2019-11-14 stsp const char *name;
752 a440fac0 2018-09-06 stsp size_t elen;
753 a440fac0 2018-09-06 stsp
754 3022d272 2019-11-14 stsp err = parse_tree_entry(&pte, &name, &elen, buf, remain);
755 a440fac0 2018-09-06 stsp if (err)
756 f5d3d7af 2019-02-05 stsp goto done;
757 3022d272 2019-11-14 stsp err = got_pathlist_insert(&new, entries, name, pte);
758 f5d3d7af 2019-02-05 stsp if (err)
759 f5d3d7af 2019-02-05 stsp goto done;
760 f5d3d7af 2019-02-05 stsp if (new == NULL) {
761 f5d3d7af 2019-02-05 stsp err = got_error(GOT_ERR_TREE_DUP_ENTRY);
762 f5d3d7af 2019-02-05 stsp goto done;
763 f5d3d7af 2019-02-05 stsp }
764 a440fac0 2018-09-06 stsp buf += elen;
765 a440fac0 2018-09-06 stsp remain -= elen;
766 3022d272 2019-11-14 stsp (*nentries)++;
767 a440fac0 2018-09-06 stsp }
768 a440fac0 2018-09-06 stsp
769 a440fac0 2018-09-06 stsp if (remain != 0) {
770 f5d3d7af 2019-02-05 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
771 f5d3d7af 2019-02-05 stsp goto done;
772 a440fac0 2018-09-06 stsp }
773 3022d272 2019-11-14 stsp done:
774 3022d272 2019-11-14 stsp if (err) {
775 b87b4170 2020-01-06 stsp got_object_parsed_tree_entries_free(entries);
776 3022d272 2019-11-14 stsp *nentries = 0;
777 f5d3d7af 2019-02-05 stsp }
778 f5d3d7af 2019-02-05 stsp return err;
779 b64b1f95 2020-01-06 stsp }
780 b64b1f95 2020-01-06 stsp
781 b64b1f95 2020-01-06 stsp void
782 b87b4170 2020-01-06 stsp got_object_parsed_tree_entries_free(struct got_pathlist_head *entries)
783 b64b1f95 2020-01-06 stsp {
784 b64b1f95 2020-01-06 stsp struct got_pathlist_entry *pe;
785 b64b1f95 2020-01-06 stsp
786 b64b1f95 2020-01-06 stsp TAILQ_FOREACH(pe, entries, entry) {
787 b64b1f95 2020-01-06 stsp struct got_parsed_tree_entry *pte = pe->data;
788 b64b1f95 2020-01-06 stsp free(pte);
789 b64b1f95 2020-01-06 stsp }
790 b64b1f95 2020-01-06 stsp got_pathlist_free(entries);
791 a440fac0 2018-09-06 stsp }
792 a440fac0 2018-09-06 stsp
793 f4a881ce 2018-11-17 stsp void
794 f4a881ce 2018-11-17 stsp got_object_tag_close(struct got_tag_object *tag)
795 f4a881ce 2018-11-17 stsp {
796 ca0d469c 2019-08-13 stsp if (tag->refcnt > 0) {
797 ca0d469c 2019-08-13 stsp tag->refcnt--;
798 ca0d469c 2019-08-13 stsp if (tag->refcnt > 0)
799 ca0d469c 2019-08-13 stsp return;
800 ca0d469c 2019-08-13 stsp }
801 ca0d469c 2019-08-13 stsp
802 f4a881ce 2018-11-17 stsp free(tag->tag);
803 f4a881ce 2018-11-17 stsp free(tag->tagger);
804 f4a881ce 2018-11-17 stsp free(tag->tagmsg);
805 f4a881ce 2018-11-17 stsp free(tag);
806 f4a881ce 2018-11-17 stsp }
807 f4a881ce 2018-11-17 stsp
808 ad242220 2018-09-08 stsp const struct got_error *
809 f4a881ce 2018-11-17 stsp got_object_parse_tag(struct got_tag_object **tag, uint8_t *buf, size_t len)
810 f4a881ce 2018-11-17 stsp {
811 f4a881ce 2018-11-17 stsp const struct got_error *err = NULL;
812 f4a881ce 2018-11-17 stsp size_t remain = len;
813 f4a881ce 2018-11-17 stsp char *s = buf;
814 ff2a4428 2019-03-19 stsp size_t label_len;
815 4793d91b 2019-09-22 stsp
816 4793d91b 2019-09-22 stsp if (remain == 0)
817 4793d91b 2019-09-22 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
818 f4a881ce 2018-11-17 stsp
819 f4a881ce 2018-11-17 stsp *tag = calloc(1, sizeof(**tag));
820 f4a881ce 2018-11-17 stsp if (*tag == NULL)
821 638f9024 2019-05-13 stsp return got_error_from_errno("calloc");
822 f4a881ce 2018-11-17 stsp
823 ff2a4428 2019-03-19 stsp label_len = strlen(GOT_TAG_LABEL_OBJECT);
824 ff2a4428 2019-03-19 stsp if (strncmp(s, GOT_TAG_LABEL_OBJECT, label_len) == 0) {
825 ff2a4428 2019-03-19 stsp remain -= label_len;
826 f4a881ce 2018-11-17 stsp if (remain < SHA1_DIGEST_STRING_LENGTH) {
827 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
828 f4a881ce 2018-11-17 stsp goto done;
829 f4a881ce 2018-11-17 stsp }
830 ff2a4428 2019-03-19 stsp s += label_len;
831 f4a881ce 2018-11-17 stsp if (!got_parse_sha1_digest((*tag)->id.sha1, s)) {
832 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
833 f4a881ce 2018-11-17 stsp goto done;
834 f4a881ce 2018-11-17 stsp }
835 f4a881ce 2018-11-17 stsp remain -= SHA1_DIGEST_STRING_LENGTH;
836 f4a881ce 2018-11-17 stsp s += SHA1_DIGEST_STRING_LENGTH;
837 f4a881ce 2018-11-17 stsp } else {
838 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
839 f4a881ce 2018-11-17 stsp goto done;
840 f4a881ce 2018-11-17 stsp }
841 f4a881ce 2018-11-17 stsp
842 f4a881ce 2018-11-17 stsp if (remain <= 0) {
843 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
844 f4a881ce 2018-11-17 stsp goto done;
845 f4a881ce 2018-11-17 stsp }
846 f4a881ce 2018-11-17 stsp
847 ff2a4428 2019-03-19 stsp label_len = strlen(GOT_TAG_LABEL_TYPE);
848 ff2a4428 2019-03-19 stsp if (strncmp(s, GOT_TAG_LABEL_TYPE, label_len) == 0) {
849 ff2a4428 2019-03-19 stsp remain -= label_len;
850 f4a881ce 2018-11-17 stsp if (remain <= 0) {
851 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
852 f4a881ce 2018-11-17 stsp goto done;
853 f4a881ce 2018-11-17 stsp }
854 ff2a4428 2019-03-19 stsp s += label_len;
855 ff2a4428 2019-03-19 stsp if (strncmp(s, GOT_OBJ_LABEL_COMMIT,
856 ff2a4428 2019-03-19 stsp strlen(GOT_OBJ_LABEL_COMMIT)) == 0) {
857 f4a881ce 2018-11-17 stsp (*tag)->obj_type = GOT_OBJ_TYPE_COMMIT;
858 ff2a4428 2019-03-19 stsp label_len = strlen(GOT_OBJ_LABEL_COMMIT);
859 ff2a4428 2019-03-19 stsp s += label_len;
860 ff2a4428 2019-03-19 stsp remain -= label_len;
861 ff2a4428 2019-03-19 stsp } else if (strncmp(s, GOT_OBJ_LABEL_TREE,
862 ff2a4428 2019-03-19 stsp strlen(GOT_OBJ_LABEL_TREE)) == 0) {
863 f4a881ce 2018-11-17 stsp (*tag)->obj_type = GOT_OBJ_TYPE_TREE;
864 ff2a4428 2019-03-19 stsp label_len = strlen(GOT_OBJ_LABEL_TREE);
865 ff2a4428 2019-03-19 stsp s += label_len;
866 ff2a4428 2019-03-19 stsp remain -= label_len;
867 ff2a4428 2019-03-19 stsp } else if (strncmp(s, GOT_OBJ_LABEL_BLOB,
868 ff2a4428 2019-03-19 stsp strlen(GOT_OBJ_LABEL_BLOB)) == 0) {
869 f4a881ce 2018-11-17 stsp (*tag)->obj_type = GOT_OBJ_TYPE_BLOB;
870 ff2a4428 2019-03-19 stsp label_len = strlen(GOT_OBJ_LABEL_BLOB);
871 ff2a4428 2019-03-19 stsp s += label_len;
872 ff2a4428 2019-03-19 stsp remain -= label_len;
873 ff2a4428 2019-03-19 stsp } else if (strncmp(s, GOT_OBJ_LABEL_TAG,
874 ff2a4428 2019-03-19 stsp strlen(GOT_OBJ_LABEL_TAG)) == 0) {
875 f4a881ce 2018-11-17 stsp (*tag)->obj_type = GOT_OBJ_TYPE_TAG;
876 ff2a4428 2019-03-19 stsp label_len = strlen(GOT_OBJ_LABEL_TAG);
877 ff2a4428 2019-03-19 stsp s += label_len;
878 ff2a4428 2019-03-19 stsp remain -= label_len;
879 f4a881ce 2018-11-17 stsp } else {
880 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
881 f4a881ce 2018-11-17 stsp goto done;
882 f4a881ce 2018-11-17 stsp }
883 f4a881ce 2018-11-17 stsp
884 f4a881ce 2018-11-17 stsp if (remain <= 0 || *s != '\n') {
885 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
886 f4a881ce 2018-11-17 stsp goto done;
887 f4a881ce 2018-11-17 stsp }
888 f4a881ce 2018-11-17 stsp s++;
889 f4a881ce 2018-11-17 stsp remain--;
890 f4a881ce 2018-11-17 stsp if (remain <= 0) {
891 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
892 f4a881ce 2018-11-17 stsp goto done;
893 f4a881ce 2018-11-17 stsp }
894 f4a881ce 2018-11-17 stsp } else {
895 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
896 f4a881ce 2018-11-17 stsp goto done;
897 f4a881ce 2018-11-17 stsp }
898 f4a881ce 2018-11-17 stsp
899 ff2a4428 2019-03-19 stsp label_len = strlen(GOT_TAG_LABEL_TAG);
900 ff2a4428 2019-03-19 stsp if (strncmp(s, GOT_TAG_LABEL_TAG, label_len) == 0) {
901 f4a881ce 2018-11-17 stsp char *p;
902 f4a881ce 2018-11-17 stsp size_t slen;
903 ff2a4428 2019-03-19 stsp remain -= label_len;
904 f4a881ce 2018-11-17 stsp if (remain <= 0) {
905 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
906 f4a881ce 2018-11-17 stsp goto done;
907 f4a881ce 2018-11-17 stsp }
908 ff2a4428 2019-03-19 stsp s += label_len;
909 dedbbd9d 2019-04-13 stsp p = memchr(s, '\n', remain);
910 f4a881ce 2018-11-17 stsp if (p == NULL) {
911 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
912 f4a881ce 2018-11-17 stsp goto done;
913 f4a881ce 2018-11-17 stsp }
914 f4a881ce 2018-11-17 stsp *p = '\0';
915 f4a881ce 2018-11-17 stsp slen = strlen(s);
916 f4a881ce 2018-11-17 stsp (*tag)->tag = strndup(s, slen);
917 f4a881ce 2018-11-17 stsp if ((*tag)->tag == NULL) {
918 638f9024 2019-05-13 stsp err = got_error_from_errno("strndup");
919 f4a881ce 2018-11-17 stsp goto done;
920 f4a881ce 2018-11-17 stsp }
921 f4a881ce 2018-11-17 stsp s += slen + 1;
922 f4a881ce 2018-11-17 stsp remain -= slen + 1;
923 f4a881ce 2018-11-17 stsp if (remain <= 0) {
924 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
925 f4a881ce 2018-11-17 stsp goto done;
926 f4a881ce 2018-11-17 stsp }
927 f4a881ce 2018-11-17 stsp } else {
928 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
929 f4a881ce 2018-11-17 stsp goto done;
930 f4a881ce 2018-11-17 stsp }
931 f4a881ce 2018-11-17 stsp
932 ff2a4428 2019-03-19 stsp label_len = strlen(GOT_TAG_LABEL_TAGGER);
933 ff2a4428 2019-03-19 stsp if (strncmp(s, GOT_TAG_LABEL_TAGGER, label_len) == 0) {
934 f4a881ce 2018-11-17 stsp char *p;
935 f4a881ce 2018-11-17 stsp size_t slen;
936 f4a881ce 2018-11-17 stsp
937 ff2a4428 2019-03-19 stsp remain -= label_len;
938 f4a881ce 2018-11-17 stsp if (remain <= 0) {
939 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
940 f4a881ce 2018-11-17 stsp goto done;
941 f4a881ce 2018-11-17 stsp }
942 ff2a4428 2019-03-19 stsp s += label_len;
943 dedbbd9d 2019-04-13 stsp p = memchr(s, '\n', remain);
944 f4a881ce 2018-11-17 stsp if (p == NULL) {
945 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
946 f4a881ce 2018-11-17 stsp goto done;
947 f4a881ce 2018-11-17 stsp }
948 f4a881ce 2018-11-17 stsp *p = '\0';
949 f4a881ce 2018-11-17 stsp slen = strlen(s);
950 f4a881ce 2018-11-17 stsp err = parse_commit_time(&(*tag)->tagger_time,
951 f4a881ce 2018-11-17 stsp &(*tag)->tagger_gmtoff, s);
952 f4a881ce 2018-11-17 stsp if (err)
953 f4a881ce 2018-11-17 stsp goto done;
954 f4a881ce 2018-11-17 stsp (*tag)->tagger = strdup(s);
955 f4a881ce 2018-11-17 stsp if ((*tag)->tagger == NULL) {
956 638f9024 2019-05-13 stsp err = got_error_from_errno("strdup");
957 f4a881ce 2018-11-17 stsp goto done;
958 f4a881ce 2018-11-17 stsp }
959 f4a881ce 2018-11-17 stsp s += slen + 1;
960 f4a881ce 2018-11-17 stsp remain -= slen + 1;
961 5a8b373c 2020-12-18 stsp if (remain < 0) {
962 f4a881ce 2018-11-17 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
963 f4a881ce 2018-11-17 stsp goto done;
964 f4a881ce 2018-11-17 stsp }
965 f4a881ce 2018-11-17 stsp } else {
966 e0e55b50 2019-02-01 stsp /* Some old tags in the Linux git repo have no tagger. */
967 e0e55b50 2019-02-01 stsp (*tag)->tagger = strdup("");
968 e0e55b50 2019-02-01 stsp if ((*tag)->tagger == NULL) {
969 638f9024 2019-05-13 stsp err = got_error_from_errno("strdup");
970 e0e55b50 2019-02-01 stsp goto done;
971 e0e55b50 2019-02-01 stsp }
972 f4a881ce 2018-11-17 stsp }
973 f4a881ce 2018-11-17 stsp
974 f4a881ce 2018-11-17 stsp (*tag)->tagmsg = strndup(s, remain);
975 f4a881ce 2018-11-17 stsp if ((*tag)->tagmsg == NULL) {
976 638f9024 2019-05-13 stsp err = got_error_from_errno("strndup");
977 f4a881ce 2018-11-17 stsp goto done;
978 f4a881ce 2018-11-17 stsp }
979 f4a881ce 2018-11-17 stsp done:
980 f4a881ce 2018-11-17 stsp if (err) {
981 f4a881ce 2018-11-17 stsp got_object_tag_close(*tag);
982 f4a881ce 2018-11-17 stsp *tag = NULL;
983 f4a881ce 2018-11-17 stsp }
984 f4a881ce 2018-11-17 stsp return err;
985 f4a881ce 2018-11-17 stsp }
986 f4a881ce 2018-11-17 stsp
987 f4a881ce 2018-11-17 stsp const struct got_error *
988 ad242220 2018-09-08 stsp got_read_file_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f)
989 a440fac0 2018-09-06 stsp {
990 a440fac0 2018-09-06 stsp const struct got_error *err = NULL;
991 a440fac0 2018-09-06 stsp static const size_t blocksize = 512;
992 a440fac0 2018-09-06 stsp size_t n, total, remain;
993 a440fac0 2018-09-06 stsp uint8_t *buf;
994 a440fac0 2018-09-06 stsp
995 a440fac0 2018-09-06 stsp *outbuf = NULL;
996 a440fac0 2018-09-06 stsp *outlen = 0;
997 a440fac0 2018-09-06 stsp
998 a440fac0 2018-09-06 stsp buf = malloc(blocksize);
999 a440fac0 2018-09-06 stsp if (buf == NULL)
1000 638f9024 2019-05-13 stsp return got_error_from_errno("malloc");
1001 a440fac0 2018-09-06 stsp
1002 a440fac0 2018-09-06 stsp remain = blocksize;
1003 a440fac0 2018-09-06 stsp total = 0;
1004 656b1f76 2019-05-11 jcs for (;;) {
1005 a440fac0 2018-09-06 stsp if (remain == 0) {
1006 a440fac0 2018-09-06 stsp uint8_t *newbuf;
1007 a440fac0 2018-09-06 stsp newbuf = reallocarray(buf, 1, total + blocksize);
1008 a440fac0 2018-09-06 stsp if (newbuf == NULL) {
1009 638f9024 2019-05-13 stsp err = got_error_from_errno("reallocarray");
1010 a440fac0 2018-09-06 stsp goto done;
1011 a440fac0 2018-09-06 stsp }
1012 a440fac0 2018-09-06 stsp buf = newbuf;
1013 a440fac0 2018-09-06 stsp remain += blocksize;
1014 a440fac0 2018-09-06 stsp }
1015 a440fac0 2018-09-06 stsp n = fread(buf + total, 1, remain, f);
1016 a440fac0 2018-09-06 stsp if (n == 0) {
1017 a440fac0 2018-09-06 stsp if (ferror(f)) {
1018 a440fac0 2018-09-06 stsp err = got_ferror(f, GOT_ERR_IO);
1019 a440fac0 2018-09-06 stsp goto done;
1020 a440fac0 2018-09-06 stsp }
1021 a440fac0 2018-09-06 stsp break; /* EOF */
1022 a440fac0 2018-09-06 stsp }
1023 a440fac0 2018-09-06 stsp remain -= n;
1024 a440fac0 2018-09-06 stsp total += n;
1025 a440fac0 2018-09-06 stsp };
1026 a440fac0 2018-09-06 stsp
1027 a440fac0 2018-09-06 stsp done:
1028 a440fac0 2018-09-06 stsp if (err == NULL) {
1029 a440fac0 2018-09-06 stsp *outbuf = buf;
1030 a440fac0 2018-09-06 stsp *outlen = total;
1031 a440fac0 2018-09-06 stsp } else
1032 a440fac0 2018-09-06 stsp free(buf);
1033 ad242220 2018-09-08 stsp return err;
1034 a440fac0 2018-09-06 stsp }