Skip to content

Commit 7484394

Browse files
committed
sapi/cgi: fix buffer limit on windows.
MSDN recommends dropping the deprecated `read` in favor of `_read`. Also, the buffer size limit is INT_MAX. Close GH-14022
1 parent 2dbe2d6 commit 7484394

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.2.20
44

5+
- CGI:
6+
. Fixed buffer limit on Windows, replacing read call usage by _read.
7+
(David Carlier)
8+
59
- DOM:
610
. Fix crashes when entity declaration is removed while still having entity
711
references. (nielsdos)

main/fastcgi.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -965,9 +965,9 @@ static inline ssize_t safe_read(fcgi_request *req, const void *buf, size_t count
965965
tmp = count - n;
966966

967967
if (!req->tcp) {
968-
unsigned int in_len = tmp > UINT_MAX ? UINT_MAX : (unsigned int)tmp;
968+
unsigned int in_len = tmp > INT_MAX ? INT_MAX : (unsigned int)tmp;
969969

970-
ret = read(req->fd, ((char*)buf)+n, in_len);
970+
ret = _read(req->fd, ((char*)buf)+n, in_len);
971971
} else {
972972
int in_len = tmp > INT_MAX ? INT_MAX : (int)tmp;
973973

sapi/cgi/cgi_main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,9 @@ static size_t sapi_cgi_read_post(char *buffer, size_t count_bytes)
486486
while (read_bytes < count_bytes) {
487487
#ifdef PHP_WIN32
488488
size_t diff = count_bytes - read_bytes;
489-
unsigned int to_read = (diff > UINT_MAX) ? UINT_MAX : (unsigned int)diff;
489+
unsigned int to_read = (diff > INT_MAX) ? INT_MAX : (unsigned int)diff;
490490

491-
tmp_read_bytes = read(STDIN_FILENO, buffer + read_bytes, to_read);
491+
tmp_read_bytes = _read(STDIN_FILENO, buffer + read_bytes, to_read);
492492
#else
493493
tmp_read_bytes = read(STDIN_FILENO, buffer + read_bytes, count_bytes - read_bytes);
494494
#endif

0 commit comments

Comments
 (0)