From: Ulf Wendel Date: Fri, 11 Sep 2009 12:16:56 +0000 (+0000) Subject: Fixing a crash which must have existed since PHP 5.0. At least the crash can be repro... X-Git-Tag: php-5.4.0alpha1~191^2~2666 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9af451ff4948bf3561716eeca670d345b6bc235b;p=php Fixing a crash which must have existed since PHP 5.0. At least the crash can be reproduced with PHP 5.0.6. The crash happens only when using the MySQL Client Library (libmysql) - it does not happen when using mysqlnd. --- diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 93f5aaad13..f69f6e7634 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -409,7 +409,7 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc, bind[ofs].buffer = stmt->result.buf[ofs].val; bind[ofs].is_null = &stmt->result.is_null[ofs]; bind[ofs].buffer_length = stmt->result.buf[ofs].buflen; - bind[ofs].length = &stmt->result.buf[ofs].buflen; + bind[ofs].length = &stmt->result.buf[ofs].output_len; break; } default: @@ -955,7 +955,7 @@ void mysqli_stmt_fetch_libmysql(INTERNAL_FUNCTION_PARAMETERS) } else #endif { - copy_len = stmt->result.buf[i].buflen; + copy_len = stmt->result.buf[i].output_len; } if (!IS_BINARY_DATA(fields[i])) { ZVAL_UTF8_STRINGL(stmt->result.vars[i], stmt->result.buf[i].val, diff --git a/ext/mysqli/php_mysqli_structs.h b/ext/mysqli/php_mysqli_structs.h index 3367010fa7..0865430067 100644 --- a/ext/mysqli/php_mysqli_structs.h +++ b/ext/mysqli/php_mysqli_structs.h @@ -82,10 +82,10 @@ typedef struct { UErrorCode status; /* error code */ } MYSQLI_STRING; - typedef struct { - ulong buflen; char *val; + ulong buflen; + ulong output_len; ulong type; } VAR_BUFFER; diff --git a/ext/mysqli/tests/005.phpt b/ext/mysqli/tests/005.phpt index 69e04c7a60..563b10359d 100644 --- a/ext/mysqli/tests/005.phpt +++ b/ext/mysqli/tests/005.phpt @@ -32,6 +32,9 @@ require_once('skipifconnectfailure.inc'); var_dump($test); + /* this will crash with libmysql from PHP 5.0.6 (or earlier) to 5.3.0 */ + mysqli_fetch($stmt); + mysqli_stmt_close($stmt); mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch"); mysqli_close($link);