Commit 257c39a5 authored by Piotr Pawliczek's avatar Piotr Pawliczek Committed by Commit Bot

Correct printer URI validation

Printer URI validation fails when detected queue name does not start
from a slash character. This patch corrects this problem.

BUG=none
TEST=tested on atlas with Brother printer

Change-Id: I3aaf2b82c55ebdcd3388a7067f0005cf12c618e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2306820
Auto-Submit: Piotr Pawliczek <pawliczek@chromium.org>
Reviewed-by: default avatarSean Kau <skau@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Piotr Pawliczek <pawliczek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790176}
parent 71dd434c
......@@ -168,6 +168,9 @@ std::unique_ptr<chromeos::Printer> DictToPrinter(
std::string printer_queue;
printer_dict.GetString("printerQueue", &printer_queue);
// Path must start from '/' character.
if (!printer_queue.empty() && printer_queue.front() != '/')
printer_queue = "/" + printer_queue;
auto printer = std::make_unique<chromeos::Printer>(printer_id);
printer->set_display_name(printer_name);
......@@ -182,9 +185,25 @@ std::unique_ptr<chromeos::Printer> DictToPrinter(
SplitAddress(printer_address, &printer_host, &printer_port);
Uri uri;
if (!uri.SetScheme(printer_protocol) || !uri.SetHostEncoded(printer_host) ||
!uri.SetPort(printer_port) || !uri.SetPathEncoded(printer_queue) ||
!printer->SetUri(uri)) {
if (!uri.SetScheme(printer_protocol)) {
PRINTER_LOG(ERROR) << "Incorrect protocol: " << printer_protocol;
return nullptr;
}
if (!uri.SetHostEncoded(printer_host)) {
PRINTER_LOG(ERROR) << "Incorrect host: " << printer_host;
return nullptr;
}
if (!uri.SetPort(printer_port)) {
PRINTER_LOG(ERROR) << "Incorrect port: " << printer_port;
return nullptr;
}
if (!uri.SetPathEncoded(printer_queue)) {
PRINTER_LOG(ERROR) << "Incorrect path: " << printer_queue;
return nullptr;
}
std::string message;
if (!printer->SetUri(uri, &message)) {
PRINTER_LOG(ERROR) << "Incorrect uri: " << message;
return nullptr;
}
......@@ -476,6 +495,9 @@ void CupsPrintersHandler::HandleGetPrinterInfo(const base::ListValue* args) {
std::string printer_queue;
printer_dict->GetString("printerQueue", &printer_queue);
// Path must start from '/' character.
if (!printer_queue.empty() && printer_queue.front() != '/')
printer_queue = "/" + printer_queue;
std::string printer_protocol;
if (!printer_dict->GetString("printerProtocol", &printer_protocol)) {
......
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