Skip to content

Commit c0fceeb

Browse files
ndosscheramsey
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 8ef9294 commit c0fceeb

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
@@ -1182,7 +1182,7 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so
11821182
int validate, recover, resolve_externals, keep_blanks, substitute_ent;
11831183
int resolved_path_len;
11841184
int old_error_reporting = 0;
1185-
char *directory=NULL, resolved_path[MAXPATHLEN];
1185+
char *directory=NULL, resolved_path[MAXPATHLEN + 1];
11861186

11871187
if (id != NULL) {
11881188
intern = Z_DOMOBJ_P(id);

ext/xmlreader/php_xmlreader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ PHP_METHOD(XMLReader, XML)
10171017
xmlreader_object *intern = NULL;
10181018
char *source, *uri = NULL, *encoding = NULL;
10191019
int resolved_path_len, ret = 0;
1020-
char *directory=NULL, resolved_path[MAXPATHLEN];
1020+
char *directory=NULL, resolved_path[MAXPATHLEN + 1];
10211021
xmlParserInputBufferPtr inputbfr;
10221022
xmlTextReaderPtr reader;
10231023

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)