]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: path-util - Allocate more space earlier
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 20 Nov 2017 14:01:25 +0000 (16:01 +0200)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Mon, 20 Nov 2017 19:37:54 +0000 (20:37 +0100)
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)

src/lib/path-util.c

index ac192b27695944ae09dab49c44d1e353c73dd21b..e3e74d77cefbcc4b3d765fbf90ccb638dfc4ec69 100644 (file)
@@ -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);