Ticket #221: local_files.diff

File local_files.diff, 2.8 KB (added by thomasb, 5 years ago)
  • xcache-1.2.2

    old new  
    652652    xc_entry_unholds_real(XG(var_holds), xc_var_caches, xc_var_hcache.size TSRMLS_CC); 
    653653} 
    654654/* }}} */ 
    655 static int xc_stat(const char *filename, const char *include_path, struct stat *pbuf TSRMLS_DC) /* {{{ */ 
     655static int xc_stat(const char *filename, const char *include_path, char *full_path, struct stat *pbuf TSRMLS_DC) /* {{{ */ 
    656656{ 
    657657    char filepath[MAXPATHLEN]; 
    658658    char *paths, *path; 
     
    660660    int size = strlen(include_path) + 1; 
    661661    char tokens[] = { DEFAULT_DIR_SEPARATOR, '\0' }; 
    662662 
    663     paths = (char *)do_alloca(size); 
    664     memcpy(paths, include_path, size); 
     663    if (zend_is_executing(TSRMLS_C)) { 
     664        char *exec_fname = zend_get_executed_filename(TSRMLS_C); 
     665        int exec_fname_length = strlen(exec_fname); 
     666        int path_length = strlen(include_path); 
     667 
     668        while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length])); 
     669        if ((exec_fname && exec_fname[0] == '[') 
     670            || exec_fname_length<=0) { 
     671            /* [no active file] or no path */ 
     672            paths = (char *)do_alloca(size); 
     673            memcpy(paths, include_path, size); 
     674        } else { 
     675            paths = (char *) do_alloca(exec_fname_length + path_length +1 +1); 
     676            memcpy(paths, include_path, path_length); 
     677            paths[path_length] = DEFAULT_DIR_SEPARATOR; 
     678            memcpy(paths+path_length+1, exec_fname, exec_fname_length); 
     679            paths[path_length + exec_fname_length +1] = '\0'; 
     680        } 
     681    } else { 
     682        paths = (char *)do_alloca(size); 
     683        memcpy(paths, include_path, size); 
     684    } 
    665685 
    666686    for (path = php_strtok_r(paths, tokens, &tokbuf); path; path = php_strtok_r(NULL, tokens, &tokbuf)) { 
    667687        if (snprintf(filepath, sizeof(filepath), "%s/%s", path, filename) >= MAXPATHLEN - 1) { 
    668688            continue; 
    669689        } 
    670690        if (VCWD_STAT(filepath, pbuf) == 0) { 
     691            if (full_path) { 
     692                memcpy(full_path, filepath, strlen(filepath) + 1); 
     693            } 
    671694            free_alloca(paths); 
    672695            return 0; 
    673696        } 
     
    719742    xc_entry_data_php_t *php; 
    720743    char *ptr; 
    721744    time_t delta; 
     745    char real_name_buffer[MAXPATHLEN]; 
     746    int real_name = 0; 
    722747 
    723748    if (!filename || !SG(request_info).path_translated) { 
    724749        return 0; 
     
    762787not_relative_path: 
    763788 
    764789        /* use include_path */ 
    765         if (xc_stat(filename, PG(include_path), pbuf TSRMLS_CC) != 0) {    
     790        if (xc_stat(filename, PG(include_path), real_name_buffer, pbuf TSRMLS_CC) != 0) {    
    766791            return 0; 
    767792        } 
     793        real_name = 1; 
    768794 
    769795        /* fall */ 
    770796 
     
    795821#endif 
    796822    { 
    797823        /* hash on filename, let's expand it to real path */ 
    798         filename = expand_filepath(filename, opened_path_buffer TSRMLS_CC); 
     824        if (!real_name) { 
     825            filename = expand_filepath(filename, opened_path_buffer TSRMLS_CC); 
     826        } else { 
     827            filename = expand_filepath(real_name_buffer, opened_path_buffer TSRMLS_CC); 
     828        } 
     829 
    799830        if (filename == NULL) { 
    800831            return 0; 
    801832        }