Don't ever return corrupt objects from "parse_object()"
Looking at the SHA1 validation code due to the corruption that Alexander Litvinov is seeing under Cygwin, I notice that one of the most central places where we read objects, we actually do end up verifying the SHA1 of the result, but then we happily parse it anyway. And using "printf" to write the error message means that it not only can get lost, but will actually mess up stdout, and cause other strange and hard-to-debug failures downstream. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
Mar 20, 2007 at 10:05 UTC
acdeec62cb644e48436bbe931e69b3d4842344cb
1 file changed
+4
-2
object.c
+4
-2
@@ -184,8 +184,10 @@ struct object *parse_object(const unsigned char *sha1)
184
185
if (buffer) {
186
struct object *obj;
187
- if (check_sha1_signature(sha1, buffer, size, typename(type)) < 0)
188
- printf("sha1 mismatch %s\n", sha1_to_hex(sha1));
187
+ if (check_sha1_signature(sha1, buffer, size, typename(type)) < 0) {
188
+ error("sha1 mismatch %s\n", sha1_to_hex(sha1));
189
+ return NULL;
190
+ }
191
192
obj = parse_object_buffer(sha1, type, size, buffer, &eaten);
193
if (!eaten)