- char *slash, *tmp, *colon, *ref;
-
- if (!ctx.repo->readme || !(*ctx.repo->readme))
- return;
-
- ref = NULL;
-
- /* Check if the readme is tracked in the git repo. */
- colon = strchr(ctx.repo->readme, ':');
- if (colon && strlen(colon) > 1) {
- *colon = '\0';
- /* If it starts with a colon, we want to use
- * the default branch */
- if (colon == ctx.repo->readme && ctx.repo->defbranch)
- ref = ctx.repo->defbranch;
- else
- ref = ctx.repo->readme;
- ctx.repo->readme = colon + 1;
- if (!(*ctx.repo->readme))
- return;
+ char *file, *base_dir, *full_path, *resolved_base = NULL, *resolved_full = NULL;
+ /* If a subpath is specified for the about page, make it relative
+ * to the directory containing the configured readme. */
+
+ file = xstrdup(filename);
+ base_dir = dirname(file);
+ if (!strcmp(base_dir, ".") || !strcmp(base_dir, "..")) {
+ if (!ref) {
+ free(file);
+ return NULL;
+ }
+ full_path = xstrdup(path);
+ } else
+ full_path = fmtalloc("%s/%s", base_dir, path);
+
+ if (!ref) {
+ resolved_base = realpath(base_dir, NULL);
+ resolved_full = realpath(full_path, NULL);
+ if (!resolved_base || !resolved_full || !starts_with(resolved_full, resolved_base)) {
+ free(full_path);
+ full_path = NULL;
+ }