Skip to content

Commit fef63cd

Browse files
author
Ilia Alshanetsky
committed
MFB51: Added overflow checks to wordwrap() function.
1 parent 78aed20 commit fef63cd

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

ext/standard/string.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,12 +866,13 @@ PHP_FUNCTION(wordwrap)
866866
/* Multiple character line break or forced cut */
867867
if (linelength > 0) {
868868
chk = (int)(textlen/linelength + 1);
869+
newtext = safe_emalloc(chk, breakcharlen, textlen + 1);
869870
alloced = textlen + chk * breakcharlen + 1;
870871
} else {
871872
chk = textlen;
872873
alloced = textlen * (breakcharlen + 1) + 1;
874+
newtext = safe_emalloc(textlen, (breakcharlen + 1), 1);
873875
}
874-
newtext = emalloc(alloced);
875876

876877
/* now keep track of the actual new text length */
877878
newtextlen = 0;

0 commit comments

Comments
 (0)