1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
11 #include "base/strings/string_util.h"
12 #include "ipc/ipc_message.h"
13 #include "ipc/ipc_message_utils.h"
14 #include "ipc/ipc_switches.h"
15 #include "ipc/ipc_sync_channel.h"
16 #include "ipc/ipc_sync_message.h"
17 #include "tools/ipc_fuzzer/fuzzer/fuzzer.h"
18 #include "tools/ipc_fuzzer/fuzzer/rand_util.h"
19 #include "tools/ipc_fuzzer/message_lib/message_cracker.h"
20 #include "tools/ipc_fuzzer/message_lib/message_file.h"
26 // First include of all message files to provide basic types.
27 #include "tools/ipc_fuzzer/message_lib/all_messages.h"
28 #include "tools/ipc_fuzzer/message_lib/all_message_null_macros.h"
30 #if defined(COMPILER_GCC)
31 #define PRETTY_FUNCTION __PRETTY_FUNCTION__
32 #elif defined(COMPILER_MSVC)
33 #define PRETTY_FUNCTION __FUNCSIG__
35 #define PRETTY_FUNCTION __FUNCTION__
43 // For breaking deep recursion.
47 namespace ipc_fuzzer
{
49 FuzzerFunctionVector g_function_vector
;
51 bool Fuzzer::ShouldGenerate() {
55 // Partially-specialized class that knows how to handle a given type.
58 static bool Fuzz(P
* p
, Fuzzer
*fuzzer
) {
59 // This is the catch-all for types we don't have enough information
61 std::cerr
<< "Can't handle " << PRETTY_FUNCTION
<< "\n";
66 // Template function to invoke partially-specialized class method.
68 static bool FuzzParam(P
* p
, Fuzzer
* fuzzer
) {
69 return FuzzTraits
<P
>::Fuzz(p
, fuzzer
);
73 static bool FuzzParamArray(P
* p
, size_t length
, Fuzzer
* fuzzer
) {
74 for (size_t i
= 0; i
< length
; i
++, p
++) {
75 if (!FuzzTraits
<P
>::Fuzz(p
, fuzzer
))
81 // Specializations to generate primitive types.
83 struct FuzzTraits
<bool> {
84 static bool Fuzz(bool* p
, Fuzzer
* fuzzer
) {
91 struct FuzzTraits
<int> {
92 static bool Fuzz(int* p
, Fuzzer
* fuzzer
) {
99 struct FuzzTraits
<unsigned int> {
100 static bool Fuzz(unsigned int* p
, Fuzzer
* fuzzer
) {
101 fuzzer
->FuzzInt(reinterpret_cast<int*>(p
));
107 struct FuzzTraits
<long> {
108 static bool Fuzz(long* p
, Fuzzer
* fuzzer
) {
115 struct FuzzTraits
<unsigned long> {
116 static bool Fuzz(unsigned long* p
, Fuzzer
* fuzzer
) {
117 fuzzer
->FuzzLong(reinterpret_cast<long*>(p
));
123 struct FuzzTraits
<long long> {
124 static bool Fuzz(long long* p
, Fuzzer
* fuzzer
) {
125 fuzzer
->FuzzInt64(reinterpret_cast<int64
*>(p
));
131 struct FuzzTraits
<unsigned long long> {
132 static bool Fuzz(unsigned long long* p
, Fuzzer
* fuzzer
) {
133 fuzzer
->FuzzInt64(reinterpret_cast<int64
*>(p
));
139 struct FuzzTraits
<short> {
140 static bool Fuzz(short* p
, Fuzzer
* fuzzer
) {
141 fuzzer
->FuzzUInt16(reinterpret_cast<uint16
*>(p
));
147 struct FuzzTraits
<unsigned short> {
148 static bool Fuzz(unsigned short* p
, Fuzzer
* fuzzer
) {
149 fuzzer
->FuzzUInt16(reinterpret_cast<uint16
*>(p
));
155 struct FuzzTraits
<char> {
156 static bool Fuzz(char* p
, Fuzzer
* fuzzer
) {
157 fuzzer
->FuzzUChar(reinterpret_cast<unsigned char*>(p
));
163 struct FuzzTraits
<unsigned char> {
164 static bool Fuzz(unsigned char* p
, Fuzzer
* fuzzer
) {
165 fuzzer
->FuzzUChar(p
);
171 struct FuzzTraits
<wchar_t> {
172 static bool Fuzz(wchar_t* p
, Fuzzer
* fuzzer
) {
173 fuzzer
->FuzzWChar(p
);
179 struct FuzzTraits
<float> {
180 static bool Fuzz(float* p
, Fuzzer
* fuzzer
) {
181 fuzzer
->FuzzFloat(p
);
187 struct FuzzTraits
<double> {
188 static bool Fuzz(double* p
, Fuzzer
* fuzzer
) {
189 fuzzer
->FuzzDouble(p
);
195 struct FuzzTraits
<std::string
> {
196 static bool Fuzz(std::string
* p
, Fuzzer
* fuzzer
) {
197 fuzzer
->FuzzString(p
);
203 struct FuzzTraits
<base::string16
> {
204 static bool Fuzz(base::string16
* p
, Fuzzer
* fuzzer
) {
205 fuzzer
->FuzzString16(p
);
210 // Specializations for tuples.
212 struct FuzzTraits
<base::Tuple
<>> {
213 static bool Fuzz(base::Tuple
<>* p
, Fuzzer
* fuzzer
) {
219 struct FuzzTraits
<base::Tuple
<A
>> {
220 static bool Fuzz(base::Tuple
<A
>* p
, Fuzzer
* fuzzer
) {
221 return FuzzParam(&base::get
<0>(*p
), fuzzer
);
225 template <class A
, class B
>
226 struct FuzzTraits
<base::Tuple
<A
, B
>> {
227 static bool Fuzz(base::Tuple
<A
, B
>* p
, Fuzzer
* fuzzer
) {
229 FuzzParam(&base::get
<0>(*p
), fuzzer
) &&
230 FuzzParam(&base::get
<1>(*p
), fuzzer
);
234 template <class A
, class B
, class C
>
235 struct FuzzTraits
<base::Tuple
<A
, B
, C
>> {
236 static bool Fuzz(base::Tuple
<A
, B
, C
>* p
, Fuzzer
* fuzzer
) {
238 FuzzParam(&base::get
<0>(*p
), fuzzer
) &&
239 FuzzParam(&base::get
<1>(*p
), fuzzer
) &&
240 FuzzParam(&base::get
<2>(*p
), fuzzer
);
244 template <class A
, class B
, class C
, class D
>
245 struct FuzzTraits
<base::Tuple
<A
, B
, C
, D
>> {
246 static bool Fuzz(base::Tuple
<A
, B
, C
, D
>* p
, Fuzzer
* fuzzer
) {
248 FuzzParam(&base::get
<0>(*p
), fuzzer
) &&
249 FuzzParam(&base::get
<1>(*p
), fuzzer
) &&
250 FuzzParam(&base::get
<2>(*p
), fuzzer
) &&
251 FuzzParam(&base::get
<3>(*p
), fuzzer
);
255 template <class A
, class B
, class C
, class D
, class E
>
256 struct FuzzTraits
<base::Tuple
<A
, B
, C
, D
, E
>> {
257 static bool Fuzz(base::Tuple
<A
, B
, C
, D
, E
>* p
, Fuzzer
* fuzzer
) {
259 FuzzParam(&base::get
<0>(*p
), fuzzer
) &&
260 FuzzParam(&base::get
<1>(*p
), fuzzer
) &&
261 FuzzParam(&base::get
<2>(*p
), fuzzer
) &&
262 FuzzParam(&base::get
<3>(*p
), fuzzer
) &&
263 FuzzParam(&base::get
<4>(*p
), fuzzer
);
267 // Specializations for containers.
269 struct FuzzTraits
<std::vector
<A
> > {
270 static bool Fuzz(std::vector
<A
>* p
, Fuzzer
* fuzzer
) {
272 size_t count
= p
->size();
273 if (fuzzer
->ShouldGenerate()) {
274 count
= g_depth
> 3 ? 0 : RandElementCount();
277 for (size_t i
= 0; i
< count
; ++i
) {
278 if (!FuzzParam(&p
->at(i
), fuzzer
)) {
289 struct FuzzTraits
<std::set
<A
> > {
290 static bool Fuzz(std::set
<A
>* p
, Fuzzer
* fuzzer
) {
291 if (!fuzzer
->ShouldGenerate()) {
293 typename
std::set
<A
>::iterator it
;
294 for (it
= p
->begin(); it
!= p
->end(); ++it
) {
296 if (!FuzzParam(&item
, fuzzer
))
304 static int g_depth
= 0;
305 size_t count
= ++g_depth
> 3 ? 0 : RandElementCount();
307 for (size_t i
= 0; i
< count
; ++i
) {
308 if (!FuzzParam(&a
, fuzzer
)) {
319 template <class A
, class B
>
320 struct FuzzTraits
<std::map
<A
, B
> > {
321 static bool Fuzz(std::map
<A
, B
>* p
, Fuzzer
* fuzzer
) {
322 if (!fuzzer
->ShouldGenerate()) {
323 typename
std::map
<A
, B
>::iterator it
;
324 for (it
= p
->begin(); it
!= p
->end(); ++it
) {
325 if (!FuzzParam(&it
->second
, fuzzer
))
331 static int g_depth
= 0;
332 size_t count
= ++g_depth
> 3 ? 0 : RandElementCount();
333 std::pair
<A
, B
> place_holder
;
334 for (size_t i
= 0; i
< count
; ++i
) {
335 if (!FuzzParam(&place_holder
, fuzzer
)) {
339 p
->insert(place_holder
);
346 template <class A
, class B
, class C
, class D
>
347 struct FuzzTraits
<std::map
<A
, B
, C
, D
>> {
348 static bool Fuzz(std::map
<A
, B
, C
, D
>* p
, Fuzzer
* fuzzer
) {
349 if (!fuzzer
->ShouldGenerate()) {
350 typename
std::map
<A
, B
, C
, D
>::iterator it
;
351 for (it
= p
->begin(); it
!= p
->end(); ++it
) {
352 if (!FuzzParam(&it
->second
, fuzzer
))
358 static int g_depth
= 0;
359 size_t count
= ++g_depth
> 3 ? 0 : RandElementCount();
360 std::pair
<A
, B
> place_holder
;
361 for (size_t i
= 0; i
< count
; ++i
) {
362 if (!FuzzParam(&place_holder
, fuzzer
)) {
366 p
->insert(place_holder
);
373 template <class A
, class B
>
374 struct FuzzTraits
<std::pair
<A
, B
> > {
375 static bool Fuzz(std::pair
<A
, B
>* p
, Fuzzer
* fuzzer
) {
377 FuzzParam(&p
->first
, fuzzer
) &&
378 FuzzParam(&p
->second
, fuzzer
);
382 // Specializations for hand-coded types.
385 struct FuzzTraits
<base::FilePath
> {
386 static bool Fuzz(base::FilePath
* p
, Fuzzer
* fuzzer
) {
387 if (!fuzzer
->ShouldGenerate()) {
388 base::FilePath::StringType path
= p
->value();
389 if(!FuzzParam(&path
, fuzzer
))
391 *p
= base::FilePath(path
);
395 const char path_chars
[] = "ACz0/.~:";
396 size_t count
= RandInRange(60);
397 base::FilePath::StringType random_path
;
398 for (size_t i
= 0; i
< count
; ++i
)
399 random_path
+= path_chars
[RandInRange(sizeof(path_chars
) - 1)];
400 *p
= base::FilePath(random_path
);
406 struct FuzzTraits
<base::File::Error
> {
407 static bool Fuzz(base::File::Error
* p
, Fuzzer
* fuzzer
) {
408 int value
= static_cast<int>(*p
);
409 if (!FuzzParam(&value
, fuzzer
))
411 *p
= static_cast<base::File::Error
>(value
);
417 struct FuzzTraits
<base::File::Info
> {
418 static bool Fuzz(base::File::Info
* p
, Fuzzer
* fuzzer
) {
419 double last_modified
= p
->last_modified
.ToDoubleT();
420 double last_accessed
= p
->last_accessed
.ToDoubleT();
421 double creation_time
= p
->creation_time
.ToDoubleT();
422 if (!FuzzParam(&p
->size
, fuzzer
))
424 if (!FuzzParam(&p
->is_directory
, fuzzer
))
426 if (!FuzzParam(&last_modified
, fuzzer
))
428 if (!FuzzParam(&last_accessed
, fuzzer
))
430 if (!FuzzParam(&creation_time
, fuzzer
))
432 p
->last_modified
= base::Time::FromDoubleT(last_modified
);
433 p
->last_accessed
= base::Time::FromDoubleT(last_accessed
);
434 p
->creation_time
= base::Time::FromDoubleT(creation_time
);
440 struct FuzzTraits
<base::NullableString16
> {
441 static bool Fuzz(base::NullableString16
* p
, Fuzzer
* fuzzer
) {
442 base::string16 string
= p
->string();
443 bool is_null
= p
->is_null();
444 if (!FuzzParam(&string
, fuzzer
))
446 if (!FuzzParam(&is_null
, fuzzer
))
448 *p
= base::NullableString16(string
, is_null
);
454 struct FuzzTraits
<base::Time
> {
455 static bool Fuzz(base::Time
* p
, Fuzzer
* fuzzer
) {
456 int64 internal_value
= p
->ToInternalValue();
457 if (!FuzzParam(&internal_value
, fuzzer
))
459 *p
= base::Time::FromInternalValue(internal_value
);
465 struct FuzzTraits
<base::TimeDelta
> {
466 static bool Fuzz(base::TimeDelta
* p
, Fuzzer
* fuzzer
) {
467 int64 internal_value
= p
->ToInternalValue();
468 if (!FuzzParam(&internal_value
, fuzzer
))
470 *p
= base::TimeDelta::FromInternalValue(internal_value
);
476 struct FuzzTraits
<base::TimeTicks
> {
477 static bool Fuzz(base::TimeTicks
* p
, Fuzzer
* fuzzer
) {
478 int64 internal_value
= p
->ToInternalValue();
479 if (!FuzzParam(&internal_value
, fuzzer
))
481 *p
= base::TimeTicks::FromInternalValue(internal_value
);
487 struct FuzzTraits
<base::ListValue
> {
488 static bool Fuzz(base::ListValue
* p
, Fuzzer
* fuzzer
) {
489 // TODO(mbarbella): Support mutation.
490 if (!fuzzer
->ShouldGenerate())
494 size_t list_length
= p
->GetSize();
495 if (fuzzer
->ShouldGenerate())
496 list_length
= g_depth
> 3 ? 0 : RandInRange(8);
497 for (size_t index
= 0; index
< list_length
; ++index
) {
498 switch (RandInRange(8)) {
499 case base::Value::TYPE_BOOLEAN
: {
501 p
->GetBoolean(index
, &tmp
);
502 fuzzer
->FuzzBool(&tmp
);
503 p
->Set(index
, new base::FundamentalValue(tmp
));
506 case base::Value::TYPE_INTEGER
: {
508 p
->GetInteger(index
, &tmp
);
509 fuzzer
->FuzzInt(&tmp
);
510 p
->Set(index
, new base::FundamentalValue(tmp
));
513 case base::Value::TYPE_DOUBLE
: {
515 p
->GetDouble(index
, &tmp
);
516 fuzzer
->FuzzDouble(&tmp
);
517 p
->Set(index
, new base::FundamentalValue(tmp
));
520 case base::Value::TYPE_STRING
: {
522 p
->GetString(index
, &tmp
);
523 fuzzer
->FuzzString(&tmp
);
524 p
->Set(index
, new base::StringValue(tmp
));
527 case base::Value::TYPE_BINARY
: {
529 size_t bin_length
= RandInRange(sizeof(tmp
));
530 fuzzer
->FuzzData(tmp
, bin_length
);
532 base::BinaryValue::CreateWithCopiedBuffer(tmp
, bin_length
));
535 case base::Value::TYPE_DICTIONARY
: {
536 base::DictionaryValue
* tmp
= new base::DictionaryValue();
537 p
->GetDictionary(index
, &tmp
);
538 FuzzParam(tmp
, fuzzer
);
542 case base::Value::TYPE_LIST
: {
543 base::ListValue
* tmp
= new base::ListValue();
544 p
->GetList(index
, &tmp
);
545 FuzzParam(tmp
, fuzzer
);
549 case base::Value::TYPE_NULL
:
560 struct FuzzTraits
<base::DictionaryValue
> {
561 static bool Fuzz(base::DictionaryValue
* p
, Fuzzer
* fuzzer
) {
562 // TODO(mbarbella): Support mutation.
563 if (!fuzzer
->ShouldGenerate())
567 size_t dict_length
= g_depth
> 3 ? 0 : RandInRange(8);
568 for (size_t index
= 0; index
< dict_length
; ++index
) {
569 std::string property
;
570 fuzzer
->FuzzString(&property
);
571 switch (RandInRange(8)) {
572 case base::Value::TYPE_BOOLEAN
: {
574 fuzzer
->FuzzBool(&tmp
);
575 p
->SetWithoutPathExpansion(property
, new base::FundamentalValue(tmp
));
578 case base::Value::TYPE_INTEGER
: {
580 fuzzer
->FuzzInt(&tmp
);
581 p
->SetWithoutPathExpansion(property
, new base::FundamentalValue(tmp
));
584 case base::Value::TYPE_DOUBLE
: {
586 fuzzer
->FuzzDouble(&tmp
);
587 p
->SetWithoutPathExpansion(property
, new base::FundamentalValue(tmp
));
590 case base::Value::TYPE_STRING
: {
592 fuzzer
->FuzzString(&tmp
);
593 p
->SetWithoutPathExpansion(property
, new base::StringValue(tmp
));
596 case base::Value::TYPE_BINARY
: {
598 size_t bin_length
= RandInRange(sizeof(tmp
));
599 fuzzer
->FuzzData(tmp
, bin_length
);
600 p
->SetWithoutPathExpansion(
602 base::BinaryValue::CreateWithCopiedBuffer(tmp
, bin_length
));
605 case base::Value::TYPE_DICTIONARY
: {
606 base::DictionaryValue
* tmp
= new base::DictionaryValue();
607 FuzzParam(tmp
, fuzzer
);
608 p
->SetWithoutPathExpansion(property
, tmp
);
611 case base::Value::TYPE_LIST
: {
612 base::ListValue
* tmp
= new base::ListValue();
613 FuzzParam(tmp
, fuzzer
);
614 p
->SetWithoutPathExpansion(property
, tmp
);
617 case base::Value::TYPE_NULL
:
628 struct FuzzTraits
<blink::WebGamepad
> {
629 static bool Fuzz(blink::WebGamepad
* p
, Fuzzer
* fuzzer
) {
630 if (!FuzzParam(&p
->connected
, fuzzer
))
632 if (!FuzzParam(&p
->timestamp
, fuzzer
))
634 unsigned idLength
= static_cast<unsigned>(
635 RandInRange(blink::WebGamepad::idLengthCap
+ 1));
636 if (!FuzzParamArray(&p
->id
[0], idLength
, fuzzer
))
638 p
->axesLength
= static_cast<unsigned>(
639 RandInRange(blink::WebGamepad::axesLengthCap
+ 1));
640 if (!FuzzParamArray(&p
->axes
[0], p
->axesLength
, fuzzer
))
642 p
->buttonsLength
= static_cast<unsigned>(
643 RandInRange(blink::WebGamepad::buttonsLengthCap
+ 1));
644 if (!FuzzParamArray(&p
->buttons
[0], p
->buttonsLength
, fuzzer
))
646 unsigned mappingsLength
= static_cast<unsigned>(
647 RandInRange(blink::WebGamepad::mappingLengthCap
+ 1));
648 if (!FuzzParamArray(&p
->mapping
[0], mappingsLength
, fuzzer
))
655 struct FuzzTraits
<blink::WebGamepadButton
> {
656 static bool Fuzz(blink::WebGamepadButton
* p
, Fuzzer
* fuzzer
) {
657 if (!FuzzParam(&p
->pressed
, fuzzer
))
659 if (!FuzzParam(&p
->value
, fuzzer
))
666 struct FuzzTraits
<cc::CompositorFrame
> {
667 static bool Fuzz(cc::CompositorFrame
* p
, Fuzzer
* fuzzer
) {
668 // TODO(mbarbella): Support mutation.
669 if (!fuzzer
->ShouldGenerate())
672 if (!FuzzParam(&p
->metadata
, fuzzer
))
675 switch (RandInRange(4)) {
677 p
->delegated_frame_data
.reset(new cc::DelegatedFrameData());
678 if (!FuzzParam(p
->delegated_frame_data
.get(), fuzzer
))
683 p
->gl_frame_data
.reset(new cc::GLFrameData());
684 if (!FuzzParam(p
->gl_frame_data
.get(), fuzzer
))
689 p
->software_frame_data
.reset(new cc::SoftwareFrameData());
690 if (!FuzzParam(p
->software_frame_data
.get(), fuzzer
))
695 // Fuzz nothing to handle the no frame case.
702 struct FuzzTraits
<cc::CompositorFrameAck
> {
703 static bool Fuzz(cc::CompositorFrameAck
* p
, Fuzzer
* fuzzer
) {
704 if (!FuzzParam(&p
->resources
, fuzzer
))
707 if (!p
->gl_frame_data
)
708 p
->gl_frame_data
.reset(new cc::GLFrameData
);
709 if (!FuzzParam(p
->gl_frame_data
.get(), fuzzer
))
716 struct FuzzTraits
<cc::DelegatedFrameData
> {
717 static bool Fuzz(cc::DelegatedFrameData
* p
, Fuzzer
* fuzzer
) {
718 if (!FuzzParam(&p
->device_scale_factor
, fuzzer
))
720 if (!FuzzParam(&p
->resource_list
, fuzzer
))
722 if (!FuzzParam(&p
->render_pass_list
, fuzzer
))
729 struct FuzzTraits
<cc::ListContainer
<A
>> {
730 static bool Fuzz(cc::ListContainer
<A
>* p
, Fuzzer
* fuzzer
) {
731 // TODO(mbarbella): This should actually do something.
737 struct FuzzTraits
<cc::QuadList
> {
738 static bool Fuzz(cc::QuadList
* p
, Fuzzer
* fuzzer
) {
739 // TODO(mbarbella): This should actually do something.
745 struct FuzzTraits
<cc::RenderPass
> {
746 static bool Fuzz(cc::RenderPass
* p
, Fuzzer
* fuzzer
) {
747 if (!FuzzParam(&p
->id
, fuzzer
))
749 if (!FuzzParam(&p
->output_rect
, fuzzer
))
751 if (!FuzzParam(&p
->damage_rect
, fuzzer
))
753 if (!FuzzParam(&p
->transform_to_root_target
, fuzzer
))
755 if (!FuzzParam(&p
->has_transparent_background
, fuzzer
))
757 if (!FuzzParam(&p
->quad_list
, fuzzer
))
759 if (!FuzzParam(&p
->shared_quad_state_list
, fuzzer
))
761 // Omitting |copy_requests| as it is not sent over IPC.
767 struct FuzzTraits
<cc::RenderPassList
> {
768 static bool Fuzz(cc::RenderPassList
* p
, Fuzzer
* fuzzer
) {
769 if (!fuzzer
->ShouldGenerate()) {
770 for (size_t i
= 0; i
< p
->size(); ++i
) {
771 if (!FuzzParam(p
->at(i
), fuzzer
))
777 size_t count
= RandElementCount();
778 for (size_t i
= 0; i
< count
; ++i
) {
779 scoped_ptr
<cc::RenderPass
> render_pass
= cc::RenderPass::Create();
780 if (!FuzzParam(render_pass
.get(), fuzzer
))
782 p
->push_back(render_pass
.Pass());
789 struct FuzzTraits
<cc::SoftwareFrameData
> {
790 static bool Fuzz(cc::SoftwareFrameData
* p
, Fuzzer
* fuzzer
) {
791 if (!FuzzParam(&p
->id
, fuzzer
))
793 if (!FuzzParam(&p
->size
, fuzzer
))
795 if (!FuzzParam(&p
->damage_rect
, fuzzer
))
797 if (!FuzzParam(&p
->bitmap_id
, fuzzer
))
804 struct FuzzTraits
<content::IndexedDBKey
> {
805 static bool Fuzz(content::IndexedDBKey
* p
, Fuzzer
* fuzzer
) {
806 // TODO(mbarbella): Support mutation.
807 if (!fuzzer
->ShouldGenerate())
811 blink::WebIDBKeyType web_type
=
812 static_cast<blink::WebIDBKeyType
>(RandInRange(7));
814 case blink::WebIDBKeyTypeArray
: {
815 size_t length
= g_depth
> 3 ? 0 : RandInRange(4);
816 std::vector
<content::IndexedDBKey
> array
;
817 array
.resize(length
);
818 for (size_t i
= 0; i
< length
; ++i
) {
819 if (!FuzzParam(&array
[i
], fuzzer
)) {
824 *p
= content::IndexedDBKey(array
);
827 case blink::WebIDBKeyTypeBinary
: {
829 if (!FuzzParam(&binary
, fuzzer
)) {
833 *p
= content::IndexedDBKey(binary
);
836 case blink::WebIDBKeyTypeString
: {
837 base::string16 string
;
838 if (!FuzzParam(&string
, fuzzer
))
840 *p
= content::IndexedDBKey(string
);
843 case blink::WebIDBKeyTypeDate
:
844 case blink::WebIDBKeyTypeNumber
: {
846 if (!FuzzParam(&number
, fuzzer
)) {
850 *p
= content::IndexedDBKey(number
, web_type
);
853 case blink::WebIDBKeyTypeInvalid
:
854 case blink::WebIDBKeyTypeNull
: {
855 *p
= content::IndexedDBKey(web_type
);
868 struct FuzzTraits
<content::IndexedDBKeyRange
> {
869 static bool Fuzz(content::IndexedDBKeyRange
* p
, Fuzzer
* fuzzer
) {
870 content::IndexedDBKey lower
= p
->lower();
871 content::IndexedDBKey upper
= p
->upper();
872 bool lower_open
= p
->lower_open();
873 bool upper_open
= p
->upper_open();
874 if (!FuzzParam(&lower
, fuzzer
))
876 if (!FuzzParam(&upper
, fuzzer
))
878 if (!FuzzParam(&lower_open
, fuzzer
))
880 if (!FuzzParam(&upper_open
, fuzzer
))
882 *p
= content::IndexedDBKeyRange(lower
, upper
, lower_open
, upper_open
);
888 struct FuzzTraits
<content::IndexedDBKeyPath
> {
889 static bool Fuzz(content::IndexedDBKeyPath
* p
, Fuzzer
* fuzzer
) {
890 // TODO(mbarbella): Support mutation.
891 if (!fuzzer
->ShouldGenerate())
894 switch (RandInRange(3)) {
896 std::vector
<base::string16
> array
;
897 if (!FuzzParam(&array
, fuzzer
))
899 *p
= content::IndexedDBKeyPath(array
);
903 base::string16 string
;
904 if (!FuzzParam(&string
, fuzzer
))
906 *p
= content::IndexedDBKeyPath(string
);
910 *p
= content::IndexedDBKeyPath();
919 struct FuzzTraits
<content::NPIdentifier_Param
> {
920 static bool Fuzz(content::NPIdentifier_Param
* p
, Fuzzer
* fuzzer
) {
921 // TODO(mbarbella): This should actually do something.
927 struct FuzzTraits
<content::NPVariant_Param
> {
928 static bool Fuzz(content::NPVariant_Param
* p
, Fuzzer
* fuzzer
) {
929 // TODO(mbarbella): This should actually do something.
935 struct FuzzTraits
<content::PageState
> {
936 static bool Fuzz(content::PageState
* p
, Fuzzer
* fuzzer
) {
937 std::string data
= p
->ToEncodedData();
938 if (!FuzzParam(&data
, fuzzer
))
940 *p
= content::PageState::CreateFromEncodedData(data
);
946 struct FuzzTraits
<content::SyntheticGesturePacket
> {
947 static bool Fuzz(content::SyntheticGesturePacket
* p
,
949 // TODO(mbarbella): Support mutation.
950 if (!fuzzer
->ShouldGenerate())
953 scoped_ptr
<content::SyntheticGestureParams
> gesture_params
;
955 content::SyntheticGestureParams::SYNTHETIC_GESTURE_TYPE_MAX
+ 1)) {
956 case content::SyntheticGestureParams::GestureType::
957 SMOOTH_SCROLL_GESTURE
: {
958 content::SyntheticSmoothScrollGestureParams
* params
=
959 new content::SyntheticSmoothScrollGestureParams();
960 if (!FuzzParam(¶ms
->anchor
, fuzzer
))
962 if (!FuzzParam(¶ms
->distances
, fuzzer
))
964 if (!FuzzParam(¶ms
->prevent_fling
, fuzzer
))
966 if (!FuzzParam(¶ms
->speed_in_pixels_s
, fuzzer
))
968 gesture_params
.reset(params
);
971 case content::SyntheticGestureParams::GestureType::SMOOTH_DRAG_GESTURE
: {
972 content::SyntheticSmoothDragGestureParams
* params
=
973 new content::SyntheticSmoothDragGestureParams();
974 if (!FuzzParam(¶ms
->start_point
, fuzzer
))
976 if (!FuzzParam(¶ms
->distances
, fuzzer
))
978 if (!FuzzParam(¶ms
->speed_in_pixels_s
, fuzzer
))
980 gesture_params
.reset(params
);
983 case content::SyntheticGestureParams::GestureType::PINCH_GESTURE
: {
984 content::SyntheticPinchGestureParams
* params
=
985 new content::SyntheticPinchGestureParams();
986 if (!FuzzParam(¶ms
->scale_factor
, fuzzer
))
988 if (!FuzzParam(¶ms
->anchor
, fuzzer
))
990 if (!FuzzParam(¶ms
->relative_pointer_speed_in_pixels_s
,
993 gesture_params
.reset(params
);
996 case content::SyntheticGestureParams::GestureType::TAP_GESTURE
: {
997 content::SyntheticTapGestureParams
* params
=
998 new content::SyntheticTapGestureParams();
999 if (!FuzzParam(¶ms
->position
, fuzzer
))
1001 if (!FuzzParam(¶ms
->duration_ms
, fuzzer
))
1003 gesture_params
.reset(params
);
1007 p
->set_gesture_params(gesture_params
.Pass());
1013 struct FuzzTraits
<content::WebCursor
> {
1014 static bool Fuzz(content::WebCursor
* p
, Fuzzer
* fuzzer
) {
1015 content::WebCursor::CursorInfo info
;
1016 p
->GetCursorInfo(&info
);
1018 // |type| enum is not validated on de-serialization, so pick random value.
1019 if (!FuzzParam(reinterpret_cast<int*>(&info
.type
), fuzzer
))
1021 if (!FuzzParam(&info
.hotspot
, fuzzer
))
1023 if (!FuzzParam(&info
.image_scale_factor
, fuzzer
))
1025 if (!FuzzParam(&info
.custom_image
, fuzzer
))
1027 // Omitting |externalHandle| since it is not serialized.
1029 // Scale factor is expected to be greater than 0, otherwise we hit
1031 info
.image_scale_factor
= fabs(info
.image_scale_factor
) + 0.001;
1033 *p
= content::WebCursor(info
);
1039 struct FuzzTraits
<ContentSettingsPattern
> {
1040 static bool Fuzz(ContentSettingsPattern
* p
, Fuzzer
* fuzzer
) {
1041 // TODO(mbarbella): This can crash if a pattern is generated from a random
1042 // string. We could carefully generate a pattern or fix pattern generation.
1048 struct FuzzTraits
<ExtensionMsg_PermissionSetStruct
> {
1049 static bool Fuzz(ExtensionMsg_PermissionSetStruct
* p
,
1051 // TODO(mbarbella): This should actually do something.
1057 struct FuzzTraits
<extensions::URLPatternSet
> {
1058 static bool Fuzz(extensions::URLPatternSet
* p
, Fuzzer
* fuzzer
) {
1059 std::set
<URLPattern
> patterns
= p
->patterns();
1060 if (!FuzzParam(&patterns
, fuzzer
))
1062 *p
= extensions::URLPatternSet(patterns
);
1068 struct FuzzTraits
<gfx::Point
> {
1069 static bool Fuzz(gfx::Point
* p
, Fuzzer
* fuzzer
) {
1072 if (!FuzzParam(&x
, fuzzer
))
1074 if (!FuzzParam(&y
, fuzzer
))
1082 struct FuzzTraits
<gfx::PointF
> {
1083 static bool Fuzz(gfx::PointF
* p
, Fuzzer
* fuzzer
) {
1086 if (!FuzzParam(&x
, fuzzer
))
1088 if (!FuzzParam(&y
, fuzzer
))
1096 struct FuzzTraits
<gfx::Rect
> {
1097 static bool Fuzz(gfx::Rect
* p
, Fuzzer
* fuzzer
) {
1098 gfx::Point origin
= p
->origin();
1099 gfx::Size size
= p
->size();
1100 if (!FuzzParam(&origin
, fuzzer
))
1102 if (!FuzzParam(&size
, fuzzer
))
1104 p
->set_origin(origin
);
1111 struct FuzzTraits
<gfx::RectF
> {
1112 static bool Fuzz(gfx::RectF
* p
, Fuzzer
* fuzzer
) {
1113 gfx::PointF origin
= p
->origin();
1114 gfx::SizeF size
= p
->size();
1115 if (!FuzzParam(&origin
, fuzzer
))
1117 if (!FuzzParam(&size
, fuzzer
))
1119 p
->set_origin(origin
);
1126 struct FuzzTraits
<gfx::Range
> {
1127 static bool Fuzz(gfx::Range
* p
, Fuzzer
* fuzzer
) {
1128 size_t start
= p
->start();
1129 size_t end
= p
->end();
1130 if (!FuzzParam(&start
, fuzzer
))
1132 if (!FuzzParam(&end
, fuzzer
))
1134 *p
= gfx::Range(start
, end
);
1140 struct FuzzTraits
<gfx::Size
> {
1141 static bool Fuzz(gfx::Size
* p
, Fuzzer
* fuzzer
) {
1142 int width
= p
->width();
1143 int height
= p
->height();
1144 if (!FuzzParam(&width
, fuzzer
))
1146 if (!FuzzParam(&height
, fuzzer
))
1148 p
->SetSize(width
, height
);
1154 struct FuzzTraits
<gfx::SizeF
> {
1155 static bool Fuzz(gfx::SizeF
* p
, Fuzzer
* fuzzer
) {
1158 if (!FuzzParam(&w
, fuzzer
))
1160 if (!FuzzParam(&h
, fuzzer
))
1168 struct FuzzTraits
<gfx::Transform
> {
1169 static bool Fuzz(gfx::Transform
* p
, Fuzzer
* fuzzer
) {
1170 SkMScalar matrix
[16];
1171 for (size_t i
= 0; i
< arraysize(matrix
); i
++) {
1172 matrix
[i
] = p
->matrix().get(i
/ 4, i
% 4);
1174 if (!FuzzParamArray(&matrix
[0], arraysize(matrix
), fuzzer
))
1176 *p
= gfx::Transform(matrix
[0], matrix
[1], matrix
[2], matrix
[3], matrix
[4],
1177 matrix
[5], matrix
[6], matrix
[7], matrix
[8], matrix
[9],
1178 matrix
[10], matrix
[11], matrix
[12], matrix
[13],
1179 matrix
[14], matrix
[15]);
1185 struct FuzzTraits
<gfx::Vector2d
> {
1186 static bool Fuzz(gfx::Vector2d
* p
, Fuzzer
* fuzzer
) {
1189 if (!FuzzParam(&x
, fuzzer
))
1191 if (!FuzzParam(&y
, fuzzer
))
1193 *p
= gfx::Vector2d(x
, y
);
1199 struct FuzzTraits
<gfx::Vector2dF
> {
1200 static bool Fuzz(gfx::Vector2dF
* p
, Fuzzer
* fuzzer
) {
1203 if (!FuzzParam(&x
, fuzzer
))
1205 if (!FuzzParam(&y
, fuzzer
))
1207 *p
= gfx::Vector2dF(x
, y
);
1213 struct FuzzTraits
<gpu::Mailbox
> {
1214 static bool Fuzz(gpu::Mailbox
* p
, Fuzzer
* fuzzer
) {
1215 fuzzer
->FuzzBytes(p
->name
, sizeof(p
->name
));
1221 struct FuzzTraits
<gpu::MailboxHolder
> {
1222 static bool Fuzz(gpu::MailboxHolder
* p
, Fuzzer
* fuzzer
) {
1223 if (!FuzzParam(&p
->mailbox
, fuzzer
))
1225 if (!FuzzParam(&p
->texture_target
, fuzzer
))
1227 if (!FuzzParam(&p
->sync_point
, fuzzer
))
1234 struct FuzzTraits
<gpu::ValueState
> {
1235 static bool Fuzz(gpu::ValueState
* p
, Fuzzer
* fuzzer
) {
1236 if (!FuzzParamArray(&p
->float_value
[0], 4, fuzzer
))
1238 if (!FuzzParamArray(&p
->int_value
[0], 4, fuzzer
))
1245 struct FuzzTraits
<GURL
> {
1246 static bool Fuzz(GURL
* p
, Fuzzer
* fuzzer
) {
1247 if (!fuzzer
->ShouldGenerate()) {
1248 std::string spec
= p
->possibly_invalid_spec();
1249 if (!FuzzParam(&spec
, fuzzer
))
1251 if (spec
!= p
->possibly_invalid_spec())
1256 const char url_chars
[] = "Ahtp0:/.?+\\%&#";
1257 size_t count
= RandInRange(100);
1258 std::string random_url
;
1259 for (size_t i
= 0; i
< count
; ++i
)
1260 random_url
+= url_chars
[RandInRange(sizeof(url_chars
) - 1)];
1261 int selector
= RandInRange(10);
1263 random_url
= std::string("http://") + random_url
;
1264 else if (selector
== 1)
1265 random_url
= std::string("file://") + random_url
;
1266 else if (selector
== 2)
1267 random_url
= std::string("javascript:") + random_url
;
1268 else if (selector
== 2)
1269 random_url
= std::string("data:") + random_url
;
1270 *p
= GURL(random_url
);
1276 struct FuzzTraits
<HostID
> {
1277 static bool Fuzz(HostID
* p
, Fuzzer
* fuzzer
) {
1278 HostID::HostType type
= p
->type();
1279 std::string id
= p
->id();
1280 if (!FuzzParam(&type
, fuzzer
))
1282 if (!FuzzParam(&id
, fuzzer
))
1284 *p
= HostID(type
, id
);
1291 struct FuzzTraits
<HWND
> {
1292 static bool Fuzz(HWND
* p
, Fuzzer
* fuzzer
) {
1293 // TODO(aarya): This should actually do something.
1300 struct FuzzTraits
<IPC::Message
> {
1301 static bool Fuzz(IPC::Message
* p
, Fuzzer
* fuzzer
) {
1302 // TODO(mbarbella): Support mutation.
1303 if (!fuzzer
->ShouldGenerate())
1306 if (g_function_vector
.empty())
1308 size_t index
= RandInRange(g_function_vector
.size());
1309 IPC::Message
* ipc_message
= (*g_function_vector
[index
])(NULL
, fuzzer
);
1318 struct FuzzTraits
<IPC::PlatformFileForTransit
> {
1319 static bool Fuzz(IPC::PlatformFileForTransit
* p
, Fuzzer
* fuzzer
) {
1320 // TODO(inferno): I don't think we can generate real ones due to check on
1327 struct FuzzTraits
<IPC::ChannelHandle
> {
1328 static bool Fuzz(IPC::ChannelHandle
* p
, Fuzzer
* fuzzer
) {
1329 // TODO(mbarbella): Support mutation.
1330 if (!fuzzer
->ShouldGenerate())
1333 // TODO(inferno): Add way to generate real channel handles.
1335 HANDLE fake_handle
= (HANDLE
)(RandU64());
1336 p
->pipe
= IPC::ChannelHandle::PipeHandle(fake_handle
);
1338 #elif defined(OS_POSIX)
1340 FuzzParam(&p
->name
, fuzzer
) &&
1341 FuzzParam(&p
->socket
, fuzzer
);
1348 struct FuzzTraits
<LOGFONT
> {
1349 static bool Fuzz(LOGFONT
* p
, Fuzzer
* fuzzer
) {
1350 // TODO(aarya): This should actually do something.
1357 struct FuzzTraits
<media::AudioParameters
> {
1358 static bool Fuzz(media::AudioParameters
* p
, Fuzzer
* fuzzer
) {
1359 int format
= p
->format();
1360 int channel_layout
= p
->channel_layout();
1361 int sample_rate
= p
->sample_rate();
1362 int bits_per_sample
= p
->bits_per_sample();
1363 int frames_per_buffer
= p
->frames_per_buffer();
1364 int channels
= p
->channels();
1365 int effects
= p
->effects();
1366 if (!FuzzParam(&format
, fuzzer
))
1368 if (!FuzzParam(&channel_layout
, fuzzer
))
1370 if (!FuzzParam(&sample_rate
, fuzzer
))
1372 if (!FuzzParam(&bits_per_sample
, fuzzer
))
1374 if (!FuzzParam(&frames_per_buffer
, fuzzer
))
1376 if (!FuzzParam(&channels
, fuzzer
))
1378 if (!FuzzParam(&effects
, fuzzer
))
1380 media::AudioParameters
params(
1381 static_cast<media::AudioParameters::Format
>(format
),
1382 static_cast<media::ChannelLayout
>(channel_layout
), channels
,
1383 sample_rate
, bits_per_sample
, frames_per_buffer
, effects
);
1390 struct FuzzTraits
<media::VideoCaptureFormat
> {
1391 static bool Fuzz(media::VideoCaptureFormat
* p
, Fuzzer
* fuzzer
) {
1392 if (!FuzzParam(&p
->frame_size
, fuzzer
))
1394 if (!FuzzParam(&p
->frame_rate
, fuzzer
))
1396 if (!FuzzParam(reinterpret_cast<int*>(&p
->pixel_format
), fuzzer
))
1403 struct FuzzTraits
<net::LoadTimingInfo
> {
1404 static bool Fuzz(net::LoadTimingInfo
* p
, Fuzzer
* fuzzer
) {
1405 return FuzzParam(&p
->socket_log_id
, fuzzer
) &&
1406 FuzzParam(&p
->socket_reused
, fuzzer
) &&
1407 FuzzParam(&p
->request_start_time
, fuzzer
) &&
1408 FuzzParam(&p
->request_start
, fuzzer
) &&
1409 FuzzParam(&p
->proxy_resolve_start
, fuzzer
) &&
1410 FuzzParam(&p
->proxy_resolve_end
, fuzzer
) &&
1411 FuzzParam(&p
->connect_timing
.dns_start
, fuzzer
) &&
1412 FuzzParam(&p
->connect_timing
.dns_end
, fuzzer
) &&
1413 FuzzParam(&p
->connect_timing
.connect_start
, fuzzer
) &&
1414 FuzzParam(&p
->connect_timing
.connect_end
, fuzzer
) &&
1415 FuzzParam(&p
->connect_timing
.ssl_start
, fuzzer
) &&
1416 FuzzParam(&p
->connect_timing
.ssl_end
, fuzzer
) &&
1417 FuzzParam(&p
->send_start
, fuzzer
) &&
1418 FuzzParam(&p
->send_end
, fuzzer
) &&
1419 FuzzParam(&p
->receive_headers_end
, fuzzer
);
1424 struct FuzzTraits
<net::HostPortPair
> {
1425 static bool Fuzz(net::HostPortPair
* p
, Fuzzer
* fuzzer
) {
1426 std::string host
= p
->host();
1427 uint16 port
= p
->port();
1428 if (!FuzzParam(&host
, fuzzer
))
1430 if (!FuzzParam(&port
, fuzzer
))
1439 struct FuzzTraits
<net::IPEndPoint
> {
1440 static bool Fuzz(net::IPEndPoint
* p
, Fuzzer
* fuzzer
) {
1441 net::IPAddressNumber address
= p
->address();
1442 int port
= p
->port();
1443 if (!FuzzParam(&address
, fuzzer
))
1445 if (!FuzzParam(&port
, fuzzer
))
1447 net::IPEndPoint
ip_endpoint(address
, port
);
1454 struct FuzzTraits
<network_hints::LookupRequest
> {
1455 static bool Fuzz(network_hints::LookupRequest
* p
, Fuzzer
* fuzzer
) {
1456 if (!FuzzParam(&p
->hostname_list
, fuzzer
))
1464 struct FuzzTraits
<PP_Bool
> {
1465 static bool Fuzz(PP_Bool
* p
, Fuzzer
* fuzzer
) {
1466 bool tmp
= PP_ToBool(*p
);
1467 if (!FuzzParam(&tmp
, fuzzer
))
1469 *p
= PP_FromBool(tmp
);
1475 struct FuzzTraits
<PP_KeyInformation
> {
1476 static bool Fuzz(PP_KeyInformation
* p
, Fuzzer
* fuzzer
) {
1477 // TODO(mbarbella): This should actually do something.
1483 struct FuzzTraits
<PP_NetAddress_Private
> {
1484 static bool Fuzz(PP_NetAddress_Private
* p
, Fuzzer
* fuzzer
) {
1485 p
->size
= RandInRange(sizeof(p
->data
) + 1);
1486 fuzzer
->FuzzBytes(&p
->data
, p
->size
);
1492 struct FuzzTraits
<ppapi::PPB_X509Certificate_Fields
> {
1493 static bool Fuzz(ppapi::PPB_X509Certificate_Fields
* p
,
1495 // TODO(mbarbella): This should actually do something.
1501 struct FuzzTraits
<ppapi::proxy::PPBFlash_DrawGlyphs_Params
> {
1502 static bool Fuzz(ppapi::proxy::PPBFlash_DrawGlyphs_Params
* p
,
1504 // TODO(mbarbella): This should actually do something.
1510 struct FuzzTraits
<ppapi::proxy::ResourceMessageCallParams
> {
1512 ppapi::proxy::ResourceMessageCallParams
* p
, Fuzzer
* fuzzer
) {
1513 // TODO(mbarbella): Support mutation.
1514 if (!fuzzer
->ShouldGenerate())
1517 PP_Resource resource
;
1520 if (!FuzzParam(&resource
, fuzzer
))
1522 if (!FuzzParam(&sequence
, fuzzer
))
1524 if (!FuzzParam(&has_callback
, fuzzer
))
1526 *p
= ppapi::proxy::ResourceMessageCallParams(resource
, sequence
);
1528 p
->set_has_callback();
1534 struct FuzzTraits
<ppapi::proxy::ResourceMessageReplyParams
> {
1536 ppapi::proxy::ResourceMessageReplyParams
* p
, Fuzzer
* fuzzer
) {
1537 // TODO(mbarbella): Support mutation.
1538 if (!fuzzer
->ShouldGenerate())
1541 PP_Resource resource
;
1544 if (!FuzzParam(&resource
, fuzzer
))
1546 if (!FuzzParam(&sequence
, fuzzer
))
1548 if (!FuzzParam(&result
, fuzzer
))
1550 *p
= ppapi::proxy::ResourceMessageReplyParams(resource
, sequence
);
1551 p
->set_result(result
);
1557 struct FuzzTraits
<ppapi::proxy::SerializedHandle
> {
1558 static bool Fuzz(ppapi::proxy::SerializedHandle
* p
,
1560 // TODO(mbarbella): This should actually do something.
1566 struct FuzzTraits
<ppapi::proxy::SerializedFontDescription
> {
1567 static bool Fuzz(ppapi::proxy::SerializedFontDescription
* p
,
1569 // TODO(mbarbella): This should actually do something.
1575 struct FuzzTraits
<ppapi::proxy::SerializedTrueTypeFontDesc
> {
1576 static bool Fuzz(ppapi::proxy::SerializedTrueTypeFontDesc
* p
,
1578 // TODO(mbarbella): This should actually do something.
1584 struct FuzzTraits
<ppapi::proxy::SerializedVar
> {
1585 static bool Fuzz(ppapi::proxy::SerializedVar
* p
, Fuzzer
* fuzzer
) {
1586 // TODO(mbarbella): This should actually do something.
1592 struct FuzzTraits
<ppapi::HostResource
> {
1593 static bool Fuzz(ppapi::HostResource
* p
, Fuzzer
* fuzzer
) {
1594 // TODO(mbarbella): Support mutation.
1595 if (!fuzzer
->ShouldGenerate())
1598 PP_Instance instance
;
1599 PP_Resource resource
;
1600 if (!FuzzParam(&instance
, fuzzer
))
1602 if (!FuzzParam(&resource
, fuzzer
))
1604 p
->SetHostResource(instance
, resource
);
1610 struct FuzzTraits
<ppapi::PepperFilePath
> {
1611 static bool Fuzz(ppapi::PepperFilePath
*p
, Fuzzer
* fuzzer
) {
1612 // TODO(mbarbella): Support mutation.
1613 if (!fuzzer
->ShouldGenerate())
1616 unsigned domain
= RandInRange(ppapi::PepperFilePath::DOMAIN_MAX_VALID
+1);
1617 base::FilePath path
;
1618 if (!FuzzParam(&path
, fuzzer
))
1620 *p
= ppapi::PepperFilePath(
1621 static_cast<ppapi::PepperFilePath::Domain
>(domain
), path
);
1627 struct FuzzTraits
<ppapi::PpapiPermissions
> {
1628 static bool Fuzz(ppapi::PpapiPermissions
* p
, Fuzzer
* fuzzer
) {
1629 uint32_t bits
= p
->GetBits();
1630 if (!FuzzParam(&bits
, fuzzer
))
1632 *p
= ppapi::PpapiPermissions(bits
);
1638 struct FuzzTraits
<ppapi::SocketOptionData
> {
1639 static bool Fuzz(ppapi::SocketOptionData
* p
, Fuzzer
* fuzzer
) {
1640 // TODO(mbarbella): This can be improved.
1643 if (!FuzzParam(&tmp
, fuzzer
))
1651 struct FuzzTraits
<printing::PdfRenderSettings
> {
1652 static bool Fuzz(printing::PdfRenderSettings
* p
, Fuzzer
* fuzzer
) {
1653 gfx::Rect area
= p
->area();
1655 bool autorotate
= p
->autorotate();
1656 if (!FuzzParam(&area
, fuzzer
))
1658 if (!FuzzParam(&dpi
, fuzzer
))
1660 if (!FuzzParam(&autorotate
, fuzzer
))
1662 *p
= printing::PdfRenderSettings(area
, dpi
, autorotate
);
1668 struct FuzzTraits
<remoting::ScreenResolution
> {
1669 static bool Fuzz(remoting::ScreenResolution
* p
, Fuzzer
* fuzzer
) {
1670 webrtc::DesktopSize dimensions
= p
->dimensions();
1671 webrtc::DesktopVector dpi
= p
->dpi();
1672 if (!FuzzParam(&dimensions
, fuzzer
))
1674 if (!FuzzParam(&dpi
, fuzzer
))
1676 *p
= remoting::ScreenResolution(dimensions
, dpi
);
1682 struct FuzzTraits
<SkBitmap
> {
1683 static bool Fuzz(SkBitmap
* p
, Fuzzer
* fuzzer
) {
1684 // TODO(mbarbella): This should actually do something.
1690 struct FuzzTraits
<storage::DataElement
> {
1691 static bool Fuzz(storage::DataElement
* p
, Fuzzer
* fuzzer
) {
1692 // TODO(mbarbella): Support mutation.
1693 if (!fuzzer
->ShouldGenerate())
1696 switch (RandInRange(4)) {
1697 case storage::DataElement::Type::TYPE_BYTES
: {
1699 p
->SetToEmptyBytes();
1702 int data_len
= RandInRange(sizeof(data
));
1703 fuzzer
->FuzzBytes(&data
[0], data_len
);
1704 p
->SetToBytes(&data
[0], data_len
);
1708 case storage::DataElement::Type::TYPE_FILE
: {
1709 base::FilePath path
;
1712 base::Time modification_time
;
1713 if (!FuzzParam(&path
, fuzzer
))
1715 if (!FuzzParam(&offset
, fuzzer
))
1717 if (!FuzzParam(&length
, fuzzer
))
1719 if (!FuzzParam(&modification_time
, fuzzer
))
1721 p
->SetToFilePathRange(path
, offset
, length
, modification_time
);
1724 case storage::DataElement::Type::TYPE_BLOB
: {
1728 if (!FuzzParam(&uuid
, fuzzer
))
1730 if (!FuzzParam(&offset
, fuzzer
))
1732 if (!FuzzParam(&length
, fuzzer
))
1734 p
->SetToBlobRange(uuid
, offset
, length
);
1737 case storage::DataElement::Type::TYPE_FILE_FILESYSTEM
: {
1741 base::Time modification_time
;
1742 if (!FuzzParam(&url
, fuzzer
))
1744 if (!FuzzParam(&offset
, fuzzer
))
1746 if (!FuzzParam(&length
, fuzzer
))
1748 if (!FuzzParam(&modification_time
, fuzzer
))
1750 p
->SetToFileSystemUrlRange(url
, offset
, length
, modification_time
);
1762 struct FuzzTraits
<ui::LatencyInfo
> {
1763 static bool Fuzz(ui::LatencyInfo
* p
, Fuzzer
* fuzzer
) {
1764 // TODO(inferno): Add param traits for |latency_components|.
1765 int64 trace_id
= p
->trace_id();
1766 bool terminated
= p
->terminated();
1767 uint32 input_coordinates_size
= static_cast<uint32
>(
1768 RandInRange(ui::LatencyInfo::kMaxInputCoordinates
+ 1));
1769 ui::LatencyInfo::InputCoordinate
1770 input_coordinates
[ui::LatencyInfo::kMaxInputCoordinates
];
1771 if (!FuzzParamArray(
1772 input_coordinates
, input_coordinates_size
, fuzzer
))
1774 if (!FuzzParam(&trace_id
, fuzzer
))
1776 if (!FuzzParam(&terminated
, fuzzer
))
1779 ui::LatencyInfo
latency(trace_id
, terminated
);
1780 for (size_t i
= 0; i
< input_coordinates_size
; i
++) {
1781 latency
.AddInputCoordinate(input_coordinates
[i
]);
1790 struct FuzzTraits
<ui::LatencyInfo::InputCoordinate
> {
1792 ui::LatencyInfo::InputCoordinate
* p
, Fuzzer
* fuzzer
) {
1793 if (!FuzzParam(&p
->x
, fuzzer
))
1795 if (!FuzzParam(&p
->y
, fuzzer
))
1802 struct FuzzTraits
<url::Origin
> {
1803 static bool Fuzz(url::Origin
* p
, Fuzzer
* fuzzer
) {
1804 std::string scheme
= p
->scheme();
1805 std::string host
= p
->host();
1806 uint16 port
= p
->port();
1807 if (!FuzzParam(&scheme
, fuzzer
))
1809 if (!FuzzParam(&host
, fuzzer
))
1811 if (!FuzzParam(&port
, fuzzer
))
1813 *p
= url::Origin::UnsafelyCreateOriginWithoutNormalization(scheme
, host
,
1816 // Force a unique origin 1% of the time:
1817 if (RandInRange(100) == 1)
1824 struct FuzzTraits
<URLPattern
> {
1825 static bool Fuzz(URLPattern
* p
, Fuzzer
* fuzzer
) {
1826 int valid_schemes
= p
->valid_schemes();
1827 std::string host
= p
->host();
1828 std::string port
= p
->port();
1829 std::string path
= p
->path();
1830 if (!FuzzParam(&valid_schemes
, fuzzer
))
1832 if (!FuzzParam(&host
, fuzzer
))
1834 if (!FuzzParam(&port
, fuzzer
))
1836 if (!FuzzParam(&path
, fuzzer
))
1838 *p
= URLPattern(valid_schemes
);
1847 struct FuzzTraits
<webrtc::DesktopSize
> {
1848 static bool Fuzz(webrtc::DesktopSize
* p
, Fuzzer
* fuzzer
) {
1849 int32_t width
= p
->width();
1850 int32_t height
= p
->height();
1851 if (!FuzzParam(&width
, fuzzer
))
1853 if (!FuzzParam(&height
, fuzzer
))
1855 *p
= webrtc::DesktopSize(width
, height
);
1861 struct FuzzTraits
<webrtc::DesktopVector
> {
1862 static bool Fuzz(webrtc::DesktopVector
* p
, Fuzzer
* fuzzer
) {
1865 if (!FuzzParam(&x
, fuzzer
))
1867 if (!FuzzParam(&y
, fuzzer
))
1875 struct FuzzTraits
<webrtc::DesktopRect
> {
1876 static bool Fuzz(webrtc::DesktopRect
* p
, Fuzzer
* fuzzer
) {
1877 int32_t left
= p
->left();
1878 int32_t top
= p
->top();
1879 int32_t right
= p
->right();
1880 int32_t bottom
= p
->bottom();
1881 if (!FuzzParam(&left
, fuzzer
))
1883 if (!FuzzParam(&top
, fuzzer
))
1885 if (!FuzzParam(&right
, fuzzer
))
1887 if (!FuzzParam(&bottom
, fuzzer
))
1889 *p
= webrtc::DesktopRect::MakeLTRB(left
, top
, right
, bottom
);
1895 struct FuzzTraits
<webrtc::MouseCursor
> {
1896 static bool Fuzz(webrtc::MouseCursor
* p
, Fuzzer
* fuzzer
) {
1897 webrtc::DesktopVector hotspot
= p
->hotspot();
1898 if (!FuzzParam(&hotspot
, fuzzer
))
1900 p
->set_hotspot(hotspot
);
1902 // TODO(mbarbella): Find a way to handle the size mutation properly.
1903 if (!fuzzer
->ShouldGenerate())
1906 // Using a small size here to avoid OOM or overflow on image allocation.
1907 webrtc::DesktopSize
size(RandInRange(100), RandInRange(100));
1908 p
->set_image(new webrtc::BasicDesktopFrame(size
));
1913 // Redefine macros to generate generating from traits declarations.
1914 // STRUCT declarations cause corresponding STRUCT_TRAITS declarations to occur.
1915 #undef IPC_STRUCT_BEGIN
1916 #undef IPC_STRUCT_BEGIN_WITH_PARENT
1917 #undef IPC_STRUCT_MEMBER
1918 #undef IPC_STRUCT_END
1919 #define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \
1920 IPC_STRUCT_BEGIN(struct_name)
1921 #define IPC_STRUCT_BEGIN(struct_name) IPC_STRUCT_TRAITS_BEGIN(struct_name)
1922 #define IPC_STRUCT_MEMBER(type, name, ...) IPC_STRUCT_TRAITS_MEMBER(name)
1923 #define IPC_STRUCT_END() IPC_STRUCT_TRAITS_END()
1925 // Set up so next include will generate generate trait classes.
1926 #undef IPC_STRUCT_TRAITS_BEGIN
1927 #undef IPC_STRUCT_TRAITS_MEMBER
1928 #undef IPC_STRUCT_TRAITS_PARENT
1929 #undef IPC_STRUCT_TRAITS_END
1930 #define IPC_STRUCT_TRAITS_BEGIN(struct_name) \
1932 struct FuzzTraits<struct_name> { \
1933 static bool Fuzz(struct_name *p, Fuzzer* fuzzer) {
1935 #define IPC_STRUCT_TRAITS_MEMBER(name) \
1936 if (!FuzzParam(&p->name, fuzzer)) \
1939 #define IPC_STRUCT_TRAITS_PARENT(type) \
1940 if (!FuzzParam(static_cast<type*>(p), fuzzer)) \
1943 #define IPC_STRUCT_TRAITS_END() \
1948 // If |condition| isn't met, the messsge will fail to serialize. Try
1949 // increasingly smaller ranges until we find one that happens to meet
1950 // the condition, or fail trying.
1951 // TODO(mbarbella): Attempt to validate even in the mutation case.
1952 #undef IPC_ENUM_TRAITS_VALIDATE
1953 #define IPC_ENUM_TRAITS_VALIDATE(enum_name, condition) \
1955 struct FuzzTraits<enum_name> { \
1956 static bool Fuzz(enum_name* p, Fuzzer* fuzzer) { \
1957 if (!fuzzer->ShouldGenerate()) { \
1958 return FuzzParam(reinterpret_cast<int*>(p), fuzzer); \
1960 for (int shift = 30; shift; --shift) { \
1961 for (int tries = 0; tries < 2; ++tries) { \
1962 int value = RandInRange(1 << shift); \
1964 *reinterpret_cast<int*>(p) = value; \
1969 std::cerr << "failed to satisfy " << #condition << "\n"; \
1974 // Bring them into existence.
1975 #include "tools/ipc_fuzzer/message_lib/all_messages.h"
1976 #include "tools/ipc_fuzzer/message_lib/all_message_null_macros.h"
1978 // Redefine macros to generate generating funtions
1979 #undef IPC_MESSAGE_DECL
1980 #define IPC_MESSAGE_DECL(kind, type, name, in, out, ilist, olist) \
1981 IPC_##kind##_##type##_FUZZ(name, in, out, ilist, olist)
1983 #define IPC_EMPTY_CONTROL_FUZZ(name, in, out, ilist, olist) \
1984 IPC::Message* fuzzer_for_##name(IPC::Message* msg, Fuzzer* fuzzer) { \
1988 return new name(); \
1991 #define IPC_EMPTY_ROUTED_FUZZ(name, in, out, ilist, olist) \
1992 IPC::Message* fuzzer_for_##name(IPC::Message* msg, Fuzzer* fuzzer) { \
1996 return new name(RandInRange(MAX_FAKE_ROUTING_ID)); \
1999 #define IPC_ASYNC_CONTROL_FUZZ(name, in, out, ilist, olist) \
2000 IPC::Message* fuzzer_for_##name(IPC::Message* msg, Fuzzer* fuzzer) { \
2001 IPC_TUPLE_IN_##in ilist p; \
2003 name::Read(static_cast<name*>(msg), &p); \
2005 if (FuzzParam(&p, fuzzer)) { \
2006 return new name(IPC_MEMBERS_IN_##in(p)); \
2008 std::cerr << "Don't know how to handle " << #name << "\n"; \
2012 #define IPC_ASYNC_ROUTED_FUZZ(name, in, out, ilist, olist) \
2013 IPC::Message* fuzzer_for_##name(IPC::Message* msg, Fuzzer* fuzzer) { \
2014 IPC_TUPLE_IN_##in ilist p; \
2016 name::Read(static_cast<name*>(msg), &p); \
2018 if (FuzzParam(&p, fuzzer)) { \
2019 return new name(RandInRange(MAX_FAKE_ROUTING_ID) \
2021 IPC_MEMBERS_IN_##in(p)); \
2023 std::cerr << "Don't know how to handle " << #name << "\n"; \
2027 #define IPC_SYNC_CONTROL_FUZZ(name, in, out, ilist, olist) \
2028 IPC::Message* fuzzer_for_##name(IPC::Message* msg, Fuzzer* fuzzer) { \
2029 IPC_TUPLE_IN_##in ilist p; \
2030 name* real_msg = static_cast<name*>(msg); \
2031 name* new_msg = NULL; \
2033 name::ReadSendParam(real_msg, &p); \
2035 if (FuzzParam(&p, fuzzer)) { \
2036 new_msg = new name(IPC_MEMBERS_IN_##in(p) \
2037 IPC_COMMA_AND_##out(IPC_COMMA_##in) \
2038 IPC_MEMBERS_OUT_##out()); \
2040 if (real_msg && new_msg) { \
2041 MessageCracker::CopyMessageID(new_msg, real_msg); \
2043 else if (!new_msg) { \
2044 std::cerr << "Don't know how to handle " << #name << "\n"; \
2049 #define IPC_SYNC_ROUTED_FUZZ(name, in, out, ilist, olist) \
2050 IPC::Message* fuzzer_for_##name(IPC::Message* msg, Fuzzer* fuzzer) { \
2051 IPC_TUPLE_IN_##in ilist p; \
2052 name* real_msg = static_cast<name*>(msg); \
2053 name* new_msg = NULL; \
2055 name::ReadSendParam(real_msg, &p); \
2057 if (FuzzParam(&p, fuzzer)) { \
2058 new_msg = new name(RandInRange(MAX_FAKE_ROUTING_ID) \
2059 IPC_COMMA_OR_##out(IPC_COMMA_##in) \
2060 IPC_MEMBERS_IN_##in(p) \
2061 IPC_COMMA_AND_##out(IPC_COMMA_##in) \
2062 IPC_MEMBERS_OUT_##out()); \
2064 if (real_msg && new_msg) { \
2065 MessageCracker::CopyMessageID(new_msg, real_msg); \
2067 else if (!new_msg) { \
2068 std::cerr << "Don't know how to handle " << #name << "\n"; \
2073 #define MAX_FAKE_ROUTING_ID 15
2075 #define IPC_MEMBERS_IN_0(p)
2076 #define IPC_MEMBERS_IN_1(p) base::get<0>(p)
2077 #define IPC_MEMBERS_IN_2(p) base::get<0>(p), base::get<1>(p)
2078 #define IPC_MEMBERS_IN_3(p) base::get<0>(p), base::get<1>(p), base::get<2>(p)
2079 #define IPC_MEMBERS_IN_4(p) base::get<0>(p), base::get<1>(p), base::get<2>(p), \
2081 #define IPC_MEMBERS_IN_5(p) base::get<0>(p), base::get<1>(p), base::get<2>(p), \
2082 base::get<3>(p), base::get<4>(p)
2084 #define IPC_MEMBERS_OUT_0()
2085 #define IPC_MEMBERS_OUT_1() NULL
2086 #define IPC_MEMBERS_OUT_2() NULL, NULL
2087 #define IPC_MEMBERS_OUT_3() NULL, NULL, NULL
2088 #define IPC_MEMBERS_OUT_4() NULL, NULL, NULL, NULL
2089 #define IPC_MEMBERS_OUT_5() NULL, NULL, NULL, NULL, NULL
2091 #include "tools/ipc_fuzzer/message_lib/all_messages.h"
2092 #include "tools/ipc_fuzzer/message_lib/all_message_null_macros.h"
2094 void PopulateFuzzerFunctionVector(
2095 FuzzerFunctionVector
* function_vector
) {
2096 #undef IPC_MESSAGE_DECL
2097 #define IPC_MESSAGE_DECL(kind, type, name, in, out, ilist, olist) \
2098 function_vector->push_back(fuzzer_for_##name);
2099 #include "tools/ipc_fuzzer/message_lib/all_messages.h"
2102 // Redefine macros to register fuzzing functions into map.
2103 #include "tools/ipc_fuzzer/message_lib/all_message_null_macros.h"
2104 #undef IPC_MESSAGE_DECL
2105 #define IPC_MESSAGE_DECL(kind, type, name, in, out, ilist, olist) \
2106 (*map)[static_cast<uint32>(name::ID)] = fuzzer_for_##name;
2108 void PopulateFuzzerFunctionMap(FuzzerFunctionMap
* map
) {
2109 #include "tools/ipc_fuzzer/message_lib/all_messages.h"
2112 } // namespace ipc_fuzzer