Skip to content

Commit 6c354f2

Browse files
committed
Adjust php_stream_read checks in mysqlnd
1 parent 2105358 commit 6c354f2

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

ext/mysqlnd/mysqlnd_net.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@ MYSQLND_METHOD(mysqlnd_net, network_read_ex)(MYSQLND_NET * const net, zend_uchar
8888
enum_func_status return_value = PASS;
8989
php_stream * net_stream = net->data->m.get_stream(net);
9090
size_t old_chunk_size = net_stream->chunk_size;
91-
size_t to_read = count, ret;
91+
size_t to_read = count;
9292
zend_uchar * p = buffer;
9393

9494
DBG_ENTER("mysqlnd_net::network_read_ex");
9595
DBG_INF_FMT("count="MYSQLND_SZ_T_SPEC, count);
9696

9797
net_stream->chunk_size = MIN(to_read, net->data->options.net_read_buffer_size);
9898
while (to_read) {
99-
if (!(ret = php_stream_read(net_stream, (char *) p, to_read))) {
99+
ssize_t ret = php_stream_read(net_stream, (char *) p, to_read);
100+
if (ret <= 0) {
100101
DBG_ERR_FMT("Error while reading header from socket");
101102
return_value = FAIL;
102103
break;
@@ -866,20 +867,24 @@ MYSQLND_METHOD(mysqlnd_net, consume_uneaten_data)(MYSQLND_NET * const net, enum
866867

867868
if (PHP_STREAM_OPTION_RETURN_ERR != was_blocked) {
868869
/* Do a read of 1 byte */
869-
int bytes_consumed;
870+
ssize_t bytes_consumed;
870871

871872
do {
872-
skipped_bytes += (bytes_consumed = php_stream_read(net_stream, tmp_buf, sizeof(tmp_buf)));
873+
bytes_consumed = php_stream_read(net_stream, tmp_buf, sizeof(tmp_buf));
874+
if (bytes_consumed <= 0) {
875+
break;
876+
}
877+
skipped_bytes += bytes_consumed;
873878
} while (bytes_consumed == sizeof(tmp_buf));
874879

875880
if (was_blocked) {
876881
net_stream->ops->set_option(net_stream, opt, 1, NULL);
877882
}
878883

879884
if (bytes_consumed) {
880-
DBG_ERR_FMT("Skipped %u bytes. Last command %s hasn't consumed all the output from the server",
885+
DBG_ERR_FMT("Skipped %zu bytes. Last command %s hasn't consumed all the output from the server",
881886
bytes_consumed, mysqlnd_command_to_text[net->last_command]);
882-
php_error_docref(NULL, E_WARNING, "Skipped %u bytes. Last command %s hasn't "
887+
php_error_docref(NULL, E_WARNING, "Skipped %zu bytes. Last command %s hasn't "
883888
"consumed all the output from the server",
884889
bytes_consumed, mysqlnd_command_to_text[net->last_command]);
885890
}

ext/mysqlnd/mysqlnd_vio.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ MYSQLND_METHOD(mysqlnd_vio, network_read)(MYSQLND_VIO * const vio, zend_uchar *
7979
{
8080
enum_func_status return_value = PASS;
8181
php_stream * net_stream = vio->data->m.get_stream(vio);
82-
size_t to_read = count, ret;
82+
size_t to_read = count;
8383
zend_uchar * p = buffer;
8484

8585
DBG_ENTER("mysqlnd_vio::network_read");
8686
DBG_INF_FMT("count="MYSQLND_SZ_T_SPEC, count);
8787

8888
while (to_read) {
89-
if (!(ret = php_stream_read(net_stream, (char *) p, to_read))) {
89+
ssize_t ret = php_stream_read(net_stream, (char *) p, to_read);
90+
if (ret <= 0) {
9091
DBG_ERR_FMT("Error while reading header from socket");
9192
return_value = FAIL;
9293
break;
@@ -451,10 +452,14 @@ MYSQLND_METHOD(mysqlnd_vio, consume_uneaten_data)(MYSQLND_VIO * const net, enum
451452

452453
if (PHP_STREAM_OPTION_RETURN_ERR != was_blocked) {
453454
/* Do a read of 1 byte */
454-
int bytes_consumed;
455+
ssize_t bytes_consumed;
455456

456457
do {
457-
skipped_bytes += (bytes_consumed = php_stream_read(net_stream, tmp_buf, sizeof(tmp_buf)));
458+
bytes_consumed = php_stream_read(net_stream, tmp_buf, sizeof(tmp_buf));
459+
if (bytes_consumed <= 0) {
460+
break;
461+
}
462+
skipped_bytes += bytes_consumed;
458463
} while (bytes_consumed == sizeof(tmp_buf));
459464

460465
if (was_blocked) {

0 commit comments

Comments
 (0)