git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] notes: do not accept non-blobs as new notes
@ 2012-05-08 13:11 Nguyễn Thái Ngọc Duy
  2012-05-08 16:03 ` Jeff King
  2012-05-10 14:04 ` [PATCH 0/4] git-notes ui fixes regarding non-blobs notes Nguyễn Thái Ngọc Duy
  0 siblings, 2 replies; 29+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2012-05-08 13:11 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Nguyễn Thái Ngọc Duy

While at it, check if current notes are blobs before using them.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/notes.c  |    9 ++++++++-
 t/t3301-notes.sh |    4 ++++
 2 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index 3644d14..5f276fc 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -114,6 +114,8 @@ static void write_note_data(int fd, const unsigned char *sha1)
 	enum object_type type;
 	char *buf = read_sha1_file(sha1, &type, &size);
 	if (buf) {
+		if (type != OBJ_BLOB)
+			die(_("note %s is not a blob"), sha1_to_hex(sha1));
 		if (size)
 			write_or_die(fd, buf, size);
 		free(buf);
@@ -201,8 +203,11 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
 		strbuf_grow(&(msg->buf), size + 1);
 		if (msg->buf.len && prev_buf && size)
 			strbuf_insert(&(msg->buf), 0, "\n", 1);
-		if (prev_buf && size)
+		if (prev_buf && size) {
+			if (type != OBJ_BLOB)
+				die(_("note %s is not a blob"), sha1_to_hex(prev));
 			strbuf_insert(&(msg->buf), 0, prev_buf, size);
+		}
 		free(prev_buf);
 	}
 
@@ -274,6 +279,8 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
 		free(buf);
 		die(_("Failed to read object '%s'."), arg);;
 	}
+	if (type != OBJ_BLOB)
+		die(_("%s is not a blob, invalid for notes"), sha1_to_hex(object));
 	strbuf_add(&(msg->buf), buf, len);
 	free(buf);
 
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 16de05a..8c72755 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -1222,4 +1222,8 @@ test_expect_success 'git notes get-ref (--ref)' '
 	test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
 '
 
+test_expect_success 'non-blobs cannot be notes' '
+	test_must_fail git notes add -f -C HEAD^{tree}
+'
+
 test_done
-- 
1.7.8.36.g69ee2

^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2012-05-12  6:59 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-08 13:11 [PATCH] notes: do not accept non-blobs as new notes Nguyễn Thái Ngọc Duy
2012-05-08 16:03 ` Jeff King
2012-05-08 16:26   ` Junio C Hamano
2012-05-09  8:19   ` Nguyen Thai Ngoc Duy
2012-05-09 17:37     ` Jeff King
2012-05-09 17:52       ` Junio C Hamano
2012-05-09 18:43         ` Jeff King
2012-05-10 14:04 ` [PATCH 0/4] git-notes ui fixes regarding non-blobs notes Nguyễn Thái Ngọc Duy
2012-05-10 14:04   ` [PATCH 1/4] notes: preserve object type given by "add -C" Nguyễn Thái Ngọc Duy
2012-05-10 14:04   ` [PATCH 2/4] notes: "add -c" refuses to open an editor with non-blobs Nguyễn Thái Ngọc Duy
2012-05-10 15:26     ` Johannes Sixt
2012-05-11  1:11       ` Nguyen Thai Ngoc Duy
2012-05-10 14:05   ` [PATCH 3/4] notes: refuse to edit non-blobs Nguyễn Thái Ngọc Duy
2012-05-10 14:05   ` [PATCH 4/4] notes: refuse to append to non-blob notes Nguyễn Thái Ngọc Duy
2012-05-10 14:43     ` [PATCH 4/4] notes: only append a blob to a blob Nguyễn Thái Ngọc Duy
2012-05-10 15:19       ` Jeff King
2012-05-10 15:31         ` Nguyen Thai Ngoc Duy
2012-05-10 15:45           ` Jeff King
2012-05-11  3:57             ` Junio C Hamano
2012-05-10 14:29   ` [PATCH 0/4] git-notes ui fixes regarding non-blobs notes Jeff King
2012-05-11  1:25   ` [PATCH v2 0/4] non-blob notes fixes Nguyễn Thái Ngọc Duy
2012-05-11  1:25   ` [PATCH v2 1/4] notes: preserve object type given by "add -C" Nguyễn Thái Ngọc Duy
2012-05-11 21:16     ` Junio C Hamano
2012-05-12  5:20       ` Nguyen Thai Ngoc Duy
2012-05-12  6:12         ` Junio C Hamano
2012-05-12  6:58           ` Nguyen Thai Ngoc Duy
2012-05-11  1:25   ` [PATCH v2 2/4] notes: "add -c" refuses to open an editor with non-blobs Nguyễn Thái Ngọc Duy
2012-05-11  1:25   ` [PATCH v2 3/4] notes: refuse to edit non-blobs Nguyễn Thái Ngọc Duy
2012-05-11  1:25   ` [PATCH v2 4/4] notes: only allow to append a blob to a blob Nguyễn Thái Ngọc Duy

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).