aboutsummaryrefslogtreecommitdiffstats
path: root/cgit.h
diff options
context:
space:
mode:
authorGravatar John Keeping <john@keeping.me.uk>2013-04-02 03:03:34 (JST)
committerGravatar Jason A. Donenfeld <Jason@zx2c4.com>2013-04-08 22:59:46 (JST)
commitb1f17f168b91d709c0c0e62608de301a36f06da9 (patch)
tree9aff1fe903087cb5016ab2afdb32a7ca1cc139b2 /cgit.h
parent4b4a62d507adc61e20e75e2748301ef307a6c95f (diff)
downloadcgit-b1f17f168b91d709c0c0e62608de301a36f06da9.zip
cgit-b1f17f168b91d709c0c0e62608de301a36f06da9.tar.gz
Fix out-of-bounds memory accesses with virtual_root=""
The CGit configuration variable virtual_root is normalized so that it does not have a trailing '/' character, but it is allowed to be empty (the empty string and NULL have different meanings here) and there is code that is insufficiently cautious when checking if it ends in a '/': if (virtual_root[strlen(virtual_root) - 1] != '/') Clearly this check is redundant, but rather than simply removing it we get a slight efficiency improvement by switching the normalization so that the virtual_root variable always ends in '/'. Do this with a new "ensure_end" helper. Signed-off-by: John Keeping <john@keeping.me.uk>
Diffstat (limited to 'cgit.h')
-rw-r--r--cgit.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/cgit.h b/cgit.h
index 081f669..fc3fc6f 100644
--- a/cgit.h
+++ b/cgit.h
@@ -190,7 +190,7 @@ struct cgit_config {
190 char *script_name; 190 char *script_name;
191 char *section; 191 char *section;
192 char *repository_sort; 192 char *repository_sort;
193 char *virtual_root; 193 char *virtual_root; /* Always ends with '/'. */
194 char *strict_export; 194 char *strict_export;
195 int cache_size; 195 int cache_size;
196 int cache_dynamic_ttl; 196 int cache_dynamic_ttl;
@@ -300,6 +300,7 @@ extern int chk_positive(int result, char *msg);
300extern int chk_non_negative(int result, char *msg); 300extern int chk_non_negative(int result, char *msg);
301 301
302extern char *trim_end(const char *str, char c); 302extern char *trim_end(const char *str, char c);
303extern char *ensure_end(const char *str, char c);
303extern char *strlpart(char *txt, int maxlen); 304extern char *strlpart(char *txt, int maxlen);
304extern char *strrpart(char *txt, int maxlen); 305extern char *strrpart(char *txt, int maxlen);
305 306