Skip to content

Commit 65ed5fb

Browse files
mi-acV8-internal LUCI CQ
authored andcommitted
Work-around false-positive leak reports for regular expressions
Fixed: 496097209 Change-Id: Icb0f88bcf619791fa3a45af7f0f2cd73428d37df Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9141456 Auto-Submit: Michael Achenbach <machenbach@google.com> Commit-Queue: Matthias Liedtke <mliedtke@google.com> Reviewed-by: Matthias Liedtke <mliedtke@google.com>
1 parent 6c0c847 commit 65ed5fb

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

Sources/Fuzzilli/Environment/JavaScriptEnvironment.swift

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -318,34 +318,30 @@ public class JavaScriptEnvironment: ComponentBase {
318318
private var producingProperties: [ILType: [(group: String, property: String)]] = [:]
319319
private var subtypes: [ILType: [ILType]] = [:]
320320

321-
private let validIdentifierOrIndex: Regex<AnyRegexOutput>?
322-
private let validDotNotationName: Regex<AnyRegexOutput>?
323-
private let validPropertyIndex: Regex<AnyRegexOutput>?
324-
325-
public init(additionalBuiltins: [String: ILType] = [:], additionalObjectGroups: [ObjectGroup] = [], additionalEnumerations: [ILType] = []) {
321+
private struct ValidationRegexes {
326322
// A simple approximation of a valid JS identifier (used in dot
327323
// notation and for property and method names).
328-
let simpleId = "[_$a-zA-Z][_$a-zA-Z0-9]*"
324+
static let simpleId = "[_$a-zA-Z][_$a-zA-Z0-9]*"
329325

330326
// A non-negative integer (with no leading zero) for index access
331327
// without quotes.
332-
let index = "[1-9]\\d*|0"
333-
334-
// Initialize regular expressions to determine valid property
335-
// identifiers:
328+
static let index = "[1-9]\\d*|0"
336329

337330
// We support simple identifiers and non-negative numbers. Other
338331
// names will be quoted.
339332
// We don't support unquoted doubles.
340-
self.validIdentifierOrIndex = try! Regex("^(\(index)|\(simpleId))$")
333+
static let identifierOrIndex = try! Regex("^(\(index)|\(simpleId))$")
341334

342335
// For dot notation we only support simple identifiers. We don't
343336
// support all possible names according to JS spec.
344337
// Unsupported names will be accessed with bracket notation.
345-
self.validDotNotationName = try! Regex("^(\(simpleId))$")
338+
static let dotNotationName = try! Regex("^(\(simpleId))$")
346339

347340
// Valid indexes to use in bracket notation without quotes.
348-
self.validPropertyIndex = try! Regex("^(\(index))$")
341+
static let propertyIndex = try! Regex("^(\(index))$")
342+
}
343+
344+
public init(additionalBuiltins: [String: ILType] = [:], additionalObjectGroups: [ObjectGroup] = [], additionalEnumerations: [ILType] = []) {
349345

350346
super.init(name: "JavaScriptEnvironment")
351347

@@ -1005,15 +1001,15 @@ public class JavaScriptEnvironment: ComponentBase {
10051001
}
10061002

10071003
func isValidIdentifierOrIndex(_ name: String) -> Bool {
1008-
return (try? validIdentifierOrIndex?.wholeMatch(in: name)) != nil
1004+
return (try? ValidationRegexes.identifierOrIndex.wholeMatch(in: name)) != nil
10091005
}
10101006

10111007
func isValidDotNotationName(_ name: String) -> Bool {
1012-
return (try? validDotNotationName?.wholeMatch(in: name)) != nil
1008+
return (try? ValidationRegexes.dotNotationName.wholeMatch(in: name)) != nil
10131009
}
10141010

10151011
func isValidPropertyIndex(_ name: String) -> Bool {
1016-
return (try? validPropertyIndex?.wholeMatch(in: name)) != nil
1012+
return (try? ValidationRegexes.propertyIndex.wholeMatch(in: name)) != nil
10171013
}
10181014
}
10191015

0 commit comments

Comments
 (0)