mirror of
https://github.com/php/php-src.git
synced 2024-09-22 18:37:25 +00:00
fixed readfile() fd-leak.
guys, always remember that every function that *generates output* could cause a bailout if ignore_user_abort is set to false (and the user _aborts_ the connection). in this case a longjump will be performed and our function (in this case readfile) will have no chance to clean-up. having said that it's a good idea to register all opened files using REGISTER_RESOURCE - that way the engine will make sure they get closed on request end.
This commit is contained in:
parent
27afea5c6d
commit
6b84fb1cde
@ -1395,6 +1395,7 @@ PHP_FUNCTION(readfile)
|
||||
int size=0;
|
||||
int use_include_path=0;
|
||||
int issock=0, socketd=0;
|
||||
int rsrc_id;
|
||||
|
||||
/* check args */
|
||||
switch (ARG_COUNT(ht)) {
|
||||
@ -1429,14 +1430,21 @@ PHP_FUNCTION(readfile)
|
||||
}
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (issock) {
|
||||
int *sock=emalloc(sizeof(int));
|
||||
*sock = socketd;
|
||||
rsrc_id = ZEND_REGISTER_RESOURCE(NULL,sock,php_file_le_socket());
|
||||
} else {
|
||||
rsrc_id = ZEND_REGISTER_RESOURCE(NULL,fp,php_file_le_fopen());
|
||||
}
|
||||
|
||||
if (php_header()) {
|
||||
size = php_passthru_fd(socketd, fp, issock);
|
||||
}
|
||||
if (issock) {
|
||||
SOCK_FCLOSE(socketd);
|
||||
} else {
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
zend_list_delete(rsrc_id);
|
||||
|
||||
RETURN_LONG(size);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user