{"thread":{"id":"3378","subject":"[PATCH] Prevent git-upload-pack segfault if object cannot be found","startedAt":"2006-02-18T00:14:52Z","lastAt":"2006-02-18T06:50:17Z","messageCount":2,"participants":["Carl Worth","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"16349","messageId":"87hd6x34lf.wl%cworth@cworth.org","threadId":"3378","inReplyTo":null,"subject":"[PATCH] Prevent git-upload-pack segfault if object cannot be found","fromName":"Carl Worth","fromEmail":"cworth@cworth.org","sentAt":"2006-02-18T00:14:52Z","receivedAt":"2006-02-18T00:14:52Z","isPatch":true,"sender":{"key":"cworth@cworth.org","avatar":"https://gravatar.com/avatar/3746dc28cde609bdbd7f939058356e7e2bbd16d21e32274df0725eb3d998bc5b?d=mp&s=160"},"body":"Signed-off-by: Carl Worth <cworth@cworth.org>\n\n---\n\nIt's probably a just-don't-do-that situation, but I did-it by moving a\ndirectory that had already been cached in objects/info/alternates by\nclone -l -s. Here's a fix for the segfault that that turned up.\n\nProbably trivial enough to not bother the list with, but I'm still\nlearning about formatting patches and mails and things, so I'm open to\nany feedback if I'm getting anything wrong.\n\n sha1_file.c   |    4 +++-\n upload-pack.c |    3 +++\n 2 files changed, 6 insertions(+), 1 deletion(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 64cf245..1d799f7 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -551,8 +551,10 @@ static void prepare_packed_git_one(char \n \tsprintf(path, \"%s/pack\", objdir);\n \tlen = strlen(path);\n \tdir = opendir(path);\n-\tif (!dir)\n+\tif (!dir) {\n+\t\tfprintf(stderr, \"unable to open object pack directory: %s: %s\\n\", path, strerror(errno));\n \t\treturn;\n+\t}\n \tpath[len++] = '/';\n \twhile ((de = readdir(dir)) != NULL) {\n \t\tint namelen = strlen(de->d_name);\ndiff --git a/upload-pack.c b/upload-pack.c\nindex d198055..3606529 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -216,6 +216,9 @@ static int send_ref(const char *refname,\n \tstatic char *capabilities = \"multi_ack\";\n \tstruct object *o = parse_object(sha1);\n \n+\tif (!o)\n+\t\tdie(\"git-upload-pack: cannot find object %s:\", sha1_to_hex(sha1));\n+\n \tif (capabilities)\n \t\tpacket_write(1, \"%s %s%c%s\\n\", sha1_to_hex(sha1), refname,\n \t\t\t0, capabilities);\n"},{"id":"16363","messageId":"7vd5hlupna.fsf@assigned-by-dhcp.cox.net","threadId":"3378","inReplyTo":"87hd6x34lf.wl%cworth@cworth.org","subject":"Re: [PATCH] Prevent git-upload-pack segfault if object cannot be found","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-02-18T06:50:17Z","receivedAt":"2006-02-18T06:50:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks, this is the last remaining call that did not check its\nreturn value from opendir().\n\nI queued this one and three clone things from you.  They will\nappear in \"next\" first, but also be in 1.2.2.\n"}]}