Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fdd3839

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix potential OOB read in zend_dirname() on Windows
2 parents 1668a16 + ba7dee5 commit fdd3839

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

‎Zend/zend_compile.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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) {

‎Zend/zend_virtual_cwd.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /