Skip to content

Conversation

@niklabh
Copy link

@niklabh niklabh commented Feb 5, 2014

This code will run in an infinite loop eventually taking all memory and killing the node process (Allocation failed - process out of memory):

var ejs = require('ejs');
var ejsOpts = {
  open: '{{',
  close: '}}'
};
var template = " {{=nik }";
console.log("start");
var compiled = ejs.compile(template, ejsOpts);
console.log("compiled", compiled);

The problem is at file lib/ejs.js line 144,173 (prase function)
end becomes -1 and i(loop counter) always getting set to 1, and the for loop never ends.

This fix solves it because now ejs will throw an error when template being compiled is unescaped rather than going into infinite loop.

@samsonjs
Copy link

Was just about to submit an issue for this. I made a stupid typo and hit this, reduced code:

ejs = require('ejs')
s = '<h1>oops</h1> <%- foo ->'
ejs.compile(s)

Confirm that the fix works.

@niklabh Might be worth adding a test for this.

jtsay362 added a commit to jtsay362/ejs-no-node that referenced this pull request Mar 14, 2014
Original commit message: Fixed infinite loop problem in parse for unescaped ejs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants