diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Answer 404 for any path below the about page
The about page served every file beside the readme as a page of its
own, through the about filter, and answered 200 for directories and
missing files alike. Images it passed through came from the root of the
default branch whatever the readme's own directory and ref. A readme on
disk exposed its whole directory this way.
Diffstat (limited to 'source/ui-summary.c')
| -rw-r--r-- | source/ui-summary.c | 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 3 insertions, 90 deletions
diff --git a/source/ui-summary.c b/source/ui-summary.c index 61cd6ac..e7b229a 100644 --- a/source/ui-summary.c +++ b/source/ui-summary.c @@ -4,8 +4,7 @@ * with the clone urls, reusing the listings ui-refs.c and ui-log.c draw * elsewhere. The about page renders the readme that config parsing picked for * the repository, either through the configured about filter or escaped as - * plain text, and it can serve a file sitting beside that readme so links - * inside the readme resolve. + * plain text. */ #include "cgit.h" @@ -14,7 +13,6 @@ #include "shared.h" #include "ui-blob.h" #include "ui-log.h" -#include "ui-plain.h" #include "ui-refs.h" #include "ui-shared.h" #include "ui-summary.h" @@ -52,66 +50,6 @@ static void print_clone_url(const char *url) cgit_print_clone_row(url, columns); } -/* - * Without the separator boundary a sibling directory that merely shares the - * base as a name prefix, such as repo.git-backup beside repo.git, would pass. - */ -static int path_within(const char *base, const char *path) -{ - size_t len = strlen(base); - - return starts_with(path, base) && (path[len] == '\0' || path[len] == '/'); -} - -/* - * Returns a path the caller must free, or NULL when the request cannot be - * served. A null ref means the readme is a file on the server's disk, and - * such a readme is confined to its own directory, so one named without a - * directory is refused. - */ -static char *resolve_about_path(const char *filename, const char *ref, const char *path) -{ - char *copy, *base_dir, *full_path; - char *resolved_base = NULL, *resolved_full = NULL, *resolved_repo = NULL; - - // dirname is allowed to write into its argument and to return a - // pointer into it, so base_dir borrows from a copy freed at the end. - copy = xstrdup(filename); - base_dir = dirname(copy); - if (!strcmp(base_dir, ".") || !strcmp(base_dir, "..")) { - if (!ref) { - free(copy); - return NULL; - } - full_path = xstrdup(path); - } else { - full_path = cgit_fmtalloc("%s/%s", base_dir, path); - } - - // A readme in the repository directory, or above it, would open the - // repository's own files, its config and hooks among them. - if (!ref) { - resolved_base = realpath(base_dir, NULL); - resolved_full = realpath(full_path, NULL); - resolved_repo = realpath(ctx.repo->path, NULL); - if ( - !resolved_base || !resolved_full || !resolved_repo || - path_within(resolved_base, resolved_repo) || - !path_within(resolved_base, resolved_full) - ) { - free(full_path); - full_path = NULL; - } - } - - free(copy); - free(resolved_base); - free(resolved_full); - free(resolved_repo); - - return full_path; -} - void cgit_print_summary(void) { cgit_print_layout_start(); @@ -130,34 +68,14 @@ void cgit_print_summary(void) cgit_print_layout_end(); } -void cgit_print_repo_readme(const char *path) +void cgit_print_repo_readme(void) { - char *filename, *ref, *mimetype; - int free_filename = 0; - - mimetype = cgit_get_mimetype_for_filename(path); - if (mimetype && (starts_with(mimetype, "image/") || starts_with(mimetype, "video/"))) { - ctx.page.mimetype = mimetype; - cgit_print_plain(); - free(mimetype); - return; - } - free(mimetype); + char *filename, *ref; cgit_print_layout_start(); - if (ctx.repo->readme.nr == 0) - goto done; - filename = ctx.repo->readme.items[0].string; ref = ctx.repo->readme.items[0].util; - if (path) { - free_filename = 1; - filename = resolve_about_path(filename, ref, path); - if (!filename) - goto done; - } - html("<div id='about'>"); if (!ctx.repo->about_filter) { // With no about-filter there is nothing to turn the readme @@ -182,11 +100,6 @@ void cgit_print_repo_readme(const char *path) html_include(filename); cgit_close_filter(ctx.repo->about_filter); } - html("</div>"); - if (free_filename) - free(filename); - -done: cgit_print_layout_end(); } |
