Fix random sha1 in error message in http-fetch and http-push
When a downloaded ref doesn't contain a sha1, the error message displays a random sha1 because of uninitialized memory. This happens when cloning a repository that is already a clone of another one, in which case refs/remotes/origin/HEAD is a symref. Signed-off-by: Mike Hommey <mh@glandium.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Mike Hommey committed
Dec 14, 2007 at 22:18 UTC
a096bb18af5b7214d9b87b64ae733d106eb96544
2 files changed
+6
-4
http-push.c
+3
-2
@@ -1149,9 +1149,10 @@ int fetch_ref(char *ref, unsigned char *sha1)
1149
return error("Unable to start request");
1150
}
1151
1152
+ if (buffer.posn != 41)
1153
+ return 1;
1154
hex[40] = '\0';
1153
- get_sha1_hex(hex, sha1);
1154
- return 0;
1155
+ return get_sha1_hex(hex, sha1);
1156
}
1157
1158
static void one_remote_object(const char *hex)
http-walker.c
+3
-2
@@ -986,9 +986,10 @@ static int fetch_ref(struct walker *walker, char *ref, unsigned char *sha1)
986
return error("Unable to start request");
987
}
988
989
+ if (buffer.posn != 41)
990
+ return 1;
991
hex[40] = '\0';
990
- get_sha1_hex(hex, sha1);
991
- return 0;
992
+ return get_sha1_hex(hex, sha1);
993
}
994
995
static void cleanup(struct walker *walker)