Commit 4797ea0
Nisha Gopalakrishnan
BUG#17512527: LIST HANDLING INCORRECT IN MYSQL_PRUNE_STMT_LIST()
Analysis:
---------
Invalid memory access maybe observed when using prepared statements if:
a) The mysql client connection is lost after statement preparation
is complete and
b) There is at least one statement which is in initialized state but
not prepared yet.
When the client detects a closed connection, it calls end_server()
to shutdown the connection. As part of the clean up, the
mysql_prune_stmt_list() removes the statements which has transitioned
beyond the initialized state and retains only the statements which
are in a initialized state. During this processing, the initialized
statements are moved from 'mysql->stmts' to a temporary 'pruned_list'.
When moving the first 'INIT_DONE' element to the pruned_list,
'element->next' is set to NULL. Hence the rest of the list is never
traversed and the statements which have transitioned beyond the
initialized state are never invalidated.
When the mysql_stmt_close() is called for the statement which is not
invalidated; the statements list is updated in order to remove the
statement. This would end up accessing freed memory(freed by the
mysql_stmt_close() for a previous statement in the list).
Fix:
---
mysql_prune_stmt_list() called list_add() incorrectly to create a
temporary list. The use case of list_add() is to add a single
element to the front of the doubly linked list.
mysql_prune_stmt_list() called list_add() by passing an entire
list as the 'element'.
mysql_prune_stmt_list() now uses list_delete() to remove the
statement which has transitioned beyond the initialized phase.
Thus the statement list would contain only elements where the
the state of the statement is initialized.
Note: Run the test with valgrind-mysqltest and leak-check=full
option to see the invalid memory access.1 parent f6f0d51 commit 4797ea0
2 files changed
Lines changed: 55 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
3985 | 3985 | | |
3986 | 3986 | | |
3987 | 3987 | | |
3988 | | - | |
3989 | | - | |
| 3988 | + | |
3990 | 3989 | | |
3991 | | - | |
| 3990 | + | |
3992 | 3991 | | |
3993 | | - | |
| 3992 | + | |
| 3993 | + | |
| 3994 | + | |
| 3995 | + | |
| 3996 | + | |
3994 | 3997 | | |
3995 | 3998 | | |
3996 | 3999 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
19353 | 19353 | | |
19354 | 19354 | | |
19355 | 19355 | | |
| 19356 | + | |
| 19357 | + | |
| 19358 | + | |
| 19359 | + | |
| 19360 | + | |
| 19361 | + | |
| 19362 | + | |
| 19363 | + | |
| 19364 | + | |
| 19365 | + | |
| 19366 | + | |
| 19367 | + | |
| 19368 | + | |
| 19369 | + | |
| 19370 | + | |
| 19371 | + | |
| 19372 | + | |
| 19373 | + | |
| 19374 | + | |
| 19375 | + | |
| 19376 | + | |
| 19377 | + | |
| 19378 | + | |
| 19379 | + | |
| 19380 | + | |
| 19381 | + | |
| 19382 | + | |
| 19383 | + | |
| 19384 | + | |
| 19385 | + | |
| 19386 | + | |
| 19387 | + | |
| 19388 | + | |
| 19389 | + | |
| 19390 | + | |
| 19391 | + | |
| 19392 | + | |
| 19393 | + | |
| 19394 | + | |
| 19395 | + | |
| 19396 | + | |
| 19397 | + | |
| 19398 | + | |
| 19399 | + | |
| 19400 | + | |
19356 | 19401 | | |
19357 | 19402 | | |
19358 | 19403 | | |
| |||
19627 | 19672 | | |
19628 | 19673 | | |
19629 | 19674 | | |
| 19675 | + | |
19630 | 19676 | | |
19631 | 19677 | | |
19632 | 19678 | | |
| |||
0 commit comments