Skip to content

Commit 281676d

Browse files
committed
MFB: fix php_value application order for Apache
1 parent 24e7e62 commit 281676d

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

sapi/apache/mod_php5.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,11 +745,11 @@ static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, php_per_di
745745
return 1; /* does not exist in dest, copy from source */
746746
}
747747

748-
if (new_per_dir_entry->type==PHP_INI_SYSTEM
749-
&& orig_per_dir_entry->type!=PHP_INI_SYSTEM) {
750-
return 1;
751-
} else {
748+
if (orig_per_dir_entry->type==PHP_INI_SYSTEM
749+
&& new_per_dir_entry->type!=PHP_INI_SYSTEM) {
752750
return 0;
751+
} else {
752+
return 1;
753753
}
754754
}
755755
/* }}} */
@@ -786,9 +786,9 @@ static void *php_merge_dir(pool *p, void *basev, void *addv)
786786

787787
/* need a copy of addv to merge */
788788
new = php_create_dir(p, "php_merge_dir");
789-
zend_hash_copy(new, (HashTable *) addv, (copy_ctor_func_t) copy_per_dir_entry, NULL, sizeof(php_per_dir_entry));
789+
zend_hash_copy(new, (HashTable *) basev, (copy_ctor_func_t) copy_per_dir_entry, NULL, sizeof(php_per_dir_entry));
790790

791-
zend_hash_merge_ex(new, (HashTable *) basev, (copy_ctor_func_t) copy_per_dir_entry, sizeof(php_per_dir_entry), (merge_checker_func_t) should_overwrite_per_dir_entry, NULL);
791+
zend_hash_merge_ex(new, (HashTable *) addv, (copy_ctor_func_t) copy_per_dir_entry, sizeof(php_per_dir_entry), (merge_checker_func_t) should_overwrite_per_dir_entry, NULL);
792792
return new;
793793
}
794794
/* }}} */

sapi/apache2handler/apache_config.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ static const char *php_apache_phpini_set(cmd_parms *cmd, void *mconfig, const ch
117117
return NULL;
118118
}
119119

120+
static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, php_dir_entry *new_per_dir_entry, zend_hash_key *hash_key, void *pData)
121+
{
122+
php_dir_entry *orig_per_dir_entry;
123+
124+
if (zend_hash_find(target_ht, hash_key->arKey, hash_key->nKeyLength, (void **) &orig_per_dir_entry)==FAILURE) {
125+
return 1; /* does not exist in dest, copy from source */
126+
}
127+
128+
if (new_per_dir_entry->status >= orig_per_dir_entry->status) {
129+
/* use new entry */
130+
phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", hash_key->arKey, new_per_dir_entry->status, orig_per_dir_entry->status));
131+
return 1;
132+
} else {
133+
return 0;
134+
}
135+
}
136+
120137

121138
void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
122139
{
@@ -128,9 +145,12 @@ void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
128145
ulong num_index;
129146

130147
n = create_php_config(p, "merge_php_config");
131-
zend_hash_copy(&n->config, &e->config, NULL, NULL, sizeof(php_dir_entry));
132-
148+
/* copy old config */
149+
zend_hash_copy(&n->config, &d->config, NULL, NULL, sizeof(php_dir_entry));
150+
/* merge new config */
133151
phpapdebug((stderr, "Merge dir (%p)+(%p)=(%p)\n", base_conf, new_conf, n));
152+
zend_hash_merge_ex(&n->config, &e->config, NULL, sizeof(php_dir_entry), (merge_checker_func_t) should_overwrite_per_dir_entry, NULL);
153+
#if STAS_0
134154
for (zend_hash_internal_pointer_reset(&d->config);
135155
zend_hash_get_current_key_ex(&d->config, &str, &str_len,
136156
&num_index, 0, NULL) == HASH_KEY_IS_STRING;
@@ -140,10 +160,10 @@ void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
140160
if (zend_hash_find(&n->config, str, str_len, (void **) &pe) == SUCCESS) {
141161
if (pe->status >= data->status) continue;
142162
}
143-
zend_hash_update(&n->config, str, str_len, data, sizeof(*data), NULL);
144163
phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str, data->status, pe?pe->status:-1));
164+
zend_hash_update(&n->config, str, str_len, data, sizeof(*data), NULL);
145165
}
146-
166+
#endif
147167
return n;
148168
}
149169

0 commit comments

Comments
 (0)