JS: Calling word_wrap() with negative length causes a crash (segfault); with length of 0 causes high CPU usage & doesn't seem to finish
I found this with a build of Synchronet from May 27 (and I'm running in Linux). This was found with a JavaScript script that was calculating a length to use with word_wrap, and the length ended up negative. My script now checks the length to ensure that doesn't happen. However, I found a couple things:
- Calling word_wrap() with a negative line length causes a crash (segfault)
- Calling word_wrap() with a length of 0 seems to cause high CPU usage ('top' showed 100% CPU usage by sbbs), and it also didn't seem to finish; perhaps there's an infinite loop in this case?
To reproduce - Crash/segfault:
var aStr = "This is a string that I want to word-wrap for a test.";
var wrappedStr = word_wrap(aStr, -1);
High CPU usage/possible infinite loop:
var aStr = "This is a string that I want to word-wrap for a test.";
var wrappedStr = word_wrap(aStr, 0);