File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -2196,7 +2196,7 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
21962196 }
21972197
21982198 /* Strip trailing slashes */
2199- while (end >= path && IS_SLASH_P (end )) {
2199+ while (end >= path && IS_SLASH_P_EX (end , end == path )) {
22002200 end -- ;
22012201 }
22022202 if (end < path ) {
@@ -2207,7 +2207,7 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
22072207 }
22082208
22092209 /* Strip filename */
2210- while (end >= path && !IS_SLASH_P (end )) {
2210+ while (end >= path && !IS_SLASH_P_EX (end , end == path )) {
22112211 end -- ;
22122212 }
22132213 if (end < path ) {
@@ -2218,7 +2218,7 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
22182218 }
22192219
22202220 /* Strip slashes which came before the file name */
2221- while (end >= path && IS_SLASH_P (end )) {
2221+ while (end >= path && IS_SLASH_P_EX (end , end == path )) {
22222222 end -- ;
22232223 }
22242224 if (end < path ) {
Original file line number Diff line number Diff line change @@ -75,8 +75,11 @@ typedef unsigned short mode_t;
7575#define DEFAULT_SLASH '\\'
7676#define DEFAULT_DIR_SEPARATOR ';'
7777#define IS_SLASH (c ) ((c) == '/' || (c) == '\\')
78+ // IS_SLASH_P() may read the previous char on Windows, which may be OOB; use IS_SLASH_P_EX() instead
7879#define IS_SLASH_P (c ) (*(c) == '/' || \
7980 (*(c) == '\\' && !IsDBCSLeadByte(*(c-1))))
81+ #define IS_SLASH_P_EX (c , first_byte ) (*(c) == '/' || \
82+ (*(c) == '\\' && ((first_byte) || !IsDBCSLeadByte(*(c-1)))))
8083
8184/* COPY_WHEN_ABSOLUTE is 2 under Win32 because by chance both regular absolute paths
8285 in the file system and UNC paths need copying of two characters */
@@ -110,7 +113,9 @@ typedef unsigned short mode_t;
110113#endif
111114
112115#define IS_SLASH (c ) ((c) == '/')
116+ // IS_SLASH_P() may read the previous char on Windows, which may be OOB; use IS_SLASH_P_EX() instead
113117#define IS_SLASH_P (c ) (*(c) == '/')
118+ #define IS_SLASH_P_EX (c , first_byte ) IS_SLASH_P(c)
114119
115120#endif
116121
You can’t perform that action at this time.
0 commit comments