Skip to content

Commit 9ad8e89

Browse files
committed
Allow unlimited line length in fpm config files
Fixes bug #65933
1 parent cb47396 commit 9ad8e89

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
@@ -1465,7 +1465,8 @@ static void fpm_conf_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback
14651465
int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */
14661466
{
14671467
int error = 0;
1468-
char buf[1024+1];
1468+
char *buf = NULL, *newbuf = NULL;
1469+
int bufsize = 0;
14691470
int fd, n;
14701471
int nb_read = 1;
14711472
char c = '*';
@@ -1492,19 +1493,35 @@ int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */
14921493
ini_lineno = 0;
14931494
while (nb_read > 0) {
14941495
int tmp;
1495-
memset(buf, 0, sizeof(char) * (1024 + 1));
1496-
for (n = 0; n < 1024 && (nb_read = read(fd, &c, sizeof(char))) == sizeof(char) && c != '\n'; n++) {
1496+
ini_lineno++;
1497+
ini_filename = filename;
1498+
for (n = 0; (nb_read = read(fd, &c, sizeof(char))) == sizeof(char) && c != '\n'; n++) {
1499+
if (n == bufsize) {
1500+
newbuf = (char*) realloc(buf, sizeof(char) * (bufsize + 1024 + 1));
1501+
if (newbuf == NULL) {
1502+
ini_recursion--;
1503+
close(fd);
1504+
free(buf);
1505+
return -1;
1506+
}
1507+
buf = newbuf;
1508+
memset(buf + ((bufsize + 1) * sizeof(char)), 0, sizeof(char) * 1024);
1509+
bufsize += 1024;
1510+
}
1511+
14971512
buf[n] = c;
14981513
}
1514+
if (n == 0) {
1515+
continue;
1516+
}
14991517
buf[n++] = '\n';
1500-
ini_lineno++;
1501-
ini_filename = filename;
15021518
tmp = zend_parse_ini_string(buf, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t)fpm_conf_ini_parser, &error TSRMLS_CC);
15031519
ini_filename = filename;
15041520
if (error || tmp == FAILURE) {
15051521
if (ini_include) free(ini_include);
15061522
ini_recursion--;
15071523
close(fd);
1524+
free(buf);
15081525
return -1;
15091526
}
15101527
if (ini_include) {
@@ -1516,11 +1533,14 @@ int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */
15161533
free(tmp);
15171534
ini_recursion--;
15181535
close(fd);
1536+
free(buf);
15191537
return -1;
15201538
}
15211539
free(tmp);
15221540
}
1541+
memset(buf, 0, sizeof(char) * (bufsize + 1));
15231542
}
1543+
free(buf);
15241544

15251545
ini_recursion--;
15261546
close(fd);

0 commit comments

Comments
 (0)