commit - 12bec09b8ee75929ed950b389867d6116246a690
commit + a578d6ec6d3818f6a19379ef10e6def9dc71abb1
blob - eb6769ef2d4ba39ff599e3c075d2618ee4890387
blob + c1ab1a494a04643b73a4f64ba8ad9f03e68f6285
--- lib/got_lib_privsep.h
+++ lib/got_lib_privsep.h
/* Structure for GOT_IMSG_COMMIT_TRAVERSAL_REQUEST */
struct got_imsg_commit_traversal_request {
- uint8_t id[SHA1_DIGEST_LENGTH];
- int idx;
+ struct got_imsg_packed_object iobj;
size_t path_len;
/* Followed by path_len bytes of path data */
} __attribute__((__packed__));
blob - ad308a6c9b7dda90ed15a2273bf2b022c64e6c05
blob + 57c7e0e532d44492699622e9ff0ff3feab6aee72
--- lib/privsep.c
+++ lib/privsep.c
struct got_object_id *id, int idx, const char *path)
{
struct ibuf *wbuf;
- size_t path_len = strlen(path) + 1;
+ size_t path_len = strlen(path);
wbuf = imsg_create(ibuf, GOT_IMSG_COMMIT_TRAVERSAL_REQUEST, 0, 0,
sizeof(struct got_imsg_commit_traversal_request) + path_len);
if (wbuf == NULL)
return got_error_from_errno(
"imsg_create COMMIT_TRAVERSAL_REQUEST");
- if (imsg_add(wbuf, id->sha1, SHA1_DIGEST_LENGTH) == -1)
+ /*
+ * Keep in sync with struct got_imsg_commit_traversal_request
+ * and struct got_imsg_packed_object.
+ */
+ if (imsg_add(wbuf, id, sizeof(*id)) == -1)
return got_error_from_errno("imsg_add "
"COMMIT_TRAVERSAL_REQUEST");
if (imsg_add(wbuf, &idx, sizeof(idx)) == -1)
return got_error_from_errno("imsg_add "
"COMMIT_TRAVERSAL_REQUEST");
+ if (imsg_add(wbuf, &path_len, sizeof(path_len)) == -1)
+ return got_error_from_errno("imsg_add "
+ "COMMIT_TRAVERSAL_REQUEST");
if (imsg_add(wbuf, path, path_len) == -1)
return got_error_from_errno("imsg_add "
"COMMIT_TRAVERSAL_REQUEST");
blob - f62b5b34419a28d58f8666b7c7f128f4fdde0513
blob + 13179ad27a006789e9d95798304f06ea601f25df
--- libexec/got-read-pack/got-read-pack.c
+++ libexec/got-read-pack/got-read-pack.c
struct got_object_cache *objcache)
{
const struct got_error *err = NULL;
- struct got_imsg_packed_object iobj;
+ struct got_imsg_commit_traversal_request ctreq;
struct got_object_qid *pid;
struct got_commit_object *commit = NULL, *pcommit = NULL;
struct got_parsed_tree_entry *entries = NULL, *pentries = NULL;
size_t nentries = 0, nentries_alloc = 0;
size_t pnentries = 0, pnentries_alloc = 0;
struct got_object_id id;
- size_t datalen, path_len;
+ size_t datalen;
char *path = NULL;
const int min_alloc = 64;
int changed = 0, ncommits = 0, nallocated = 0;
struct got_object_id *commit_ids = NULL;
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
- if (datalen < sizeof(iobj))
- return got_error(GOT_ERR_PRIVSEP_LEN);
- memcpy(&iobj, imsg->data, sizeof(iobj));
- memcpy(&id, &iobj.id, sizeof(id));
+ if (datalen < sizeof(ctreq))
+ return got_error(GOT_ERR_PRIVSEP_LEN);
+ memcpy(&ctreq, imsg->data, sizeof(ctreq));
+ memcpy(&id, &ctreq.iobj.id, sizeof(id));
- path_len = datalen - sizeof(iobj) - 1;
- if (path_len < 0)
+ if (datalen != sizeof(ctreq) + ctreq.path_len)
return got_error(GOT_ERR_PRIVSEP_LEN);
- if (path_len > 0) {
- path = imsg->data + sizeof(iobj);
- if (path[path_len] != '\0')
- return got_error(GOT_ERR_PRIVSEP_LEN);
- }
+ if (ctreq.path_len == 0)
+ return got_error(GOT_ERR_PRIVSEP_LEN);
+ path = strndup(imsg->data + sizeof(ctreq), ctreq.path_len);
+ if (path == NULL)
+ return got_error_from_errno("strndup");
+
nallocated = min_alloc;
commit_ids = reallocarray(NULL, nallocated, sizeof(*commit_ids));
if (commit_ids == NULL)
}
err = send_commit_traversal_done(ibuf);
done:
+ free(path);
free(commit_ids);
if (commit)
got_object_commit_close(commit);