From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH/RFC] Disallow NULL in struct commit_list
Date: Wed, 17 Aug 2011 09:01:18 +0700 [thread overview]
Message-ID: <1313546478-8833-1-git-send-email-pclouds@gmail.com> (raw)
It seems to me that in most cases commit_list is supposed to contain
real commits. If someone puts a NULL there by accident, it'd be hard to
track down because sigsegv would happen later when the the commit is
used, not when added.
So perhaps we could safeguard commit_list_insert(). If a bug tries to
put NULL in, it'd be caught earlier.
There is code that add NULL commit on purpose, "make test" only catches
one in revert.c, but I may miss other cases and crash system unnecessarily.
Not sure if this patch is worth the trouble. Maybe make it permanent
resident of next and never graduate to master?
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/merge.c | 2 +-
builtin/revert.c | 2 +-
commit.c | 3 +++
commit.h | 2 ++
4 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 325891e..158008d 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -611,7 +611,7 @@ static void write_tree_trivial(unsigned char *sha1)
static const char *merge_argument(struct commit *commit)
{
- if (commit)
+ if (commit && commit != &null_commit)
return sha1_to_hex(commit->object.sha1);
else
return EMPTY_TREE_SHA1_HEX;
diff --git a/builtin/revert.c b/builtin/revert.c
index 1f27c63..7d5005e 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -471,7 +471,7 @@ static int do_pick_commit(void)
}
strbuf_addstr(&msgbuf, ".\n");
} else {
- base = parent;
+ base = parent ? parent : &null_commit;
base_label = msg.parent_label;
next = commit;
next_label = msg.label;
diff --git a/commit.c b/commit.c
index dc22695..604d2f1 100644
--- a/commit.c
+++ b/commit.c
@@ -11,6 +11,8 @@ int save_commit_buffer = 1;
const char *commit_type = "commit";
+struct commit null_commit;
+
static struct commit *check_commit(struct object *obj,
const unsigned char *sha1,
int quiet)
@@ -363,6 +365,7 @@ int find_commit_subject(const char *commit_buffer, const char **subject)
struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p)
{
struct commit_list *new_list = xmalloc(sizeof(struct commit_list));
+ assert(item != NULL);
new_list->item = item;
new_list->next = *list_p;
*list_p = new_list;
diff --git a/commit.h b/commit.h
index 0e36fd0..c9f0743 100644
--- a/commit.h
+++ b/commit.h
@@ -21,6 +21,8 @@ struct commit {
char *buffer;
};
+extern struct commit null_commit;
+
extern int save_commit_buffer;
extern const char *commit_type;
--
1.7.4.74.g639db
reply other threads:[~2011-08-17 2:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1313546478-8833-1-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/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).