25
25
26
26
ZEND_DLIMPORT int isatty (int fd );
27
27
28
- static size_t zend_stream_stdio_reader (void * handle , char * buf , size_t len ) /* {{{ */
28
+ static ssize_t zend_stream_stdio_reader (void * handle , char * buf , size_t len ) /* {{{ */
29
29
{
30
30
return fread (buf , 1 , len , (FILE * )handle );
31
31
} /* }}} */
@@ -95,7 +95,7 @@ static int zend_stream_getc(zend_file_handle *file_handle) /* {{{ */
95
95
return EOF ;
96
96
} /* }}} */
97
97
98
- static size_t zend_stream_read (zend_file_handle * file_handle , char * buf , size_t len ) /* {{{ */
98
+ static ssize_t zend_stream_read (zend_file_handle * file_handle , char * buf , size_t len ) /* {{{ */
99
99
{
100
100
if (file_handle -> handle .stream .isatty ) {
101
101
int c = '*' ;
@@ -148,10 +148,18 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
148
148
}
149
149
150
150
if (size ) {
151
- file_handle -> buf = * buf = safe_emalloc (1 , size , ZEND_MMAP_AHEAD );
152
- file_handle -> len = zend_stream_read (file_handle , * buf , size );
151
+ ssize_t read ;
152
+ * buf = safe_emalloc (1 , size , ZEND_MMAP_AHEAD );
153
+ read = zend_stream_read (file_handle , * buf , size );
154
+ if (read < 0 ) {
155
+ efree (* buf );
156
+ return FAILURE ;
157
+ }
158
+ file_handle -> buf = * buf ;
159
+ file_handle -> len = read ;
153
160
} else {
154
- size_t read , remain = 4 * 1024 ;
161
+ size_t remain = 4 * 1024 ;
162
+ ssize_t read ;
155
163
* buf = emalloc (remain );
156
164
size = 0 ;
157
165
@@ -164,6 +172,11 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
164
172
remain = size ;
165
173
}
166
174
}
175
+ if (read < 0 ) {
176
+ efree (* buf );
177
+ return FAILURE ;
178
+ }
179
+
167
180
file_handle -> len = size ;
168
181
if (size && remain < ZEND_MMAP_AHEAD ) {
169
182
* buf = safe_erealloc (* buf , size , 1 , ZEND_MMAP_AHEAD );
0 commit comments