Skip to content

Commit

Permalink
lib: path-util - Allocate more space earlier
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
cmouse authored and stephanbosch committed Nov 20, 2017
1 parent 82e7761 commit 569b502
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/lib/path-util.c
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 569b502

Please sign in to comment.