1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_dom_MessageManagerFuzzer_h__
8 #define mozilla_dom_MessageManagerFuzzer_h__
9 
10 #include "jspubtd.h"
11 #include "nsAString.h"
12 #include "nsTArray.h"
13 
14 namespace mozilla {
15 namespace dom {
16 
17 namespace ipc {
18 class StructuredCloneData;
19 }
20 
21 /*
22 Exposed environment variables:
23 MESSAGEMANAGER_FUZZER_ENABLE=1
24 MESSAGEMANAGER_FUZZER_ENABLE_LOGGING=1 (optional)
25 MESSAGEMANAGER_FUZZER_MUTATION_PROBABILITY=2 (optional)
26 MESSAGEMANAGER_FUZZER_STRINGSFILE=<path> (optional)
27 MESSAGEMANAGER_FUZZER_BLACKLIST=<path> (optional)
28 */
29 
30 #ifdef IsLoggingEnabled
31 // This is defined in the Windows SDK urlmon.h
32 #  undef IsLoggingEnabled
33 #endif
34 
35 class MessageManagerFuzzer {
36  public:
37   static void TryMutate(JSContext* aCx, const nsAString& aMessageName,
38                         ipc::StructuredCloneData* aData,
39                         const JS::Value& aTransfer);
40 
41  private:
42   static void ReadFile(const char* path, nsTArray<nsCString>& aArray);
43   static nsCString GetFuzzValueFromFile();
44   static bool IsMessageNameBlacklisted(const nsAString& aMessageName);
45   static bool Mutate(JSContext* aCx, const nsAString& aMessageName,
46                      ipc::StructuredCloneData* aData,
47                      const JS::Value& aTransfer);
48   static void Mutate(JSContext* aCx, JS::Rooted<JS::Value>& aMutation);
49   static void MutateObject(JSContext* aCx, JS::HandleValue aValue,
50                            unsigned short int aRecursionCounter);
51   static bool MutateValue(JSContext* aCx, JS::HandleValue aValue,
52                           JS::MutableHandleValue aOutMutationValue,
53                           unsigned short int aRecursionCounter);
54   static unsigned int DefaultMutationProbability();
55   static nsAutoString ReadJSON(JSContext* aCx, const JS::Value& aJSON);
56   static bool IsEnabled();
57   static bool IsLoggingEnabled();
58 };
59 
60 }  // namespace dom
61 }  // namespace mozilla
62 
63 #endif
64