File tree 3 files changed +9
-3
lines changed
3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ PHP NEWS
19
19
. Fixed bug GH-16630 (UAF in lexer with encoding translation and heredocs).
20
20
(nielsdos)
21
21
. Fix is_zend_ptr() huge block comparison. (nielsdos)
22
+ . Fixed potential OOB read in zend_dirname() on Windows. (cmb)
22
23
23
24
- Curl:
24
25
. 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)
2122
2122
}
2123
2123
2124
2124
/* Strip trailing slashes */
2125
- while (end >= path && IS_SLASH_P (end )) {
2125
+ while (end >= path && IS_SLASH_P_EX (end , end == path )) {
2126
2126
end -- ;
2127
2127
}
2128
2128
if (end < path ) {
@@ -2133,7 +2133,7 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
2133
2133
}
2134
2134
2135
2135
/* Strip filename */
2136
- while (end >= path && !IS_SLASH_P (end )) {
2136
+ while (end >= path && !IS_SLASH_P_EX (end , end == path )) {
2137
2137
end -- ;
2138
2138
}
2139
2139
if (end < path ) {
@@ -2144,7 +2144,7 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
2144
2144
}
2145
2145
2146
2146
/* 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 )) {
2148
2148
end -- ;
2149
2149
}
2150
2150
if (end < path ) {
Original file line number Diff line number Diff line change @@ -73,8 +73,11 @@ typedef unsigned short mode_t;
73
73
#define DEFAULT_SLASH '\\'
74
74
#define DEFAULT_DIR_SEPARATOR ';'
75
75
#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
76
77
#define IS_SLASH_P (c ) (*(c) == '/' || \
77
78
(*(c) == '\\' && !IsDBCSLeadByte(*(c-1))))
79
+ #define IS_SLASH_P_EX (c , first_byte ) (*(c) == '/' || \
80
+ (*(c) == '\\' && ((first_byte) || !IsDBCSLeadByte(*(c-1)))))
78
81
79
82
/* COPY_WHEN_ABSOLUTE is 2 under Win32 because by chance both regular absolute paths
80
83
in the file system and UNC paths need copying of two characters */
@@ -108,7 +111,9 @@ typedef unsigned short mode_t;
108
111
#endif
109
112
110
113
#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
111
115
#define IS_SLASH_P (c ) (*(c) == '/')
116
+ #define IS_SLASH_P_EX (c , first_byte ) IS_SLASH_P(c)
112
117
113
118
#endif
114
119
You can’t perform that action at this time.
0 commit comments