Skip to content

Commit

Permalink
Merge pull request from GHSA-4q6p-r6v2-jvc5
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus authored Sep 26, 2023
1 parent 1436af2 commit f934b22
Show file tree
Hide file tree
Showing 3 changed files with 9,027 additions and 6,174 deletions.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

const { toString } = Function.prototype;
const functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*/)]+\*\/\s*)*([^\s(/]+)/;
const maxFunctionSourceLength = 512;
function getFuncName(aFunc) {
if (typeof aFunc !== 'function') {
return null;
Expand All @@ -22,6 +23,12 @@ function getFuncName(aFunc) {
if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') {
// Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
// eslint-disable-next-line prefer-reflect
const functionSource = toString.call(aFunc);
// To avoid unconstrained resource consumption due to pathalogically large function names,
// we limit the available return value to be less than 512 characters.
if (functionSource.indexOf('(') > maxFunctionSourceLength) {
return name;
}
const match = toString.call(aFunc).match(functionNameMatch);
if (match) {
[ name ] = match;
Expand Down
Loading

0 comments on commit f934b22

Please sign in to comment.