# [BUG] comments in grafts file broken in current master

2 messages from 2006-04-16 to 2006-04-16. Participants: Yann Dirson, Junio C Hamano.
Thread: https://gitlist.dev/t/3889

## Yann Dirson, 2006-04-16 12:35

Subject: [BUG] comments in grafts file broken in current master
Message-ID: <20060416123535.GT12638@nowhere.earth>
URL: https://gitlist.dev/e/20060416123535.GT12638%40nowhere.earth

```
While looking at allowing empty lines in grafts files, I discovered
that comments had already been implemented.  However, current
git-read-tree segfaults when there is a comment line in info/grafts:

dwitch@gandelf:/export/work/yann/git/git$ cat .git/info/grafts 
c118c026e44f02c3dbad00d924285eef2340f700
# foo
dwitch@gandelf:/export/work/yann/git/git$ git-read-tree master
Segmentation fault


The commit introducing the problem is
5040f17eba15504bad66b14a645bddd9b015ebb7 (blame -S <ancestry-file>),
which changes quite some things in the grafts area.
    

BTW, after segfaulting, .git/index.lock is still there, and the
"unable to create new cachefile" is not so helpful - I had to strace
to see what was happenning.

Hope this helps,
-- 
Yann Dirson    <ydirson@altern.org> |
Debian-related: <dirson@debian.org> |   Support Debian GNU/Linux:
                                    |  Freedom, Power, Stability, Gratis
     http://ydirson.free.fr/        | Check <http://www.debian.org/>

```

## Junio C Hamano, 2006-04-16 21:26

Subject: [PATCH] reading $GIT_DIR/info/graft - skip comments correctly.
Message-ID: <7v64l9qkjd.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v64l9qkjd.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20060416123535.GT12638@nowhere.earth>

```
Noticed by Yann Dirson.

Signed-off-by: Junio C Hamano <junkio@cox.net>

---

  Yann Dirson <ydirson@altern.org> writes:

  > While looking at allowing empty lines in grafts files, I discovered
  > that comments had already been implemented.  However, current
  > git-read-tree segfaults when there is a comment line in info/grafts:
  >
  > dwitch@gandelf:/export/work/yann/git/git$ cat .git/info/grafts 
  > c118c026e44f02c3dbad00d924285eef2340f700
  > # foo
  > dwitch@gandelf:/export/work/yann/git/git$ git-read-tree master
  > Segmentation fault

  Thanks for noticing.

 commit.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

5bc4ce589646faf72c7a77a5d32d9496ccc8d456
diff --git a/commit.c b/commit.c
index ca25574..05c4c92 100644
--- a/commit.c
+++ b/commit.c
@@ -161,7 +161,7 @@ struct commit_graft *read_graft_line(cha
 	if (buf[len-1] == '\n')
 		buf[--len] = 0;
 	if (buf[0] == '#')
-		return 0;
+		return NULL;
 	if ((len + 1) % 41) {
 	bad_graft_data:
 		error("bad graft data: %s", buf);
@@ -192,6 +192,8 @@ int read_graft_file(const char *graft_fi
 		/* The format is just "Commit Parent1 Parent2 ...\n" */
 		int len = strlen(buf);
 		struct commit_graft *graft = read_graft_line(buf, len);
+		if (!graft)
+			continue;
 		if (register_commit_graft(graft, 1))
 			error("duplicate graft data: %s", buf);
 	}
-- 
1.3.0.rc4.g4024

```
