Skip to content

Commit

Permalink
sapi/cgi: fix buffer limit on windows.
Browse files Browse the repository at this point in the history
MSDN recommends dropping the deprecated `read` in favor of `_read`.
Also, the buffer size limit is INT_MAX.

Close GH-14022
  • Loading branch information
devnexen committed May 1, 2024
1 parent 2dbe2d6 commit 7484394
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.2.20

- CGI:
. Fixed buffer limit on Windows, replacing read call usage by _read.
(David Carlier)

- DOM:
. Fix crashes when entity declaration is removed while still having entity
references. (nielsdos)
Expand Down
4 changes: 2 additions & 2 deletions main/fastcgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,9 @@ static inline ssize_t safe_read(fcgi_request *req, const void *buf, size_t count
tmp = count - n;

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

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

Expand Down
4 changes: 2 additions & 2 deletions sapi/cgi/cgi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ static size_t sapi_cgi_read_post(char *buffer, size_t count_bytes)
while (read_bytes < count_bytes) {
#ifdef PHP_WIN32
size_t diff = count_bytes - read_bytes;
unsigned int to_read = (diff > UINT_MAX) ? UINT_MAX : (unsigned int)diff;
unsigned int to_read = (diff > INT_MAX) ? INT_MAX : (unsigned int)diff;

tmp_read_bytes = read(STDIN_FILENO, buffer + read_bytes, to_read);
tmp_read_bytes = _read(STDIN_FILENO, buffer + read_bytes, to_read);
#else
tmp_read_bytes = read(STDIN_FILENO, buffer + read_bytes, count_bytes - read_bytes);
#endif
Expand Down

0 comments on commit 7484394

Please sign in to comment.