~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/opt_range.cc

Replace MAX_(DATE|TIME).*_WIDTH defines in definitions.h with real (and correct) static const members to Temporal types.

This fixes the buffer overflow in https://bugs.launchpad.net/drizzle/+bug/373468

It also removes a handwritten snprintf in field/datetime.cc
However... this caused us to have to change Temporal to have a way to not
"convert" the int64_t value (so 20090101 becomes 20090101000000 etc) as it
has already been converted and we just want the Temporal type to do the
to_string conversion.

This still causes a failure in 'metadata' test due to size of timestamp type. I need feedback from Jay on when the usecond code comes into play to know the correct fix for this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4554
4554
    if (value->real_item()->type() == Item::FIELD_ITEM
4555
4555
        && value->result_type() == STRING_RESULT)
4556
4556
    {
4557
 
      char buff[MAX_DATETIME_FULL_WIDTH];
 
4557
      char buff[drizzled::DateTime::MAX_STRING_LENGTH];
4558
4558
      String tmp(buff, sizeof(buff), &my_charset_bin);
4559
4559
      String *res= value->val_str(&tmp);
4560
4560
 
4584
4584
           * Datetime in right-hand side column is before UNIX epoch, so adjust to
4585
4585
           * lower bound.
4586
4586
           */
4587
 
          char new_value_buff[MAX_DATETIME_FULL_WIDTH];
4588
 
          size_t new_value_length;
 
4587
          char new_value_buff[drizzled::DateTime::MAX_STRING_LENGTH];
 
4588
          int new_value_length;
4589
4589
          String new_value_string(new_value_buff, sizeof(new_value_buff), &my_charset_bin);
4590
4590
 
4591
4591
          new_value_length= min_timestamp.to_string(new_value_string.c_ptr(),
4592
 
                                                    MAX_DATETIME_FULL_WIDTH);
4593
 
          assert(new_value_length < MAX_DATETIME_FULL_WIDTH);
 
4592
                                    drizzled::DateTime::MAX_STRING_LENGTH);
 
4593
          assert((new_value_length+1) < drizzled::DateTime::MAX_STRING_LENGTH);
4594
4594
          new_value_string.length(new_value_length);
4595
4595
          err= value->save_str_value_in_field(field, &new_value_string);
4596
4596
        }
4600
4600
           * Datetime in right hand side column is after UNIX epoch, so adjust
4601
4601
           * to the higher bound of the epoch.
4602
4602
           */
4603
 
          char new_value_buff[MAX_DATETIME_FULL_WIDTH];
 
4603
          char new_value_buff[drizzled::DateTime::MAX_STRING_LENGTH];
4604
4604
          int new_value_length;
4605
4605
          String new_value_string(new_value_buff, sizeof(new_value_buff), &my_charset_bin);
4606
4606
 
4607
4607
          new_value_length= max_timestamp.to_string(new_value_string.c_ptr(),
4608
 
                                                    MAX_DATETIME_FULL_WIDTH);
4609
 
          assert(new_value_length < MAX_DATETIME_FULL_WIDTH);
 
4608
                                        drizzled::DateTime::MAX_STRING_LENGTH);
 
4609
          assert((new_value_length+1) < drizzled::DateTime::MAX_STRING_LENGTH);
4610
4610
          new_value_string.length(new_value_length);
4611
4611
          err= value->save_str_value_in_field(field, &new_value_string);
4612
4612
        }