1
- /* Copyright (c) 2002, 2012 , Oracle and/or its affiliates. All rights reserved.
1
+ /* Copyright (c) 2002, 2013 , Oracle and/or its affiliates. All rights reserved.
2
2
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License as published by
@@ -959,6 +959,9 @@ static bool setup_conversion_functions(Prepared_statement *stmt,
959
959
960
960
DBUG_ENTER (" setup_conversion_functions" );
961
961
962
+ if (read_pos >= data_end)
963
+ DBUG_RETURN (1 );
964
+
962
965
if (*read_pos++) // types supplied / first execute
963
966
{
964
967
/*
@@ -2624,8 +2627,8 @@ static void reset_stmt_params(Prepared_statement *stmt)
2624
2627
void mysqld_stmt_execute (THD *thd, char *packet_arg, uint packet_length)
2625
2628
{
2626
2629
uchar *packet= (uchar*)packet_arg; // GCC 4.0.1 workaround
2627
- ulong stmt_id= uint4korr (packet) ;
2628
- ulong flags= (ulong) packet[ 4 ] ;
2630
+ ulong stmt_id;
2631
+ ulong flags;
2629
2632
/* Query text for binary, general or slow log, if any of them is open */
2630
2633
String expanded_query;
2631
2634
uchar *packet_end= packet + packet_length;
@@ -2634,6 +2637,14 @@ void mysqld_stmt_execute(THD *thd, char *packet_arg, uint packet_length)
2634
2637
bool open_cursor;
2635
2638
DBUG_ENTER (" mysqld_stmt_execute" );
2636
2639
2640
+ if (packet + 9 > packet_end)
2641
+ {
2642
+ my_error (ER_MALFORMED_PACKET, MYF (0 ));
2643
+ DBUG_VOID_RETURN;
2644
+ }
2645
+
2646
+ stmt_id= uint4korr (packet);
2647
+ flags= (ulong) packet[4 ];
2637
2648
packet+= 9 ; /* stmt_id + 5 bytes of flags */
2638
2649
2639
2650
/* First of all clear possible warnings from the previous command */
@@ -2728,13 +2739,21 @@ void mysql_sql_stmt_execute(THD *thd)
2728
2739
void mysqld_stmt_fetch (THD *thd, char *packet, uint packet_length)
2729
2740
{
2730
2741
/* assume there is always place for 8-16 bytes */
2731
- ulong stmt_id= uint4korr (packet) ;
2732
- ulong num_rows= uint4korr (packet+ 4 ) ;
2742
+ ulong stmt_id;
2743
+ ulong num_rows;
2733
2744
Prepared_statement *stmt;
2734
2745
Statement stmt_backup;
2735
2746
Server_side_cursor *cursor;
2736
2747
DBUG_ENTER (" mysqld_stmt_fetch" );
2737
2748
2749
+ if (packet_length < 8 )
2750
+ {
2751
+ my_error (ER_MALFORMED_PACKET, MYF (0 ));
2752
+ DBUG_VOID_RETURN;
2753
+ }
2754
+ stmt_id= uint4korr (packet);
2755
+ num_rows= uint4korr (packet+4 );
2756
+
2738
2757
/* First of all clear possible warnings from the previous command */
2739
2758
mysql_reset_thd_for_next_command (thd);
2740
2759
status_var_increment (thd->status_var .com_stmt_fetch );
@@ -2785,15 +2804,23 @@ void mysqld_stmt_fetch(THD *thd, char *packet, uint packet_length)
2785
2804
2786
2805
@param thd Thread handle
2787
2806
@param packet Packet with stmt id
2807
+ @param packet_length length of data in packet
2788
2808
*/
2789
2809
2790
- void mysqld_stmt_reset (THD *thd, char *packet)
2810
+ void mysqld_stmt_reset (THD *thd, char *packet, uint packet_length )
2791
2811
{
2792
- /* There is always space for 4 bytes in buffer */
2793
- ulong stmt_id= uint4korr (packet);
2812
+ ulong stmt_id;
2794
2813
Prepared_statement *stmt;
2795
2814
DBUG_ENTER (" mysqld_stmt_reset" );
2796
2815
2816
+ if (packet_length < 4 )
2817
+ {
2818
+ my_error (ER_MALFORMED_PACKET, MYF (0 ));
2819
+ DBUG_VOID_RETURN;
2820
+ }
2821
+
2822
+ stmt_id= uint4korr (packet);
2823
+
2797
2824
/* First of all clear possible warnings from the previous command */
2798
2825
mysql_reset_thd_for_next_command (thd);
2799
2826
@@ -2831,13 +2858,21 @@ void mysqld_stmt_reset(THD *thd, char *packet)
2831
2858
we don't send any reply to this command.
2832
2859
*/
2833
2860
2834
- void mysqld_stmt_close (THD *thd, char *packet)
2861
+ void mysqld_stmt_close (THD *thd, char *packet, uint packet_length )
2835
2862
{
2836
2863
/* There is always space for 4 bytes in packet buffer */
2837
- ulong stmt_id= uint4korr (packet) ;
2864
+ ulong stmt_id;
2838
2865
Prepared_statement *stmt;
2839
2866
DBUG_ENTER (" mysqld_stmt_close" );
2840
2867
2868
+ if (packet_length < 4 )
2869
+ {
2870
+ my_error (ER_MALFORMED_PACKET, MYF (0 ));
2871
+ DBUG_VOID_RETURN;
2872
+ }
2873
+
2874
+ stmt_id= uint4korr (packet);
2875
+
2841
2876
thd->get_stmt_da ()->disable_status ();
2842
2877
2843
2878
if (!(stmt= find_prepared_statement (thd, stmt_id)))
0 commit comments