File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -468,35 +468,35 @@ redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS,
468468PHP_REDIS_API char *
469469redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes TSRMLS_DC)
470470{
471- int offset = 0;
472- char *reply, c[2] ;
471+ int offset = 0, nbytes ;
472+ char *reply;
473473 size_t got;
474474
475475 if (-1 == bytes || -1 == redis_check_eof(redis_sock, 0 TSRMLS_CC)) {
476476 return NULL;
477477 }
478478
479+ nbytes = bytes + 2;
479480 /* Allocate memory for string */
480- reply = emalloc(bytes+1 );
481+ reply = emalloc(nbytes );
481482
482483 /* Consume bulk string */
483- while(offset < bytes ) {
484- got = php_stream_read(redis_sock->stream, reply + offset, bytes- offset);
485- if (got == 0) break;
484+ while (offset < nbytes ) {
485+ got = php_stream_read(redis_sock->stream, reply + offset, nbytes - offset);
486+ if (got == 0 && php_stream_eof(redis_sock->stream) ) break;
486487 offset += got;
487488 }
488489
489490 /* Protect against reading too few bytes */
490- if (offset < bytes ) {
491+ if (offset < nbytes ) {
491492 /* Error or EOF */
492493 zend_throw_exception(redis_exception_ce,
493494 "socket error on read socket", 0 TSRMLS_CC);
494495 efree(reply);
495496 return NULL;
496497 }
497498
498- /* Consume \r\n and null terminate reply string */
499- php_stream_read(redis_sock->stream, c, 2);
499+ /* Null terminate reply string */
500500 reply[bytes] = '\0';
501501
502502 return reply;
You can’t perform that action at this time.
0 commit comments