Merge pull request #4179 from yandex/avoid-overflow-in-function-sleep

Fixed possible overflow in function "sleep" (found by fuzz test with UBSan)
This commit is contained in:
alexey-milovidov 2019-01-29 13:44:39 +03:00 committed by GitHub
commit aa06005a32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 4 deletions

View File

@ -82,12 +82,11 @@ public:
/// We do not sleep if the block is empty.
if (size > 0)
{
unsigned useconds = seconds * (variant == FunctionSleepVariant::PerBlock ? 1 : size) * 1e6;
/// When sleeping, the query cannot be cancelled. For abitily to cancel query, we limit sleep time.
if (useconds > 3000000) /// The choice is arbitrary
throw Exception("The maximum sleep time is 3000000 microseconds. Requested: " + toString(useconds), ErrorCodes::TOO_SLOW);
if (seconds > 3.0) /// The choice is arbitrary
throw Exception("The maximum sleep time is 3 seconds. Requested: " + toString(seconds), ErrorCodes::TOO_SLOW);
UInt64 useconds = seconds * (variant == FunctionSleepVariant::PerBlock ? 1 : size) * 1e6;
::usleep(useconds);
}

View File

@ -0,0 +1 @@
SELECT sleep(4295.967296); -- { serverError 160 }