From: Aki Tuomi Date: Mon, 20 Nov 2017 14:01:25 +0000 (+0200) Subject: lib: path-util - Allocate more space earlier X-Git-Tag: 2.3.0.rc1~422 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=569b5022db8e39a7f237cae08feb5412dadb2e65;p=thirdparty%2Fdovecot%2Fcore.git lib: path-util - Allocate more space earlier Fixes assert crash in path_normalize when termination needs to happen at asize boundary. Panic: file path-util.c: line 93 (path_normalize): assertion failed: ((size_t)((npath_pos - npath) + 1) < asize) --- diff --git a/src/lib/path-util.c b/src/lib/path-util.c index ac192b2769..e3e74d77ce 100644 --- a/src/lib/path-util.c +++ b/src/lib/path-util.c @@ -87,13 +87,6 @@ static int path_normalize(const char *path, bool resolve_links, for (; *(npath_pos-1) != '/'; npath_pos--); } } else { - /* make sure npath now ends in slash */ - if (*(npath_pos-1) != '/') { - i_assert(npath_pos >= npath); - i_assert((size_t)((npath_pos - npath) + 1) < asize); - *(npath_pos++) = '/'; - } - /* allocate space if necessary */ if ((npath_pos + seglen + 1) >= (npath + asize)) { ptrdiff_t npath_offset = npath_pos - npath; @@ -102,6 +95,13 @@ static int path_normalize(const char *path, bool resolve_links, npath_pos = npath + npath_offset; } + /* make sure npath now ends in slash */ + if (*(npath_pos-1) != '/') { + i_assert(npath_pos >= npath); + i_assert((size_t)((npath_pos - npath) + 1) < asize); + *(npath_pos++) = '/'; + } + /* copy segment to normalized path */ i_assert(npath_pos >= npath); i_assert((size_t)((npath_pos - npath) + seglen) < asize);