Skip to content

Commit 01ccfb7

Browse files
committed
fix ini registry handling
1 parent ff039c3 commit 01ccfb7

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

win32/registry.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,35 +70,41 @@ static int LoadDirectory(HashTable *directories, HKEY key, char *path, int path_
7070
char *name = (char*)emalloc(max_name+1);
7171
char *value = (char*)emalloc(max_value+1);
7272
DWORD name_len, type, value_len;
73-
zval data;
7473

7574
for (i = 0; i < values; i++) {
7675
name_len = max_name+1;
7776
value_len = max_value+1;
77+
78+
memset(name, '\0', max_name+1);
79+
memset(value, '\0', max_value+1);
80+
7881
if (RegEnumValue(key, i, name, &name_len, NULL, &type, value, &value_len) == ERROR_SUCCESS) {
7982
if ((type == REG_SZ) || (type == REG_EXPAND_SZ)) {
83+
zval data;
84+
8085
if (!ht) {
8186
ht = (HashTable*)malloc(sizeof(HashTable));
8287
if (!ht) {
8388
return ret;
8489
}
8590
zend_hash_init(ht, 0, NULL, ZVAL_INTERNAL_PTR_DTOR, 1);
8691
}
92+
ZVAL_PSTRINGL(&data, value, value_len-1);
8793
zend_hash_str_update(ht, name, name_len, &data);
8894
}
8995
}
9096
}
9197
if (ht) {
9298
if (parent_ht) {
9399
zend_string *index;
94-
ulong num;
100+
zend_ulong num;
95101
zval *tmpdata;
96102

97103
ZEND_HASH_FOREACH_KEY_VAL(parent_ht, num, index, tmpdata) {
98104
zend_hash_add(ht, index, tmpdata);
99105
} ZEND_HASH_FOREACH_END();
100106
}
101-
zend_hash_str_update_mem(directories, path, path_len + 1, &ht, sizeof(HashTable*));
107+
zend_hash_str_update_mem(directories, path, path_len, ht, sizeof(HashTable));
102108
ret = 1;
103109
}
104110

@@ -148,9 +154,9 @@ static int LoadDirectory(HashTable *directories, HKEY key, char *path, int path_
148154

149155
static void delete_internal_hashtable(zval *zv)
150156
{
151-
void *data = Z_PTR_P(zv);
152-
zend_hash_destroy(*(HashTable**)data);
153-
free(*(HashTable**)data);
157+
HashTable *ht = (HashTable *)Z_PTR_P(zv);
158+
zend_hash_destroy(ht);
159+
free(ht);
154160
}
155161

156162
#define RegNotifyFlags (REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_ATTRIBUTES | REG_NOTIFY_CHANGE_LAST_SET)
@@ -159,7 +165,6 @@ void UpdateIniFromRegistry(char *path)
159165
{
160166
char *p, *orig_path;
161167
int path_len;
162-
HashTable *pht;
163168

164169
if(!path) {
165170
return;
@@ -234,15 +239,16 @@ void UpdateIniFromRegistry(char *path)
234239
path_len++;
235240
}
236241
zend_str_tolower(path, path_len);
242+
237243
while (path_len >= 0) {
238-
pht = (HashTable *)zend_hash_str_find_ptr(PW32G(registry_directories), path, path_len+1);
239-
if (pht != NULL) {
240-
HashTable *ht = pht;
244+
HashTable *ht = (HashTable *)zend_hash_str_find_ptr(PW32G(registry_directories), path, path_len);
245+
246+
if (ht != NULL) {
241247
zend_string *index;
242248
zval *data;
243249

244250
ZEND_HASH_FOREACH_STR_KEY_VAL(ht, index, data) {
245-
zend_alter_ini_entry(index, Z_STR_P(data), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
251+
zend_alter_ini_entry(index, Z_STR_P(data), PHP_INI_USER, PHP_INI_STAGE_ACTIVATE);
246252
} ZEND_HASH_FOREACH_END();
247253
}
248254

0 commit comments

Comments
 (0)