Skip to content

Commit 376e545

Browse files
Merge branch 'fpmConfFix' of github.com:DaveRandom/php-src
2 parents f07b41b + 9ad8e89 commit 376e545

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

sapi/fpm/fpm/fpm_conf.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,8 @@ static void fpm_conf_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback
14761476
int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */
14771477
{
14781478
int error = 0;
1479-
char buf[1024+1];
1479+
char *buf = NULL, *newbuf = NULL;
1480+
int bufsize = 0;
14801481
int fd, n;
14811482
int nb_read = 1;
14821483
char c = '*';
@@ -1503,19 +1504,35 @@ int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */
15031504
ini_lineno = 0;
15041505
while (nb_read > 0) {
15051506
int tmp;
1506-
memset(buf, 0, sizeof(char) * (1024 + 1));
1507-
for (n = 0; n < 1024 && (nb_read = read(fd, &c, sizeof(char))) == sizeof(char) && c != '\n'; n++) {
1507+
ini_lineno++;
1508+
ini_filename = filename;
1509+
for (n = 0; (nb_read = read(fd, &c, sizeof(char))) == sizeof(char) && c != '\n'; n++) {
1510+
if (n == bufsize) {
1511+
newbuf = (char*) realloc(buf, sizeof(char) * (bufsize + 1024 + 1));
1512+
if (newbuf == NULL) {
1513+
ini_recursion--;
1514+
close(fd);
1515+
free(buf);
1516+
return -1;
1517+
}
1518+
buf = newbuf;
1519+
memset(buf + ((bufsize + 1) * sizeof(char)), 0, sizeof(char) * 1024);
1520+
bufsize += 1024;
1521+
}
1522+
15081523
buf[n] = c;
15091524
}
1525+
if (n == 0) {
1526+
continue;
1527+
}
15101528
buf[n++] = '\n';
1511-
ini_lineno++;
1512-
ini_filename = filename;
15131529
tmp = zend_parse_ini_string(buf, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t)fpm_conf_ini_parser, &error TSRMLS_CC);
15141530
ini_filename = filename;
15151531
if (error || tmp == FAILURE) {
15161532
if (ini_include) free(ini_include);
15171533
ini_recursion--;
15181534
close(fd);
1535+
free(buf);
15191536
return -1;
15201537
}
15211538
if (ini_include) {
@@ -1527,11 +1544,14 @@ int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */
15271544
free(tmp);
15281545
ini_recursion--;
15291546
close(fd);
1547+
free(buf);
15301548
return -1;
15311549
}
15321550
free(tmp);
15331551
}
1552+
memset(buf, 0, sizeof(char) * (bufsize + 1));
15341553
}
1554+
free(buf);
15351555

15361556
ini_recursion--;
15371557
close(fd);

0 commit comments

Comments
 (0)