# [PATCH] Prevent git-upload-pack segfault if object cannot be found

2 messages from 2006-02-18 to 2006-02-18. Participants: Carl Worth, Junio C Hamano.
Thread: https://gitlist.dev/t/3378

## Carl Worth, 2006-02-18 00:14

Subject: [PATCH] Prevent git-upload-pack segfault if object cannot be found
Message-ID: <87hd6x34lf.wl%cworth@cworth.org>
URL: https://gitlist.dev/e/87hd6x34lf.wl%25cworth%40cworth.org

```
Signed-off-by: Carl Worth <cworth@cworth.org>

---

It's probably a just-don't-do-that situation, but I did-it by moving a
directory that had already been cached in objects/info/alternates by
clone -l -s. Here's a fix for the segfault that that turned up.

Probably trivial enough to not bother the list with, but I'm still
learning about formatting patches and mails and things, so I'm open to
any feedback if I'm getting anything wrong.

 sha1_file.c   |    4 +++-
 upload-pack.c |    3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/sha1_file.c b/sha1_file.c
index 64cf245..1d799f7 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -551,8 +551,10 @@ static void prepare_packed_git_one(char 
 	sprintf(path, "%s/pack", objdir);
 	len = strlen(path);
 	dir = opendir(path);
-	if (!dir)
+	if (!dir) {
+		fprintf(stderr, "unable to open object pack directory: %s: %s\n", path, strerror(errno));
 		return;
+	}
 	path[len++] = '/';
 	while ((de = readdir(dir)) != NULL) {
 		int namelen = strlen(de->d_name);
diff --git a/upload-pack.c b/upload-pack.c
index d198055..3606529 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -216,6 +216,9 @@ static int send_ref(const char *refname,
 	static char *capabilities = "multi_ack";
 	struct object *o = parse_object(sha1);
 
+	if (!o)
+		die("git-upload-pack: cannot find object %s:", sha1_to_hex(sha1));
+
 	if (capabilities)
 		packet_write(1, "%s %s%c%s\n", sha1_to_hex(sha1), refname,
 			0, capabilities);

```

## Junio C Hamano, 2006-02-18 06:50

Subject: Re: [PATCH] Prevent git-upload-pack segfault if object cannot be found
Message-ID: <7vd5hlupna.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vd5hlupna.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <87hd6x34lf.wl%cworth@cworth.org>

```
Thanks, this is the last remaining call that did not check its
return value from opendir().

I queued this one and three clone things from you.  They will
appear in "next" first, but also be in 1.2.2.

```
