]> granicus.if.org Git - cgit/commitdiff
ui-tag.c: do not segfault when id is missing from query-string
authorLars Hjemli <hjemli@gmail.com>
Mon, 17 Aug 2009 07:19:05 +0000 (09:19 +0200)
committerLars Hjemli <hjemli@gmail.com>
Mon, 17 Aug 2009 07:24:36 +0000 (09:24 +0200)
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>
ui-tag.c

index 0e056e016092f53c508d86cdefd3e76f0fcb7d36..8c263abea70bce9fedf5fe816cba78b44eb37d8b 100644 (file)
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -37,7 +37,10 @@ void cgit_print_tag(char *revname)
        struct tag *tag;
        struct taginfo *info;
 
-       if (get_sha1(revname, sha1)) {
+       if (!revname)
+               revname = ctx.qry.head;
+
+       if (get_sha1(fmt("refs/tags/%s", revname), sha1)) {
                cgit_print_error(fmt("Bad tag reference: %s", revname));
                return;
        }