mirror of
https://github.com/boostorg/mysql.git
synced 2026-02-15 13:12:21 +00:00
Improved error detection in DATETIME bin deseriaiz
Now DATETIMEs with invalid dates and invalid hours/mins/secs/micros are considered an error. Added tests.
This commit is contained in:
@@ -200,6 +200,17 @@ inline errc deserialize_binary_value_to_variant_datetime(
|
||||
return err;
|
||||
}
|
||||
|
||||
// Validity check. We make this check before
|
||||
// the invalid date check to make invalid dates with incorrect
|
||||
// hours/mins/secs/micros fail
|
||||
if (hours.value > max_hour ||
|
||||
minutes.value > max_min ||
|
||||
seconds.value > max_sec ||
|
||||
micros.value > max_micro)
|
||||
{
|
||||
return errc::protocol_value_error;
|
||||
}
|
||||
|
||||
// Check for invalid dates, represented in C++ as NULL.
|
||||
// Note: we do the check here to ensure we consume all the bytes
|
||||
// associated to this datetime
|
||||
@@ -211,11 +222,7 @@ inline errc deserialize_binary_value_to_variant_datetime(
|
||||
|
||||
// Range check
|
||||
date d (ymd);
|
||||
if (is_out_of_range(d) ||
|
||||
hours.value > max_hour ||
|
||||
minutes.value > max_min ||
|
||||
seconds.value > max_sec ||
|
||||
micros.value > max_micro)
|
||||
if (is_out_of_range(d))
|
||||
{
|
||||
return errc::protocol_value_error;
|
||||
}
|
||||
|
||||
@@ -149,22 +149,26 @@ std::vector<err_binary_value_testcase> make_datetime_cases(
|
||||
{
|
||||
return {
|
||||
{ "empty", {}, type, errc::incomplete_message },
|
||||
{ "incomplete_date", {0x04, 0x09, 0x27, 0x01}, type, errc::incomplete_message },
|
||||
{ "no_hours_mins_secs", {0x07, 0x09, 0x27, 0x01, 0x01}, type, errc::incomplete_message },
|
||||
{ "no_mins_secs", {0x07, 0x09, 0x27, 0x01, 0x01, 0x01}, type, errc::incomplete_message },
|
||||
{ "no_secs", {0x07, 0x09, 0x27, 0x01, 0x01, 0x01, 0x01}, type, errc::incomplete_message },
|
||||
{ "no_micros", {0x0b, 0x09, 0x27, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00},
|
||||
{ "incomplete_date", {0x04, 0x09, 0x27, 0x01}, type, errc::incomplete_message },
|
||||
{ "no_hours_mins_secs", {0x07, 0x09, 0x27, 0x01, 0x01}, type, errc::incomplete_message },
|
||||
{ "no_mins_secs", {0x07, 0x09, 0x27, 0x01, 0x01, 0x01}, type, errc::incomplete_message },
|
||||
{ "no_secs", {0x07, 0x09, 0x27, 0x01, 0x01, 0x01, 0x01}, type, errc::incomplete_message },
|
||||
{ "no_micros", {0x0b, 0x09, 0x27, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00},
|
||||
type, errc::incomplete_message },
|
||||
{ "date_gt_max", {0x0b, 0xff, 0xff, 0x01, 0x01, 0x17, 0x01, 0x3b, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_hour", {0x0b, 0xda, 0x07, 0x01, 0x01, 24, 0x01, 0x3b, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_hour_max", {0x0b, 0xda, 0x07, 0x01, 0x01, 0xff, 0x01, 0x3b, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_min", {0x0b, 0xda, 0x07, 0x01, 0x01, 0x17, 60, 0x3b, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_min_max", {0x0b, 0xda, 0x07, 0x01, 0x01, 0x17, 0xff, 0x3b, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_sec", {0x0b, 0xda, 0x07, 0x01, 0x01, 0x17, 0x01, 60, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_sec_max", {0x0b, 0xda, 0x07, 0x01, 0x01, 0x17, 0x01, 0xff, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_micro", {0x0b, 0xda, 0x07, 0x01, 0x01, 0x17, 0x01, 0x3b, 0x40, 0x42, 0xf4, 0x00}, type }, // 1M
|
||||
{ "invalid_micro_max", {0x0b, 0xda, 0x07, 0x01, 0x01, 0x17, 0x01, 0x3b, 0xff, 0xff, 0xff, 0xff}, type },
|
||||
{ "protocol_max", {0xff, 0xff, 0xff, 12, 31, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, type }, // make date valid
|
||||
{ "date_gt_max", {0x0b, 0xff, 0xff, 0x01, 0x01, 0x17, 0x01, 0x3b, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_hour", {0x0b, 0xda, 0x07, 0x01, 0x01, 24, 0x01, 0x3b, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_hour_max", {0x0b, 0xda, 0x07, 0x01, 0x01, 0xff, 0x01, 0x3b, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_hour_invalid_date", {0x0b, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x3b, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_min", {0x0b, 0xda, 0x07, 0x01, 0x01, 0x17, 60, 0x3b, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_min_max", {0x0b, 0xda, 0x07, 0x01, 0x01, 0x17, 0xff, 0x3b, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_min_invalid_date", {0x0b, 0x00, 0x00, 0x00, 0x00, 0x17, 0xff, 0x3b, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_sec", {0x0b, 0xda, 0x07, 0x01, 0x01, 0x17, 0x01, 60, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_sec_max", {0x0b, 0xda, 0x07, 0x01, 0x01, 0x17, 0x01, 0xff, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_sec_invalid_date", {0x0b, 0x00, 0x00, 0x00, 0x00, 0x17, 0x01, 0xff, 0x56, 0xc3, 0x0e, 0x00}, type },
|
||||
{ "invalid_micro", {0x0b, 0xda, 0x07, 0x01, 0x01, 0x17, 0x01, 0x3b, 0x40, 0x42, 0xf4, 0x00}, type }, // 1M
|
||||
{ "invalid_micro_max", {0x0b, 0xda, 0x07, 0x01, 0x01, 0x17, 0x01, 0x3b, 0xff, 0xff, 0xff, 0xff}, type },
|
||||
{ "invalid_micro_invalid_date", {0x0b, 0x00, 0x00, 0x00, 0x00, 0x17, 0x01, 0x3b, 0xff, 0xff, 0xff, 0xff}, type },
|
||||
{ "protocol_max", {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, type }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user