Skip to content

Commit

Permalink
Fix array overrun when appending slash to paths
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nielsdos authored and adoy committed Feb 13, 2023
1 parent 86d0d1b commit 0f2957f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ext/dom/document.c
Expand Up @@ -1182,7 +1182,7 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so
int validate, recover, resolve_externals, keep_blanks, substitute_ent;
int resolved_path_len;
int old_error_reporting = 0;
char *directory=NULL, resolved_path[MAXPATHLEN];
char *directory=NULL, resolved_path[MAXPATHLEN + 1];

if (id != NULL) {
intern = Z_DOMOBJ_P(id);
Expand Down
2 changes: 1 addition & 1 deletion ext/xmlreader/php_xmlreader.c
Expand Up @@ -1017,7 +1017,7 @@ PHP_METHOD(XMLReader, XML)
xmlreader_object *intern = NULL;
char *source, *uri = NULL, *encoding = NULL;
int resolved_path_len, ret = 0;
char *directory=NULL, resolved_path[MAXPATHLEN];
char *directory=NULL, resolved_path[MAXPATHLEN + 1];
xmlParserInputBufferPtr inputbfr;
xmlTextReaderPtr reader;

Expand Down
6 changes: 3 additions & 3 deletions main/fopen_wrappers.c
Expand Up @@ -129,10 +129,10 @@ PHPAPI ZEND_INI_MH(OnUpdateBaseDir)
*/
PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path)
{
char resolved_name[MAXPATHLEN];
char resolved_basedir[MAXPATHLEN];
char resolved_name[MAXPATHLEN + 1];
char resolved_basedir[MAXPATHLEN + 1];
char local_open_basedir[MAXPATHLEN];
char path_tmp[MAXPATHLEN];
char path_tmp[MAXPATHLEN + 1];
char *path_file;
size_t resolved_basedir_len;
size_t resolved_name_len;
Expand Down

0 comments on commit 0f2957f

Please sign in to comment.