Commit d59272fb authored by unknown's avatar unknown

Bug #27231: Server crash when dumping into outfile with long FIELDS ENCLOSED BY option

- Problem: data separators were copied to a fixed-size buffer
  on the stack; memcpy was used, without bounds checking; a
  server crash could result if long FIELDS ENCLOSED BY, etc.,
  was given
- Fix: write the separators directly, instead of copying to
  a buffer first (in select_export::send_data())


sql/sql_class.cc:
  In select_export::send_data(), write data separators
  directly, instead of copying into a fixed-size memory
  buffer before writing.  This avoids a buffer overflow
  when very large separators are specified.
parent 39333ba7
...@@ -1048,7 +1048,6 @@ bool select_export::send_data(List<Item> &items) ...@@ -1048,7 +1048,6 @@ bool select_export::send_data(List<Item> &items)
} }
row_count++; row_count++;
Item *item; Item *item;
char *buff_ptr=buff;
uint used_length=0,items_left=items.elements; uint used_length=0,items_left=items.elements;
List_iterator_fast<Item> li(items); List_iterator_fast<Item> li(items);
...@@ -1148,20 +1147,19 @@ bool select_export::send_data(List<Item> &items) ...@@ -1148,20 +1147,19 @@ bool select_export::send_data(List<Item> &items)
goto err; goto err;
} }
} }
buff_ptr=buff; // Place separators here
if (res && (!exchange->opt_enclosed || result_type == STRING_RESULT)) if (res && (!exchange->opt_enclosed || result_type == STRING_RESULT))
{ {
memcpy(buff_ptr,exchange->enclosed->ptr(),exchange->enclosed->length()); if (my_b_write(&cache, (byte*) exchange->enclosed->ptr(),
buff_ptr+=exchange->enclosed->length(); exchange->enclosed->length()))
goto err;
} }
if (--items_left) if (--items_left)
{ {
memcpy(buff_ptr,exchange->field_term->ptr(),field_term_length); if (my_b_write(&cache, (byte*) exchange->field_term->ptr(),
buff_ptr+=field_term_length; field_term_length))
}
if (my_b_write(&cache,(byte*) buff,(uint) (buff_ptr-buff)))
goto err; goto err;
} }
}
if (my_b_write(&cache,(byte*) exchange->line_term->ptr(), if (my_b_write(&cache,(byte*) exchange->line_term->ptr(),
exchange->line_term->length())) exchange->line_term->length()))
goto err; goto err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment