commit - 34ca489849f1d73f5e1ac4a68208fbb0601901fb
commit + 5d844a1e3768d8c536169a754802b4bf8ebdd64c
blob - 2a63d8f1f0a6106de69dbfe0a9a3082b29b5c066
blob + 263bc2cb88607d7fc3ebf4d3c07422a39951de68
--- got/got.c
+++ got/got.c
name += 8;
if (strncmp(name, "tags/", 5) == 0) {
err = got_object_open_as_tag(&tag, repo, re->id);
- if (err)
- return err;
+ if (err) {
+ if (err->code != GOT_ERR_OBJ_TYPE)
+ return err;
+ /* Ref points at something other than a tag. */
+ err = NULL;
+ tag = NULL;
+ }
}
cmp = got_object_id_cmp(tag ?
got_object_tag_get_object_id(tag) : re->id, id);
blob - 63fbc857f6aca730ac30a8872e56c453ca7b60a3
blob + 79ee0f0c8347e32173b918ab6724d3456a467899
--- lib/object.c
+++ lib/object.c
struct got_packidx *packidx = NULL;
int idx;
char *path_packfile = NULL;
+ struct got_object *obj = NULL;
+ int obj_type = GOT_OBJ_TYPE_ANY;
if (check_cache) {
*tag = got_repo_get_cached_tag(repo, id);
if (err)
goto done;
}
- err = read_packed_tag_privsep(tag, pack,
- packidx, idx, id);
+
+ /* Beware of "leightweight" tags: Check object type first. */
+ err = read_packed_object_privsep(&obj, repo, pack, packidx,
+ idx, id);
+ if (err)
+ goto done;
+ obj_type = obj->type;
+ got_object_close(obj);
+ if (obj_type != GOT_OBJ_TYPE_TAG) {
+ err = got_error(GOT_ERR_OBJ_TYPE);
+ goto done;
+ }
+ err = read_packed_tag_privsep(tag, pack, packidx, idx, id);
} else if (err->code == GOT_ERR_NO_OBJ) {
int fd;
err = open_loose_object(&fd, id, repo);
if (err)
return err;
+ err = read_object_header_privsep(&obj, repo, fd);
+ if (err)
+ return err;
+ obj_type = obj->type;
+ got_object_close(obj);
+ if (obj_type != GOT_OBJ_TYPE_TAG)
+ return got_error(GOT_ERR_OBJ_TYPE);
+
+ err = open_loose_object(&fd, id, repo);
+ if (err)
+ return err;
err = read_tag_privsep(tag, fd, repo);
}
blob - 68b3bebcf73256d66fd1896739ae25c59583aa4d
blob + 330cb7270dac76c013148197dd78c6c658c5b281
--- tog/tog.c
+++ tog/tog.c
name += 8;
if (strncmp(name, "tags/", 5) == 0) {
err = got_object_open_as_tag(&tag, repo, re->id);
- if (err)
- break;
+ if (err) {
+ if (err->code != GOT_ERR_OBJ_TYPE)
+ break;
+ /* Ref points at something other than a tag. */
+ err = NULL;
+ tag = NULL;
+ }
}
cmp = got_object_id_cmp(tag ?
got_object_tag_get_object_id(tag) : re->id, id);