You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (PHAR_G(manifest_cached) &&NULL!= (pphar=zend_hash_str_find_ptr(&cached_phars, newpath, phar->fname_len))) {
2123
-
efree(oldpath);
2124
2123
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Unable to add newly converted phar \"%s\" to the list of phars, new phar name is in phar.cache_list", phar->fname);
2125
-
returnNULL;
2124
+
goto err_oldpath;
2126
2125
}
2127
2126
2128
2127
if (NULL!= (pphar=zend_hash_str_find_ptr(&(PHAR_G(phar_fname_map)), newpath, phar->fname_len))) {
/* FIX: GH-10755 Double-free issue caught by ASAN check */
2138
-
pphar->alias=phar->alias; /* Transfer alias to pphar to */
2139
-
phar->alias=NULL; /* avoid being free'd twice */
2136
+
/* The alias is not owned by the phar, so set it to NULL to avoid freeing it. */
2137
+
phar->alias=NULL;
2140
2138
phar_destroy_phar_data(phar);
2141
2139
*sphar=NULL;
2142
2140
phar=pphar;
2141
+
/* NOTE: this phar is now reused, so the refcount must be increased. */
2142
+
phar->refcount++;
2143
2143
newpath=oldpath;
2144
2144
goto its_ok;
2145
2145
}
2146
2146
}
2147
2147
2148
-
efree(oldpath);
2149
2148
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Unable to add newly converted phar \"%s\" to the list of phars, a phar with that name already exists", phar->fname);
2150
-
returnNULL;
2149
+
goto err_oldpath;
2151
2150
}
2152
2151
its_ok:
2153
2152
if (SUCCESS==php_stream_stat_path(newpath, &ssb)) {
2154
2153
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "phar \"%s\" exists and must be unlinked prior to conversion", newpath);
2155
-
efree(oldpath);
2156
-
returnNULL;
2154
+
goto err_reused_oldpath;
2157
2155
}
2158
2156
if (!phar->is_data) {
2159
2157
if (SUCCESS!=phar_detect_phar_fname_ext(newpath, phar->fname_len, (constchar**) &(phar->ext), &ext_len, 1, 1, 1)) {
2160
-
efree(oldpath);
2161
2158
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "phar \"%s\" has invalid extension %s", phar->fname, ext);
2162
-
returnNULL;
2159
+
goto err_reused_oldpath;
2163
2160
}
2164
2161
phar->ext_len=ext_len;
2165
2162
2166
-
if (phar->alias) {
2163
+
/* If we are reusing a phar, then the aliases should be already set up correctly,
2164
+
* and so we should not clear out the alias information.
2165
+
* This would also leak memory because, unlike the non-reuse path, we actually own the alias memory. */
0 commit comments