Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding webIDL sources to preferences #2

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions dom/bindings/Codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,40 @@
NEW_ENUMERATE_HOOK_NAME = "_newEnumerate"
ENUM_ENTRY_VARIABLE_NAME = "strings"
INSTANCE_RESERVED_SLOTS = 1
PREFERENCE_PREFIX = "tainting.source."


# This size is arbitrary. It is a power of 2 to make using it as a modulo
# operand cheap, and is usually around 1/3-1/5th of the set size (sometimes
# smaller for very large sets).
GLOBAL_NAMES_PHF_SIZE = 256

def format_preference_entry(taintSource):
return "%s%s" % (PREFERENCE_PREFIX, taintSource)

def format_preference(taintSource):
return (
"pref(\"%s\", true);"
% (format_preference_entry(taintSource))
)

def maybe_add_preference(taintSource):
import pathlib
root = pathlib.Path(__file__).parent.parent.parent.resolve()
prefs = root / 'modules' / 'libpref' / 'init' / 'all.js'
prefs = prefs.resolve()
if(prefs.exists()):
preference_entry = format_preference_entry(taintSource)
with prefs.open(mode='r+') as pf:
if preference_entry in pf.read():
print("%s already defined in %s... Skipping...\n" % (preference_entry, prefs))
else:
pf.write("%s\n" % (format_preference(taintSource)))
print("Added preference '%s' to '%s'..\n" % (preference_entry, prefs))
return True
else:
print("Preference file does not exist: %s!\n"% prefs)
return False

def memberReservedSlot(member, descriptor):
return (
Expand Down Expand Up @@ -7823,6 +7851,7 @@ def _setValue(value, wrapAsType=None, setter="set"):
# Attach taint metadata to the return value if it is a source
if taintSource is not None:
print("Generating taint source:", taintSource)
maybe_add_preference(taintSource)
taintHandler = dedent(
(
"""
Expand All @@ -7846,6 +7875,7 @@ def wrapAndSetPtr(wrapCall, failureCode=None):
markTaintSnippet = ""
if taintSource is not None:
print("Generating taint source for wrapped value:", taintSource)
maybe_add_preference(taintSource)
markTaintSnippet = dedent(
f"""
// Add taint source for wrapped value
Expand Down Expand Up @@ -11189,6 +11219,7 @@ def definition_body(self):
markTaintSnippet = ""
if self.taintSource is not None:
print("Generating taint source for cached value:", self.taintSource)
maybe_add_preference(self.taintSource)
markTaintSnippet = dedent(
f"""
// Add taint source for cached value
Expand Down