Be careful when dereferencing tags.
One caller of deref_tag() was not careful enough to make sure what deref_tag() returned was not NULL (i.e. we found a tag object that points at an object we do not have). Fix it, and warn about refs that point at such an incomplete tag where needed. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Nov 2, 2005 at 15:19 UTC
9534f40bc42dd826cc26c8c8c84f6a8a5fc569f6
9 files changed
+21
-14
commit.c
+1
-1
@@ -55,7 +55,7 @@ static struct commit *check_commit(struct object *obj,
55
struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
56
int quiet)
57
{
58
- struct object *obj = deref_tag(parse_object(sha1));
58
+ struct object *obj = deref_tag(parse_object(sha1), NULL, 0);
59
60
if (!obj)
61
return NULL;
fetch-pack.c
+4
-3
@@ -38,9 +38,9 @@ static void rev_list_push(struct commit *commit, int mark)
38
39
static int rev_list_insert_ref(const char *path, const unsigned char *sha1)
40
{
41
- struct object *o = deref_tag(parse_object(sha1));
41
+ struct object *o = deref_tag(parse_object(sha1), path, 0);
42
43
- if (o->type == commit_type)
43
+ if (o && o->type == commit_type)
44
rev_list_push((struct commit *)o, SEEN);
45
46
return 0;
@@ -317,7 +317,8 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
317
* Don't mark them common yet; the server has to be told so first.
318
*/
319
for (ref = *refs; ref; ref = ref->next) {
320
- struct object *o = deref_tag(lookup_object(ref->old_sha1));
320
+ struct object *o = deref_tag(lookup_object(ref->old_sha1),
321
+ NULL, 0);
322
323
if (!o || o->type != commit_type || !(o->flags & COMPLETE))
324
continue;
name-rev.c
+1
-1
@@ -164,7 +164,7 @@ int main(int argc, char **argv)
164
continue;
165
}
166
167
- o = deref_tag(parse_object(sha1));
167
+ o = deref_tag(parse_object(sha1), *argv, 0);
168
if (!o || o->type != commit_type) {
169
fprintf(stderr, "Could not get commit for %s. Skipping.\n",
170
*argv);
send-pack.c
+2
-2
@@ -126,12 +126,12 @@ static int ref_newer(const unsigned char *new_sha1,
126
/* Both new and old must be commit-ish and new is descendant of
127
* old. Otherwise we require --force.
128
*/
129
- o = deref_tag(parse_object(old_sha1));
129
+ o = deref_tag(parse_object(old_sha1), NULL, 0);
130
if (!o || o->type != commit_type)
131
return 0;
132
old = (struct commit *) o;
133
134
- o = deref_tag(parse_object(new_sha1));
134
+ o = deref_tag(parse_object(new_sha1), NULL, 0);
135
if (!o || o->type != commit_type)
136
return 0;
137
new = (struct commit *) o;
server-info.c
+4
-3
@@ -13,9 +13,10 @@ static int add_info_ref(const char *path, const unsigned char *sha1)
13
14
fprintf(info_ref_fp, "%s %s\n", sha1_to_hex(sha1), path);
15
if (o->type == tag_type) {
16
- o = deref_tag(o);
17
- fprintf(info_ref_fp, "%s %s^{}\n",
18
- sha1_to_hex(o->sha1), path);
16
+ o = deref_tag(o, path, 0);
17
+ if (o)
18
+ fprintf(info_ref_fp, "%s %s^{}\n",
19
+ sha1_to_hex(o->sha1), path);
20
}
21
return 0;
22
}
sha1_name.c
+1
-1
@@ -349,7 +349,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
349
if (!o)
350
return -1;
351
if (!type_string) {
352
- o = deref_tag(o);
352
+ o = deref_tag(o, name, sp - name - 2);
353
if (!o || (!o->parsed && !parse_object(o->sha1)))
354
return -1;
355
memcpy(sha1, o->sha1, 20);
tag.c
+6
-1
@@ -3,10 +3,15 @@
3
4
const char *tag_type = "tag";
5
6
-struct object *deref_tag(struct object *o)
6
+struct object *deref_tag(struct object *o, const char *warn, int warnlen)
7
{
8
while (o && o->type == tag_type)
9
o = parse_object(((struct tag *)o)->tagged->sha1);
10
+ if (!o && warn) {
11
+ if (!warnlen)
12
+ warnlen = strlen(warn);
13
+ error("missing object referenced by '%.*s'", warnlen, warn);
14
+ }
15
return o;
16
}
17
tag.h
+1
-1
@@ -15,6 +15,6 @@ struct tag {
15
extern struct tag *lookup_tag(const unsigned char *sha1);
16
extern int parse_tag_buffer(struct tag *item, void *data, unsigned long size);
17
extern int parse_tag(struct tag *item);
18
-extern struct object *deref_tag(struct object *);
18
+extern struct object *deref_tag(struct object *, const char *, int);
19
20
#endif /* TAG_H */
upload-pack.c
+1
-1
@@ -226,7 +226,7 @@ static int send_ref(const char *refname, const unsigned char *sha1)
226
nr_our_refs++;
227
}
228
if (o->type == tag_type) {
229
- o = deref_tag(o);
229
+ o = deref_tag(o, refname, 0);
230
packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname);
231
}
232
return 0;