diff options
author | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-04-04 16:21:52 +0200 |
---|---|---|
committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-04-04 16:26:08 +0200 |
commit | 31e80290a1a08a24780a0cbedd3a400fccd80a8b (patch) | |
tree | 3612d992ea393d64f9ea399c6163fceebd5233fc /src/mwindow.c | |
parent | bbb3723657cb595754099036ee080849b218f285 (diff) | |
download | libgit2-31e80290a1a08a24780a0cbedd3a400fccd80a8b.tar.gz |
mwindow: make sure the whole range is contained inside the same window
Looking through the open windows to check whether we can re-use an
open window should take into account whether both `offset` and `offset
+ extra` are contained within the same window. Failure to do so can
lead to invalid memory accesses. This closes #614.
While we're in the area remove an outdated assert.
Diffstat (limited to 'src/mwindow.c')
-rw-r--r-- | src/mwindow.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/mwindow.c b/src/mwindow.c index 39f6aeacc..f657d9d34 100644 --- a/src/mwindow.c +++ b/src/mwindow.c @@ -211,13 +211,15 @@ unsigned char *git_mwindow_open( git_mwindow_ctl *ctl = &GIT_GLOBAL->mem_ctl; git_mwindow *w = *cursor; - if (!w || !git_mwindow_contains(w, offset + extra)) { + if (!w || !(git_mwindow_contains(w, offset) && + git_mwindow_contains(w, offset + extra))) { if (w) { w->inuse_cnt--; } for (w = mwf->windows; w; w = w->next) { - if (git_mwindow_contains(w, offset + extra)) + if (git_mwindow_contains(w, offset) && + git_mwindow_contains(w, offset + extra)) break; } @@ -242,7 +244,6 @@ unsigned char *git_mwindow_open( } offset -= w->offset; - assert(git__is_sizet(offset)); if (left) *left = (unsigned int)(w->window_map.len - offset); |