Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions ext/mysqlnd/mysqlnd_ps_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,24 @@ mysqlnd_stmt_execute_store_params(MYSQLND_STMT * s, zend_uchar **buf, zend_uchar
Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > LONG_MAX
*/
if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_LONG) {
zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv;
/*
Bug #66124.
Copy a new local zval, convert to double on it's own instead of changing copies[i].
Previous version of declaration is commented
*/
// zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv;
zval *tmp_data;
MAKE_STD_ZVAL(tmp_data);
*tmp_data = (copies && copies[i])? *copies[i]: *(stmt->param_bind[i].zv);
Z_SET_REFCOUNT_P(tmp_data, 1);
zval_copy_ctor(tmp_data);

convert_to_double_ex(&tmp_data);

if (Z_DVAL_P(tmp_data) > LONG_MAX || Z_DVAL_P(tmp_data) < LONG_MIN) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessing DVAL after casting to long? That can't be right...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right nikic, I put my focus on my problem but forgetting to get everything right, sorry for that.
but the convert to double issue really caused my problem, maybe I should get another temporary zval to make old code working as well

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Die Zustellung an folgende Empfänger oder Gruppen verzögert sich:

p.bandow@justepic.infomailto:p.bandow@justepic.info

Betreff: Re: [php-src] Fixed bug #66124 (#532)

Diese Nachricht wurde noch nicht zugestellt. Es wird weiterhin versucht, die Nachricht zuzustellen.

Der Server wird noch 2 Tage, 22 Stunden und 58 Minuten versuchen, die Nachricht zuzustellen. Sie erhalten eine Benachrichtigung, falls die Nachricht bis dahin nicht übermittelt werden konnte.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Die Zustellung an folgende Empfänger oder Gruppen verzögert sich:

p.bandow@justepic.infomailto:p.bandow@justepic.info

Betreff: Re: [php-src] Fixed bug #66124 (#532)

Diese Nachricht wurde noch nicht zugestellt. Es wird weiterhin versucht, die Nachricht zuzustellen.

Der Server wird noch 2 Tage, 22 Stunden und 57 Minuten versuchen, die Nachricht zuzustellen. Sie erhalten eine Benachrichtigung, falls die Nachricht bis dahin nicht übermittelt werden konnte.

stmt->send_types_to_server = resend_types_next_time = 1;
}
zval_dtor(tmp_data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You created the zval with MAKE_STD_ZVAL but destroy with zval_dtor, that will leak the container. You're probably looking for something like this:

zval tmp_data;
ZVAL_ZVAL(&tmp_data, (copies && copies[i]) ? copies[i]: stmt->param_bind[i].zv, 1, 0);
convert_to_double(&tmp_data);
// ...
zval_dtor(&tmp_data);

That's the semi-standard approach to performing a cast without touching the zval. The ZVAL_ZVAL is the same as ZVAL_COPY_VALUE+zval_copy_ctor.

}
}
}
Expand Down Expand Up @@ -630,11 +643,22 @@ mysqlnd_stmt_execute_store_params(MYSQLND_STMT * s, zend_uchar **buf, zend_uchar
Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > LONG_MAX
*/
if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_LONG) {
zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv;
/*
Bug #66124.
Copy a new local zval, convert to double on it's own instead of changing copies[i].
Previous version of declaration is commented
*/
// zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv;

zval *tmp_data;
MAKE_STD_ZVAL(tmp_data);
*tmp_data = (copies && copies[i])? *copies[i]: *(stmt->param_bind[i].zv);
Z_SET_REFCOUNT_P(tmp_data, 1);
zval_copy_ctor(tmp_data);

convert_to_double_ex(&tmp_data);
if (Z_DVAL_P(tmp_data) > LONG_MAX || Z_DVAL_P(tmp_data) < LONG_MIN) {
convert_to_string_ex(&tmp_data);
convert_to_string_ex(&(copies[i]));
current_type = MYSQL_TYPE_VAR_STRING;
/*
don't change stmt->param_bind[i].type to MYSQL_TYPE_VAR_STRING
Expand All @@ -643,8 +667,11 @@ mysqlnd_stmt_execute_store_params(MYSQLND_STMT * s, zend_uchar **buf, zend_uchar
We want to preserve the original bind type given by the user. Thus, we do these hacks.
*/
} else {
convert_to_long_ex(&tmp_data);
convert_to_long_ex(&(copies[i]));
}

zval_dtor(tmp_data);

}
}
int2store(*p, current_type);
Expand Down