threads / patch / 12135

patchparse_tag: fail, if tagged objected would be NULL

Subject: [PATCH] parse_tag: fail, if tagged objected would be NULL

## tl;dr

3 messages between Feb 16, 2008 and Feb 17, 2008. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Martin Koegler· Feb 16, 2008, 13:04 UTC · lore
The cause of a NULL in tag->tagged can be:
* a unknown object type is used
* the tag points to a object with an other type as stated
  in the tag.

Both situations are most likley be caused by a not welformed tag. Catching this error here avoids doing tag->tagged!=NULL checks in the rest of git.

Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
---
In my option, this change would simplity many things.
tag.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Show changes to tag.c +4 −0
diff --git a/tag.c b/tag.c
index 38bf913..96fef70 100644
--- a/tag.c
+++ b/tag.c
@@ -82,8 +82,12 @@ int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
 	} else {
 		error("Unknown type %s", type);
 		item->tagged = NULL;
+		return -1;
 	}
 
+	if (!item->tagged)
+		return -1;
+
 	if (item->tagged && track_object_refs) {
 		struct object_refs *refs = alloc_object_refs(1);
 		refs->ref[0] = item->tagged;
-- 
1.5.4.1.gcb4c5
Junio C Hamano· Feb 16, 2008, 19:13 UTC · re: Martin Koegler · lore

Re: [PATCH] parse_tag: fail, if tagged objected would be NULL

Martin Koegler <mkoegler@auto.tuwien.ac.at> writes:
Show 8 quoted lines
> The cause of a NULL in tag->tagged can be:
> * a unknown object type is used
> * the tag points to a object with an other type as stated
>   in the tag.
>
> Both situations are most likley be caused by a not welformed
> tag. Catching this error here avoids doing tag->tagged!=NULL
> checks in the rest of git.
Honestly, I am torn on this.

The approach certainly is attractive if you care only about working in a perfectly well connected repository of a known vintage.

On the other hand, however, this robs from callers the clue that the tag itself was Ok but it points at something we do not know about. Maybe the caller was only interested in the tag itself but did not care about the pointee, and erroring out like this may make it impossible for the caller to act on the tag itself. Maybe the caller even knew about the breakage of the repository and wanted to salvage as much as possible, but because this errors out, it would now consider this tag object itself is bad and give up, salvaging one less object. It looks to me that this, along with other "tighten parse_X_buffer()" changes you sent earlier, closes door to them. That's why I think that parse_X_buffer() should be more lenient than fsck and keep saying it.

Martin Koegler· Feb 17, 2008, 17:48 UTC · re: Junio C Hamano · lore

Re: [PATCH] parse_tag: fail, if tagged objected would be NULL

On Sat, Feb 16, 2008 at 11:13:56AM -0800, Junio C Hamano wrote:
Show 26 quoted lines
> Martin Koegler <mkoegler@auto.tuwien.ac.at> writes:
> 
> > The cause of a NULL in tag->tagged can be:
> > * a unknown object type is used
> > * the tag points to a object with an other type as stated
> >   in the tag.
> >
> > Both situations are most likley be caused by a not welformed
> > tag. Catching this error here avoids doing tag->tagged!=NULL
> > checks in the rest of git.
> 
> Honestly, I am torn on this.
> 
> The approach certainly is attractive if you care only about
> working in a perfectly well connected repository of a known
> vintage.
> 
> On the other hand, however, this robs from callers the clue that
> the tag itself was Ok but it points at something we do not know
> about.  Maybe the caller was only interested in the tag itself
> but did not care about the pointee, and erroring out like this
> may make it impossible for the caller to act on the tag itself.
> Maybe the caller even knew about the breakage of the repository
> and wanted to salvage as much as possible, but because this
> errors out, it would now consider this tag object itself is bad
> and give up, salvaging one less object. 

This opens up the question, why do we set tagged to NULL in the case of an unknown object? If we want to get out as much information as possible, we could call lookup_unknown_object and store the result.

Show 5 quoted lines
> It looks to me that
> this, along with other "tighten parse_X_buffer()" changes you
> sent earlier, closes door to them.  That's why I think that
> parse_X_buffer() should be more lenient than fsck and keep
> saying it.
OK, so please forget the parse_tag_buffer patch. 

If I understand you correctly, you want to reject my last parse_commit_buffer patch (parse_commit: don't ignore NULL from loopup_commit, http://www.spinics.net/lists/git/msg58148.html) because of the same reasons.

This means, that Shawns idea (using rev-list for reachability checking during upload, http://www.spinics.net/lists/git/msg57978.html) is not implementable, as certain kinds of errors are not reported to the caller by parse_commit(_buffer).

mfg Martin Kögler

← back to recent threads