summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2009-08-17 07:19:05 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2009-08-17 07:24:36 (UTC)
commit8a631b1173b1abecc5a737b0e21751ddbabf9df2 (patch) (unidiff)
tree93320a0e21c1f13e936ccac66d250b28fa87acc1
parentfdd559abd6e6ec5e522dc5496b2bcabd36d6ba9d (diff)
downloadcgit-8a631b1173b1abecc5a737b0e21751ddbabf9df2.zip
cgit-8a631b1173b1abecc5a737b0e21751ddbabf9df2.tar.gz
cgit-8a631b1173b1abecc5a737b0e21751ddbabf9df2.tar.bz2
ui-tag.c: do not segfault when id is missing from query-string
The purpose of the tag page is to print info about a specific tag, but if no tag was specified on the query-string cgit used to segfault. With this patch, cgit will fallback to the value of the 'h' parameter instead (which is never NULL due to prepare_repo_cmd() in cgit.c). It will now also verify that the specified tagname is in fact a valid ref in the 'refs/tags/' namespace, i.e. specifying 'id=master' will trigger a 'Bad tag reference' error. Noticed-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-tag.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/ui-tag.c b/ui-tag.c
index 0e056e0..8c263ab 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -1,89 +1,92 @@
1/* ui-tag.c: display a tag 1/* ui-tag.c: display a tag
2 * 2 *
3 * Copyright (C) 2007 Lars Hjemli 3 * Copyright (C) 2007 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12 12
13static void print_tag_content(char *buf) 13static void print_tag_content(char *buf)
14{ 14{
15 char *p; 15 char *p;
16 16
17 if (!buf) 17 if (!buf)
18 return; 18 return;
19 19
20 html("<div class='commit-subject'>"); 20 html("<div class='commit-subject'>");
21 p = strchr(buf, '\n'); 21 p = strchr(buf, '\n');
22 if (p) 22 if (p)
23 *p = '\0'; 23 *p = '\0';
24 html_txt(buf); 24 html_txt(buf);
25 html("</div>"); 25 html("</div>");
26 if (p) { 26 if (p) {
27 html("<div class='commit-msg'>"); 27 html("<div class='commit-msg'>");
28 html_txt(++p); 28 html_txt(++p);
29 html("</div>"); 29 html("</div>");
30 } 30 }
31} 31}
32 32
33void cgit_print_tag(char *revname) 33void cgit_print_tag(char *revname)
34{ 34{
35 unsigned char sha1[20]; 35 unsigned char sha1[20];
36 struct object *obj; 36 struct object *obj;
37 struct tag *tag; 37 struct tag *tag;
38 struct taginfo *info; 38 struct taginfo *info;
39 39
40 if (get_sha1(revname, sha1)) { 40 if (!revname)
41 revname = ctx.qry.head;
42
43 if (get_sha1(fmt("refs/tags/%s", revname), sha1)) {
41 cgit_print_error(fmt("Bad tag reference: %s", revname)); 44 cgit_print_error(fmt("Bad tag reference: %s", revname));
42 return; 45 return;
43 } 46 }
44 obj = parse_object(sha1); 47 obj = parse_object(sha1);
45 if (!obj) { 48 if (!obj) {
46 cgit_print_error(fmt("Bad object id: %s", sha1_to_hex(sha1))); 49 cgit_print_error(fmt("Bad object id: %s", sha1_to_hex(sha1)));
47 return; 50 return;
48 } 51 }
49 if (obj->type == OBJ_TAG) { 52 if (obj->type == OBJ_TAG) {
50 tag = lookup_tag(sha1); 53 tag = lookup_tag(sha1);
51 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { 54 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
52 cgit_print_error(fmt("Bad tag object: %s", revname)); 55 cgit_print_error(fmt("Bad tag object: %s", revname));
53 return; 56 return;
54 } 57 }
55 html("<table class='commit-info'>\n"); 58 html("<table class='commit-info'>\n");
56 htmlf("<tr><td>Tag name</td><td>"); 59 htmlf("<tr><td>Tag name</td><td>");
57 html_txt(revname); 60 html_txt(revname);
58 htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1)); 61 htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1));
59 if (info->tagger_date > 0) { 62 if (info->tagger_date > 0) {
60 html("<tr><td>Tag date</td><td>"); 63 html("<tr><td>Tag date</td><td>");
61 cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time); 64 cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time);
62 html("</td></tr>\n"); 65 html("</td></tr>\n");
63 } 66 }
64 if (info->tagger) { 67 if (info->tagger) {
65 html("<tr><td>Tagged by</td><td>"); 68 html("<tr><td>Tagged by</td><td>");
66 html_txt(info->tagger); 69 html_txt(info->tagger);
67 if (info->tagger_email) { 70 if (info->tagger_email) {
68 html(" "); 71 html(" ");
69 html_txt(info->tagger_email); 72 html_txt(info->tagger_email);
70 } 73 }
71 html("</td></tr>\n"); 74 html("</td></tr>\n");
72 } 75 }
73 html("<tr><td>Tagged object</td><td>"); 76 html("<tr><td>Tagged object</td><td>");
74 cgit_object_link(tag->tagged); 77 cgit_object_link(tag->tagged);
75 html("</td></tr>\n"); 78 html("</td></tr>\n");
76 html("</table>\n"); 79 html("</table>\n");
77 print_tag_content(info->msg); 80 print_tag_content(info->msg);
78 } else { 81 } else {
79 html("<table class='commit-info'>\n"); 82 html("<table class='commit-info'>\n");
80 htmlf("<tr><td>Tag name</td><td>"); 83 htmlf("<tr><td>Tag name</td><td>");
81 html_txt(revname); 84 html_txt(revname);
82 html("</td></tr>\n"); 85 html("</td></tr>\n");
83 html("<tr><td>Tagged object</td><td>"); 86 html("<tr><td>Tagged object</td><td>");
84 cgit_object_link(obj); 87 cgit_object_link(obj);
85 html("</td></tr>\n"); 88 html("</td></tr>\n");
86 html("</table>\n"); 89 html("</table>\n");
87 } 90 }
88 return; 91 return;
89} 92}