From: Josh Micich <josh.micich@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Josh Micich <josh.micich@gmail.com>
Subject: Re: [PATCH 3/3] improved validation of entry type in mktree
Date: Thu, 14 May 2009 15:49:10 -0700 [thread overview]
Message-ID: <a644352c0905141549q495973dfn664bdad80629ac17@mail.gmail.com> (raw)
In-Reply-To: <a644352c0905141546w4193d45aq4940e72bbb4bda1c@mail.gmail.com>
Previously mktree would accept tree entries which had a mismatch
between the declared type and the actual type of object identified by
the sha.
Signed-off-by: Josh Micich <josh.micich@gmail.com>
---
builtin-mktree.c | 43 +++++++++++++++++++++++++++++++++----------
1 files changed, 33 insertions(+), 10 deletions(-)
diff --git a/builtin-mktree.c b/builtin-mktree.c
index 73b0abb..dc4f1a7 100644
--- a/builtin-mktree.c
+++ b/builtin-mktree.c
@@ -71,7 +71,8 @@ static void mktree_line(char *buf, size_t len, int
line_termination, int allow_m
{
char *ptr, *ntr;
unsigned mode;
- enum object_type type;
+ enum object_type mode_type; /* object type derived from mode */
+ enum object_type obj_type; /* object type derived from sha */
char *path;
unsigned char sha1[20];
@@ -94,17 +95,8 @@ static void mktree_line(char *buf, size_t len, int
line_termination, int allow_m
if (S_ISGITLINK(mode))
allow_missing = 1;
- if (!allow_missing)
- type = sha1_object_info(sha1, NULL);
- else
- type = object_type(mode);
-
- if (type < 0)
- die("object %s unavailable", sha1_to_hex(sha1));
*ntr++ = 0; /* now at the beginning of SHA1 */
- if (type != type_from_string(ptr))
- die("object type %s mismatch (%s)", ptr, typename(type));
path = ntr + 41; /* at the beginning of name */
if (line_termination && path[0] == '"') {
@@ -113,6 +105,37 @@ static void mktree_line(char *buf, size_t len,
int line_termination, int allow_m
die("invalid quoting");
path = strbuf_detach(&p_uq, NULL);
}
+
+ /*
+ * Object type is redundantly derivable three ways.
+ * These should all agree.
+ */
+ mode_type = object_type(mode);
+ if (mode_type != type_from_string(ptr)) {
+ die("entry '%s' object type (%s) doesn't match mode type (%s)",
+ path, ptr, typename(mode_type));
+ }
+
+ /* Check the type of object identified by sha1 */
+ obj_type = sha1_object_info(sha1, NULL);
+ if (obj_type < 0) {
+ if (allow_missing) {
+ ; /* no problem - missing objects are presumed to be of the right type */
+ } else {
+ die("entry '%s' object %s is unavailable", path, sha1_to_hex(sha1));
+ }
+ } else {
+ if (obj_type != mode_type) {
+ /*
+ * The object exists but is of the wrong type.
+ * This is a problem regardless of allow_missing
+ * because the new tree entry will never be correct.
+ */
+ die("entry '%s' object %s is a %s but specified type was (%s)",
+ path, sha1_to_hex(sha1), typename(obj_type), typename(mode_type));
+ }
+ }
+
append_to_tree(mode, sha1, path);
}
--
1.6.3.1.181.gfc9b3.dirty
next prev parent reply other threads:[~2009-05-14 22:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-14 5:06 Proposed patch for mktree [0/3] Josh Micich
2009-05-14 5:09 ` [PATCH 1/3] '--missing' option for mktree: re-added strbuf_release(&p_uq), Updated man page Josh Micich
2009-05-14 6:04 ` Junio C Hamano
2009-05-14 19:44 ` Josh Micich
2009-05-14 5:10 ` [PATCH 2/3] added --batch option to mktree Josh Micich
2009-05-14 6:18 ` Junio C Hamano
2009-05-14 9:24 ` Josh Micich
2009-05-14 10:25 ` Sverre Rabbelier
2009-05-14 19:51 ` Josh Micich
[not found] ` <a644352c0905140217h382a4d18h988b229c12577de3@mail.gmail.com>
2009-05-15 8:31 ` Junio C Hamano
2009-05-14 5:11 ` [PATCH 3/3] improved validation of entry type in mktree Josh Micich
2009-05-14 6:24 ` Junio C Hamano
2009-05-14 22:46 ` Josh Micich
2009-05-14 22:49 ` Josh Micich [this message]
2009-05-15 6:23 ` Jakub Narebski
2009-05-15 16:57 ` Josh Micich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a644352c0905141549q495973dfn664bdad80629ac17@mail.gmail.com \
--to=josh.micich@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).