Commit 896bb87a authored by Tatiana Buldina's avatar Tatiana Buldina Committed by Commit Bot

[ChromeDriver] Checking invalid input in Set Window Rect

Bug: chromedriver:2655
Change-Id: I8afab41743acd2d98e53b19e0bc11835c2025590
Reviewed-on: https://chromium-review.googlesource.com/c/1330837
Commit-Queue: Tatiana Buldina <buldina@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608438}
parent 65ed1a5d
......@@ -975,21 +975,51 @@ Status ExecuteGetWindowSize(Session* session,
Status ExecuteSetWindowRect(Session* session,
const base::DictionaryValue& params,
std::unique_ptr<base::Value>* value) {
const double max_range = 2147483647; // 2^31 - 1
const double min_range = -2147483648; // -2^31
const base::Value* temp;
double width = 0;
double height = 0;
double x = 0;
double y = 0;
bool has_x = params.Get("x", &temp) && !temp->is_none();
if (has_x) {
if (!temp->GetAsDouble(&x))
return Status(kInvalidArgument, "'x' must be a number");
if (x > max_range || x < min_range)
return Status(kInvalidArgument, "'x' out of range");
}
bool has_y = params.Get("y", &temp) && !temp->is_none();
if (has_y) {
if (!temp->GetAsDouble(&y))
return Status(kInvalidArgument, "'y' must be a number");
if (y > max_range || y < min_range )
return Status(kInvalidArgument, "'y' out of range");
}
bool has_width = params.Get("width", &temp) && !temp->is_none();
if (has_width) {
if (!temp->GetAsDouble(&width))
return Status(kInvalidArgument, "'width' must be a number");
if (width > max_range || width < 0 )
return Status(kInvalidArgument, "'width' out of range");
}
bool has_height = params.Get("height", &temp) && !temp->is_none();
if (has_height) {
if (!temp->GetAsDouble(&height))
return Status(kInvalidArgument, "'height' must be a number");
if (height > max_range || height < 0 )
return Status(kInvalidArgument, "'height' out of range");
}
// to pass to the set window rect command
base::DictionaryValue rect_params;
// only set position if both x and y are given
if (params.GetDouble("x", &x) && params.GetDouble("y", &y)) {
if (has_x && has_y) {
rect_params.SetInteger("x", static_cast<int>(x));
rect_params.SetInteger("y", static_cast<int>(y));
} // only set size if both height and width are given
if (params.GetDouble("width", &width) &&
params.GetDouble("height", &height)) {
if (has_width && has_height) {
rect_params.SetInteger("width", static_cast<int>(width));
rect_params.SetInteger("height", static_cast<int>(height));
}
......
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