From 969e9554a31385b2d2c09695dab984d585dc2693 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Mon, 21 Sep 2026 06:42:39 -1000 Subject: Harden the request path, scan and error recovery --- source/shared.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'source/shared.h') diff --git a/source/shared.h b/source/shared.h index b9f6ecf..9e39389 100644 --- a/source/shared.h +++ b/source/shared.h @@ -32,13 +32,17 @@ extern int cgit_die_unless_non_negative(int result, const char *msg); extern struct cgit_repo *cgit_add_repo(const char *url); extern struct cgit_repo *cgit_get_repoinfo(const char *url); -// Export the CGIT_REPO_* variables that filters and hooks read. +/* + * Export the CGIT_REPO_* variables that filters and hooks read. + */ extern void cgit_prepare_repo_env(struct cgit_repo *repo); extern void cgit_free_reflist_inner(struct reflist *list); -// Matches git's reference iteration callback, and appends each ref it is -// given to the struct reflist passed as cb_data. +/* + * Matches git's reference iteration callback, and appends each ref it is given + * to the struct reflist passed as cb_data. + */ extern int cgit_refs_cb(const struct reference *ref, void *cb_data); extern void cgit_free_commitinfo(struct commitinfo *info); @@ -60,11 +64,15 @@ extern void cgit_diff_tree(const struct object_id *old_oid, const struct object_ filepair_fn fn, const char *prefix, int ignorews); extern void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix); -// Accept only the date formats cgit documents, leaving mode unchanged for -// anything else. +/* + * Accept only the date formats cgit documents, leaving mode unchanged for + * anything else. + */ extern void cgit_parse_date_format(const char *format, struct date_mode *mode); -// Copy str without its trailing runs of c, returning NULL if nothing is left. +/* + * Copy str without its trailing runs of c, returning NULL if nothing is left. + */ extern char *cgit_trim_end(const char *str, char c); extern char *cgit_ensure_end(const char *str, char c); extern void strbuf_ensure_end(struct strbuf *sb, char c); @@ -84,4 +92,10 @@ extern char *cgit_expand_macros(const char *text); extern char *cgit_get_mimetype_for_filename(const char *filename); +/* + * Whether a revision from the request is a hex object id or a possible ref + * name, the only forms cgit hands to git. + */ +extern int cgit_valid_rev(const char *rev); + #endif // CGIT_SHARED_H -- cgit v2.8.0