diff --git a/src/raspberrypi/devices/device.cpp b/src/raspberrypi/devices/device.cpp index 04350246..0ce63107 100644 --- a/src/raspberrypi/devices/device.cpp +++ b/src/raspberrypi/devices/device.cpp @@ -61,9 +61,7 @@ void Device::SetProtected(bool write_protected) void Device::SetVendor(const string& vendor) { if (vendor.empty() || vendor.length() > 8) { - ostringstream error; - error << "Vendor '" << vendor << "' must be between 1 and 8 characters"; - throw illegal_argument_exception(error.str()); + throw illegal_argument_exception("Vendor '" + vendor + "' must be between 1 and 8 characters"); } this->vendor = vendor; @@ -77,9 +75,7 @@ void Device::SetProduct(const string& product, bool force) } if (product.empty() || product.length() > 16) { - ostringstream error; - error << "Product '" << product << "' must be between 1 and 16 characters"; - throw illegal_argument_exception(error.str()); + throw illegal_argument_exception("Product '" + product + "' must be between 1 and 16 characters"); } this->product = product; @@ -88,9 +84,7 @@ void Device::SetProduct(const string& product, bool force) void Device::SetRevision(const string& revision) { if (revision.empty() || revision.length() > 4) { - ostringstream error; - error << "Revision '" << revision << "' must be between 1 and 4 characters"; - throw illegal_argument_exception(error.str()); + throw illegal_argument_exception("Revision '" + revision + "' must be between 1 and 4 characters"); } this->revision = revision; diff --git a/src/raspberrypi/rascsi.cpp b/src/raspberrypi/rascsi.cpp index 32b6b0ad..0f188cd6 100644 --- a/src/raspberrypi/rascsi.cpp +++ b/src/raspberrypi/rascsi.cpp @@ -706,19 +706,25 @@ bool ProcessCmd(int fd, const PbDeviceDefinition& pbDevice, const PbOperation op device->SetId(id); device->SetLun(unit); - if (!pbDevice.vendor().empty()) { - device->SetVendor(pbDevice.vendor()); - } - if (!pbDevice.product().empty()) { - device->SetProduct(pbDevice.product()); - } - if (!pbDevice.revision().empty()) { - device->SetRevision(pbDevice.revision()); - } if (!device->IsReadOnly()) { device->SetProtected(pbDevice.protected_()); } + try { + if (!pbDevice.vendor().empty()) { + device->SetVendor(pbDevice.vendor()); + } + if (!pbDevice.product().empty()) { + device->SetProduct(pbDevice.product()); + } + if (!pbDevice.revision().empty()) { + device->SetRevision(pbDevice.revision()); + } + } + catch(const illegal_argument_exception& e) { + return ReturnStatus(fd, false, e.getmsg()); + } + if (pbDevice.block_size()) { Disk *disk = dynamic_cast(device); if (disk && disk->IsSectorSizeConfigurable()) {