aboutsummaryrefslogtreecommitdiffstats
path: root/ui-diff.c
diff options
context:
space:
mode:
authorLukas Fleischer2013-08-20 18:56:12 +0200
committerJason A. Donenfeld2013-08-20 19:55:20 +0200
commit01db08372965b082239e7946255ac43f42d3e37d (patch)
tree2ae36a481ff08a5b9d715b2adbddb9dc931d1a47 /ui-diff.c
parent445f6ae8e3ef19b6ca70e741e934778bc4a05555 (diff)
downloadcgit-01db08372965b082239e7946255ac43f42d3e37d.tar.gz
cgit-01db08372965b082239e7946255ac43f42d3e37d.tar.bz2
cgit-01db08372965b082239e7946255ac43f42d3e37d.zip
ui-diff: Check the return value of get_sha1()
Sync with what we do everywhere else and check the return value of get_sha1() instead of calling sha1_object_info() to validate the object. Note that we later call lookup_commit_reference(), which checks that both SHA1 values refer to commits, anyway. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
Diffstat (limited to 'ui-diff.c')
-rw-r--r--ui-diff.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/ui-diff.c b/ui-diff.c
index 838db8c..1209c47 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -360,15 +360,11 @@ void cgit_print_diff_ctrls()
360void cgit_print_diff(const char *new_rev, const char *old_rev, 360void cgit_print_diff(const char *new_rev, const char *old_rev,
361 const char *prefix, int show_ctrls, int raw) 361 const char *prefix, int show_ctrls, int raw)
362{ 362{
363 enum object_type type;
364 unsigned long size;
365 struct commit *commit, *commit2; 363 struct commit *commit, *commit2;
366 364
367 if (!new_rev) 365 if (!new_rev)
368 new_rev = ctx.qry.head; 366 new_rev = ctx.qry.head;
369 get_sha1(new_rev, new_rev_sha1); 367 if (get_sha1(new_rev, new_rev_sha1)) {
370 type = sha1_object_info(new_rev_sha1, &size);
371 if (type == OBJ_BAD) {
372 cgit_print_error("Bad object name: %s", new_rev); 368 cgit_print_error("Bad object name: %s", new_rev);
373 return; 369 return;
374 } 370 }
@@ -378,19 +374,18 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
378 return; 374 return;
379 } 375 }
380 376
381 if (old_rev) 377 if (old_rev) {
382 get_sha1(old_rev, old_rev_sha1); 378 if (get_sha1(old_rev, old_rev_sha1)) {
383 else if (commit->parents && commit->parents->item) 379 cgit_print_error("Bad object name: %s", old_rev);
380 return;
381 }
382 } else if (commit->parents && commit->parents->item) {
384 hashcpy(old_rev_sha1, commit->parents->item->object.sha1); 383 hashcpy(old_rev_sha1, commit->parents->item->object.sha1);
385 else 384 } else {
386 hashclr(old_rev_sha1); 385 hashclr(old_rev_sha1);
386 }
387 387
388 if (!is_null_sha1(old_rev_sha1)) { 388 if (!is_null_sha1(old_rev_sha1)) {
389 type = sha1_object_info(old_rev_sha1, &size);
390 if (type == OBJ_BAD) {
391 cgit_print_error("Bad object name: %s", sha1_to_hex(old_rev_sha1));
392 return;
393 }
394 commit2 = lookup_commit_reference(old_rev_sha1); 389 commit2 = lookup_commit_reference(old_rev_sha1);
395 if (!commit2 || parse_commit(commit2)) { 390 if (!commit2 || parse_commit(commit2)) {
396 cgit_print_error("Bad commit: %s", sha1_to_hex(old_rev_sha1)); 391 cgit_print_error("Bad commit: %s", sha1_to_hex(old_rev_sha1));