Skip to content

Commit ec10b28

Browse files
nielsdossmalyshev
authored andcommitted
Fix array overrun when appending slash to paths
Fix it by extending the array sizes by one character. As the input is limited to the maximum path length, there will always be place to append the slash. As the php_check_specific_open_basedir() simply uses the strings to compare against each other, no new failures related to too long paths are introduced. We'll let the DOM and XML case handle a potentially too long path in the library code.
1 parent af2ddc6 commit ec10b28

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

ext/dom/document.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so
11741174
int validate, recover, resolve_externals, keep_blanks, substitute_ent;
11751175
int resolved_path_len;
11761176
int old_error_reporting = 0;
1177-
char *directory=NULL, resolved_path[MAXPATHLEN];
1177+
char *directory=NULL, resolved_path[MAXPATHLEN + 1];
11781178

11791179
if (id != NULL) {
11801180
intern = Z_DOMOBJ_P(id);

ext/xmlreader/php_xmlreader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ PHP_METHOD(XMLReader, XML)
10241024
xmlreader_object *intern = NULL;
10251025
char *source, *uri = NULL, *encoding = NULL;
10261026
int resolved_path_len, ret = 0;
1027-
char *directory=NULL, resolved_path[MAXPATHLEN];
1027+
char *directory=NULL, resolved_path[MAXPATHLEN + 1];
10281028
xmlParserInputBufferPtr inputbfr;
10291029
xmlTextReaderPtr reader;
10301030

main/fopen_wrappers.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ PHPAPI ZEND_INI_MH(OnUpdateBaseDir)
129129
*/
130130
PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path)
131131
{
132-
char resolved_name[MAXPATHLEN];
133-
char resolved_basedir[MAXPATHLEN];
132+
char resolved_name[MAXPATHLEN + 1];
133+
char resolved_basedir[MAXPATHLEN + 1];
134134
char local_open_basedir[MAXPATHLEN];
135-
char path_tmp[MAXPATHLEN];
135+
char path_tmp[MAXPATHLEN + 1];
136136
char *path_file;
137137
size_t resolved_basedir_len;
138138
size_t resolved_name_len;

0 commit comments

Comments
 (0)