diff options
author | John Keeping | 2013-04-01 19:03:34 +0100 |
---|---|---|
committer | Jason A. Donenfeld | 2013-04-08 15:59:46 +0200 |
commit | b1f17f168b91d709c0c0e62608de301a36f06da9 (patch) | |
tree | 9aff1fe903087cb5016ab2afdb32a7ca1cc139b2 /cgit.c | |
parent | 4b4a62d507adc61e20e75e2748301ef307a6c95f (diff) | |
download | cgit-b1f17f168b91d709c0c0e62608de301a36f06da9.tar.gz cgit-b1f17f168b91d709c0c0e62608de301a36f06da9.tar.bz2 cgit-b1f17f168b91d709c0c0e62608de301a36f06da9.zip |
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.c')
-rw-r--r-- | cgit.c | 11 |
1 files changed, 3 insertions, 8 deletions
@@ -155,9 +155,7 @@ static void config_cb(const char *name, const char *value) | |||
155 | else if (!strcmp(name, "strict-export")) | 155 | else if (!strcmp(name, "strict-export")) |
156 | ctx.cfg.strict_export = xstrdup(value); | 156 | ctx.cfg.strict_export = xstrdup(value); |
157 | else if (!strcmp(name, "virtual-root")) { | 157 | else if (!strcmp(name, "virtual-root")) { |
158 | ctx.cfg.virtual_root = trim_end(value, '/'); | 158 | ctx.cfg.virtual_root = ensure_end(value, '/'); |
159 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) | ||
160 | ctx.cfg.virtual_root = ""; | ||
161 | } else if (!strcmp(name, "nocache")) | 159 | } else if (!strcmp(name, "nocache")) |
162 | ctx.cfg.nocache = atoi(value); | 160 | ctx.cfg.nocache = atoi(value); |
163 | else if (!strcmp(name, "noplainemail")) | 161 | else if (!strcmp(name, "noplainemail")) |
@@ -833,11 +831,8 @@ int main(int argc, const char **argv) | |||
833 | * that virtual-root equals SCRIPT_NAME, minus any possibly | 831 | * that virtual-root equals SCRIPT_NAME, minus any possibly |
834 | * trailing slashes. | 832 | * trailing slashes. |
835 | */ | 833 | */ |
836 | if (!ctx.cfg.virtual_root && ctx.cfg.script_name) { | 834 | if (!ctx.cfg.virtual_root && ctx.cfg.script_name) |
837 | ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/'); | 835 | ctx.cfg.virtual_root = ensure_end(ctx.cfg.script_name, '/'); |
838 | if (!ctx.cfg.virtual_root) | ||
839 | ctx.cfg.virtual_root = ""; | ||
840 | } | ||
841 | 836 | ||
842 | /* If no url parameter is specified on the querystring, lets | 837 | /* If no url parameter is specified on the querystring, lets |
843 | * use PATH_INFO as url. This allows cgit to work with virtual | 838 | * use PATH_INFO as url. This allows cgit to work with virtual |