diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/cache.c | 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rw-r--r-- | source/cgit.c | 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rw-r--r-- | source/cgit.h | 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 files changed, 31 insertions, 1 deletion
diff --git a/source/cache.c b/source/cache.c index e916728..c6d0427 100644 --- a/source/cache.c +++ b/source/cache.c @@ -75,6 +75,15 @@ static int open_slot(struct cache_slot *slot) return 0; } +/* A key longer than the buffer above can never be read back, so a slot keyed + * on one would never match and every such request would regenerate its page + * while still writing a slot nothing can use. Those requests skip the cache + * instead. */ +static int key_fits_slot(const char *key) +{ + return strlen(key) + 1 <= CACHE_BUFSIZE; +} + /* Close the active cache slot */ static int close_slot(struct cache_slot *slot) { @@ -379,6 +388,12 @@ int cache_process(int size, const char *path, const char *key, int ttl, } if (!key) key = ""; + if (!key_fits_slot(key)) { + cache_log("[cgit] Cache key too long for a slot, caching is " + "disabled for this request\n"); + fn(); + return 0; + } hash = cache_hash_str(key) % size; strbuf_addstr(&filename, path); strbuf_ensure_end(&filename, '/'); diff --git a/source/cgit.c b/source/cgit.c index 2ecfb4f..7cce3d3 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -360,7 +360,14 @@ static void querystring_cb(const char *name, const char *value) } else if (!strcmp(name, "qt")) { ctx.qry.grep = xstrdup(value); } else if (!strcmp(name, "q")) { - ctx.qry.search = xstrdup(value); + /* A query is matched against every repository, ref or commit + * the page lists, so bound what one request can ask to be + * compared. Nothing legible reaches this length, and the value + * also lands in the cache key. */ + if (strlen(value) > CGIT_MAX_SEARCH_LEN) + ctx.qry.search = xstrndup(value, CGIT_MAX_SEARCH_LEN); + else + ctx.qry.search = xstrdup(value); } else if (!strcmp(name, "h")) { ctx.qry.head = xstrdup(value); ctx.qry.has_symref = 1; diff --git a/source/cgit.h b/source/cgit.h index 8f10068..b05876e 100644 --- a/source/cgit.h +++ b/source/cgit.h @@ -55,6 +55,14 @@ #define BIT(x) (1U << (x)) +/* + * Longest search string a request may supply. The filter bar matches its + * query against every item a page lists, so this bounds the work one request + * can ask for. It is not a configuration knob, in the same way as the ofs + * ceiling in querystring_cb. + */ +#define CGIT_MAX_SEARCH_LEN 512 + typedef void (*configfn)(const char *name, const char *value); typedef void (*filepair_fn)(struct diff_filepair *pair); typedef void (*linediff_fn)(char *line, int len); |
