From 8a631b1173b1abecc5a737b0e21751ddbabf9df2 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 17 Aug 2009 09:19:05 +0200 Subject: 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 Signed-off-by: Lars Hjemli --- ui-tag.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui-tag.c b/ui-tag.c index 0e056e0..8c263ab 100644 --- 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; } -- cgit 1.4.1-21-gabe81 From 435a1da8d1c43bff2f2ccd5649ea8510eec0b2af Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 17 Aug 2009 09:05:13 +0200 Subject: cgit.c: do not segfault on unexpected query-string format The querystring_cb() function will be invoked with a NULL value when the querystring contains a name not followed by a '='. Such a value used to cause a segfault, which this patch fixes. Signed-off-by: Lars Hjemli --- cgit.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cgit.c b/cgit.c index 64d95f9..5301840 100644 --- a/cgit.c +++ b/cgit.c @@ -132,6 +132,9 @@ void config_cb(const char *name, const char *value) static void querystring_cb(const char *name, const char *value) { + if (!value) + value = ""; + if (!strcmp(name,"r")) { ctx.qry.repo = xstrdup(value); ctx.repo = cgit_get_repoinfo(value); -- cgit 1.4.1-21-gabe81