Skip to content

Commit e97f733

Browse files
author
Andrei Zmievski
committed
Adding ability to refer to existing .ini variables from within .ini
files. Example: open_basedir = ${open_basedir} ":/new/dir"
1 parent 5b4dc50 commit e97f733

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

Zend/zend_ini_parser.y

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ void zend_ini_do_op(char type, zval *result, zval *op1, zval *op2)
9292
result->type = IS_STRING;
9393
}
9494

95+
void zend_ini_init_string(zval *result)
96+
{
97+
result->value.str.val = malloc(1);
98+
result->value.str.val[0] = 0;
99+
result->value.str.len = 0;
100+
result->type = IS_STRING;
101+
}
102+
103+
void zend_ini_add_string(zval *result, zval *op1, zval *op2)
104+
{
105+
int length = op1->value.str.len + op2->value.str.len;
106+
107+
result->value.str.val = (char *) realloc(op1->value.str.val, length+1);
108+
memcpy(result->value.str.val+op1->value.str.len, op2->value.str.val, op2->value.str.len);
109+
result->value.str.val[length] = 0;
110+
result->value.str.len = length;
111+
result->type = IS_STRING;
112+
}
95113

96114
void zend_ini_get_constant(zval *result, zval *name)
97115
{
@@ -112,6 +130,20 @@ void zend_ini_get_constant(zval *result, zval *name)
112130
}
113131
}
114132

133+
void zend_ini_get_var(zval *result, zval *name)
134+
{
135+
zval curval;
136+
char *envvar;
137+
TSRMLS_FETCH();
138+
139+
if (zend_get_configuration_directive(name->value.str.val, name->value.str.len+1, &curval) == SUCCESS) {
140+
result->value.str.val = zend_strndup(curval.value.str.val, curval.value.str.len);
141+
result->value.str.len = curval.value.str.len;
142+
} else {
143+
zend_ini_init_string(result);
144+
}
145+
}
146+
115147

116148
static void ini_error(char *str)
117149
{
@@ -175,6 +207,7 @@ int zend_parse_ini_file(zend_file_handle *fh, zend_bool unbuffered_errors, zend_
175207
%token SECTION
176208
%token CFG_TRUE
177209
%token CFG_FALSE
210+
%token TC_DOLLAR_CURLY
178211
%left '|' '&'
179212
%right '~' '!'
180213

@@ -210,13 +243,25 @@ statement:
210243

211244
string_or_value:
212245
expr { $$ = $1; }
213-
| TC_ENCAPSULATED_STRING { $$ = $1; }
214246
| CFG_TRUE { $$ = $1; }
215247
| CFG_FALSE { $$ = $1; }
216-
| '\n' { $$.value.str.val = strdup(""); $$.value.str.len=0; $$.type = IS_STRING; }
217-
| /* empty */ { $$.value.str.val = strdup(""); $$.value.str.len=0; $$.type = IS_STRING; }
248+
| var_string_list { $$ = $1; }
249+
| '\n' { zend_ini_init_string(&$$); }
250+
| /* empty */ { zend_ini_init_string(&$$); }
218251
;
219252

253+
254+
var_string_list:
255+
var_string_list cfg_var_ref { zend_ini_add_string(&$$, &$1, &$2); free($2.value.str.val); }
256+
| var_string_list TC_ENCAPSULATED_STRING { zend_ini_add_string(&$$, &$1, &$2); }
257+
| var_string_list constant_string { zend_ini_add_string(&$$, &$1, &$2); }
258+
| /* empty */ { zend_ini_init_string(&$$); }
259+
260+
261+
cfg_var_ref:
262+
TC_DOLLAR_CURLY TC_STRING '}' { zend_ini_get_var(&$$, &$2); }
263+
264+
220265
expr:
221266
constant_string { $$ = $1; }
222267
| expr '|' expr { zend_ini_do_op('|', &$$, &$1, &$3); }

Zend/zend_ini_scanner.l

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,20 @@ NEWLINE ("\r"|"\n"|"\r\n")
153153
return TC_ENCAPSULATED_STRING;
154154
}
155155

156-
<INITIAL>[&|~()!] {
156+
<INITIAL>[&|~$(){}!] {
157157
return yytext[0];
158158
}
159159

160+
<INITIAL>"${" {
161+
return TC_DOLLAR_CURLY;
162+
}
163+
164+
<INITIAL>"}" {
165+
ini_lval->value.lval = (long) yytext[0];
166+
return yytext[0];
167+
}
160168

161-
<INITIAL>[^=\n\r\t;|&~()!"\[]+ {
169+
<INITIAL>[^=\n\r\t;|&$~(){}!"\[]+ {
162170
/* STRING */
163171
register int i;
164172

@@ -190,8 +198,6 @@ NEWLINE ("\r"|"\n"|"\r\n")
190198
}
191199
}
192200

193-
194-
195201
<INITIAL>[=\n] {
196202
if (yytext[0] == '\n') {
197203
SCNG(lineno)++;

0 commit comments

Comments
 (0)