318 lines
10 KiB
C++
Executable File
318 lines
10 KiB
C++
Executable File
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#if defined(_MSC_VER)
|
|
#pragma warning(push)
|
|
#pragma warning(disable:4065)
|
|
#endif
|
|
|
|
#include "extensions/common/api/mime_handler.mojom-shared.h"
|
|
|
|
#include <utility>
|
|
|
|
#include "base/logging.h"
|
|
#include "mojo/public/cpp/bindings/lib/validate_params.h"
|
|
#include "mojo/public/cpp/bindings/lib/validation_context.h"
|
|
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
|
|
#include "mojo/public/cpp/bindings/lib/validation_util.h"
|
|
namespace extensions {
|
|
namespace mime_handler {
|
|
|
|
namespace internal {
|
|
|
|
|
|
// static
|
|
bool StreamInfo_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const StreamInfo_Data* object = static_cast<const StreamInfo_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 48 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->mime_type, 1, validation_context)) {
|
|
return false;
|
|
}
|
|
const mojo::internal::ContainerValidateParams mime_type_validate_params(
|
|
0, false, nullptr);
|
|
if (!mojo::internal::ValidateContainer(object->mime_type, validation_context,
|
|
&mime_type_validate_params)) {
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->original_url, 2, validation_context)) {
|
|
return false;
|
|
}
|
|
const mojo::internal::ContainerValidateParams original_url_validate_params(
|
|
0, false, nullptr);
|
|
if (!mojo::internal::ValidateContainer(object->original_url, validation_context,
|
|
&original_url_validate_params)) {
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->stream_url, 3, validation_context)) {
|
|
return false;
|
|
}
|
|
const mojo::internal::ContainerValidateParams stream_url_validate_params(
|
|
0, false, nullptr);
|
|
if (!mojo::internal::ValidateContainer(object->stream_url, validation_context,
|
|
&stream_url_validate_params)) {
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->response_headers, 5, validation_context)) {
|
|
return false;
|
|
}
|
|
const mojo::internal::ContainerValidateParams response_headers_validate_params(
|
|
new mojo::internal::ContainerValidateParams(0, false, new mojo::internal::ContainerValidateParams(0, false, nullptr)), new mojo::internal::ContainerValidateParams(0, false, new mojo::internal::ContainerValidateParams(0, false, nullptr)));
|
|
if (!mojo::internal::ValidateContainer(object->response_headers, validation_context,
|
|
&response_headers_validate_params)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
StreamInfo_Data::StreamInfo_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool MimeHandlerService_GetStreamInfo_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const MimeHandlerService_GetStreamInfo_Params_Data* object = static_cast<const MimeHandlerService_GetStreamInfo_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 8 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
MimeHandlerService_GetStreamInfo_Params_Data::MimeHandlerService_GetStreamInfo_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool MimeHandlerService_GetStreamInfo_ResponseParams_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const MimeHandlerService_GetStreamInfo_ResponseParams_Data* object = static_cast<const MimeHandlerService_GetStreamInfo_ResponseParams_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 16 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidateStruct(object->stream_info, validation_context))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
MimeHandlerService_GetStreamInfo_ResponseParams_Data::MimeHandlerService_GetStreamInfo_ResponseParams_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool MimeHandlerService_AbortStream_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const MimeHandlerService_AbortStream_Params_Data* object = static_cast<const MimeHandlerService_AbortStream_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 8 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
MimeHandlerService_AbortStream_Params_Data::MimeHandlerService_AbortStream_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool MimeHandlerService_AbortStream_ResponseParams_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const MimeHandlerService_AbortStream_ResponseParams_Data* object = static_cast<const MimeHandlerService_AbortStream_ResponseParams_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 8 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
MimeHandlerService_AbortStream_ResponseParams_Data::MimeHandlerService_AbortStream_ResponseParams_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
} // namespace internal
|
|
} // namespace mime_handler
|
|
} // namespace extensions
|
|
|
|
#if defined(_MSC_VER)
|
|
#pragma warning(pop)
|
|
#endif
|