File tree Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ PHP NEWS
1919 . Fixed bug GH-16630 (UAF in lexer with encoding translation and heredocs).
2020 (nielsdos)
2121 . Fix is_zend_ptr() huge block comparison. (nielsdos)
22+ . Fixed potential OOB read in zend_dirname() on Windows. (cmb)
2223
2324- Curl:
2425 . Fixed bug GH-16802 (open_basedir bypass using curl extension). (nielsdos)
Original file line number Diff line number Diff line change @@ -2122,7 +2122,7 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
21222122 }
21232123
21242124 /* Strip trailing slashes */
2125- while (end >= path && IS_SLASH_P (end )) {
2125+ while (end >= path && IS_SLASH_P_EX (end , end == path )) {
21262126 end -- ;
21272127 }
21282128 if (end < path ) {
@@ -2133,7 +2133,7 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
21332133 }
21342134
21352135 /* Strip filename */
2136- while (end >= path && !IS_SLASH_P (end )) {
2136+ while (end >= path && !IS_SLASH_P_EX (end , end == path )) {
21372137 end -- ;
21382138 }
21392139 if (end < path ) {
@@ -2144,7 +2144,7 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
21442144 }
21452145
21462146 /* Strip slashes which came before the file name */
2147- while (end >= path && IS_SLASH_P (end )) {
2147+ while (end >= path && IS_SLASH_P_EX (end , end == path )) {
21482148 end -- ;
21492149 }
21502150 if (end < path ) {
Original file line number Diff line number Diff line change @@ -73,8 +73,11 @@ typedef unsigned short mode_t;
7373#define DEFAULT_SLASH '\\'
7474#define DEFAULT_DIR_SEPARATOR ';'
7575#define IS_SLASH (c ) ((c) == '/' || (c) == '\\')
76+ // IS_SLASH_P() may read the previous char on Windows, which may be OOB; use IS_SLASH_P_EX() instead
7677#define IS_SLASH_P (c ) (*(c) == '/' || \
7778 (*(c) == '\\' && !IsDBCSLeadByte(*(c-1))))
79+ #define IS_SLASH_P_EX (c , first_byte ) (*(c) == '/' || \
80+ (*(c) == '\\' && ((first_byte) || !IsDBCSLeadByte(*(c-1)))))
7881
7982/* COPY_WHEN_ABSOLUTE is 2 under Win32 because by chance both regular absolute paths
8083 in the file system and UNC paths need copying of two characters */
@@ -108,7 +111,9 @@ typedef unsigned short mode_t;
108111#endif
109112
110113#define IS_SLASH (c ) ((c) == '/')
114+ // IS_SLASH_P() may read the previous char on Windows, which may be OOB; use IS_SLASH_P_EX() instead
111115#define IS_SLASH_P (c ) (*(c) == '/')
116+ #define IS_SLASH_P_EX (c , first_byte ) IS_SLASH_P(c)
112117
113118#endif
114119
You can’t perform that action at this time.
0 commit comments