summaryrefslogtreecommitdiff
path: root/builtin/notes.c
diff options
context:
space:
mode:
authorJohan Herland <johan@herland.net>2014-02-12 09:54:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-02-20 22:14:33 (GMT)
commitce8daa1eb863c9cdefb06feae2ee7c742ea89847 (patch)
tree448c60ed092b4bc7130e11212082831cc82b9898 /builtin/notes.c
parent2f93541d88fadd1ff5307d81c2c8921ee3eea058 (diff)
downloadgit-ce8daa1eb863c9cdefb06feae2ee7c742ea89847.zip
git-ce8daa1eb863c9cdefb06feae2ee7c742ea89847.tar.gz
git-ce8daa1eb863c9cdefb06feae2ee7c742ea89847.tar.bz2
notes: disallow reusing non-blob as a note object
Currently "git notes add -C $object" will read the raw bytes from $object, and then copy those bytes into the note object, which is hardcoded to be of type blob. This means that if the given $object is a non-blob (e.g. tree or commit), the raw bytes from that object is copied into a blob object. This is probably not useful, and certainly not what any sane user would expect. So disallow it, by erroring out if the $object passed to the -C option is not a blob. The fix also applies to the -c option (in which the user is prompted to edit/verify the note contents in a text editor), and also when -c/-C is passed to "git notes append" (which appends the $object contents to an existing note object). In both cases, passing a non-blob $object does not make sense. Also add a couple of tests demonstrating expected behavior. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/notes.c')
-rw-r--r--builtin/notes.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/builtin/notes.c b/builtin/notes.c
index e4100c4..c11d6e6 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -269,7 +269,11 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
die(_("Failed to resolve '%s' as a valid ref."), arg);
if (!(buf = read_sha1_file(object, &type, &len)) || !len) {
free(buf);
- die(_("Failed to read object '%s'."), arg);;
+ die(_("Failed to read object '%s'."), arg);
+ }
+ if (type != OBJ_BLOB) {
+ free(buf);
+ die(_("Cannot read note data from non-blob object '%s'."), arg);
}
strbuf_add(&(msg->buf), buf, len);
free(buf);