Skip to content

Commit

Permalink
More conservative buffer overflow checking code for
Browse files Browse the repository at this point in the history
apr_filepath_merge(): fail immediately if the sum of
the rootpath and addpath lengths is too long, rather
than letting long strings pass through and checking
for overflow at multiple points throughout the merge
code.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@63495 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Brian Pane committed Jun 12, 2002
1 parent d548339 commit cb1b3f5
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions file_io/unix/filepath.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,7 @@ APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath,
* root, and at end, plus trailing
* null */
if (maxlen > APR_PATH_MAX) {
if (rootlen >= APR_PATH_MAX) {
return APR_ENAMETOOLONG;
}
maxlen = APR_PATH_MAX;
return APR_ENAMETOOLONG;
}
path = (char *)apr_palloc(p, maxlen);

Expand Down Expand Up @@ -223,8 +220,6 @@ APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath,
/* Always '/' terminate the given root path
*/
if (keptlen && path[keptlen - 1] != '/') {
if (keptlen + 1 >= maxlen)
return APR_ENAMETOOLONG;
path[keptlen++] = '/';
}
pathlen = keptlen;
Expand Down Expand Up @@ -271,9 +266,6 @@ APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath,

/* Otherwise append another backpath.
*/
if (pathlen + 3 >= maxlen ) {
return APR_ENAMETOOLONG;
}
memcpy(path + pathlen, "../", 3);
pathlen += 3;
}
Expand Down Expand Up @@ -304,9 +296,6 @@ APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath,
if (*next) {
seglen++;
}
if (pathlen + seglen >= maxlen) {
return APR_ENAMETOOLONG;
}
memcpy(path + pathlen, addpath, seglen);
pathlen += seglen;
}
Expand Down

0 comments on commit cb1b3f5

Please sign in to comment.