Esempio n. 1
0
Area RectT<T>::getInteriorArea() const
{
	RectT<T> canon = canonicalized();
	
	return Area( static_cast<int32_t>( ceil( canon.x1 ) ), static_cast<int32_t>( ceil( canon.y1 ) ), 
		static_cast<int32_t>( floor( canon.x2 ) ) + 1, static_cast<int32_t>( floor( canon.y2 ) ) + 1 );
}
Esempio n. 2
0
String File::TranslatePath(CStrRef filename, bool useFileCache /* = false */,
                           bool keepRelative /*= false */) {
  String canonicalized(Util::canonicalize(filename.data(),
                                          filename.size()), AttachString);

  if (useFileCache) {
    String translated = TranslatePath(canonicalized, false);
    if (!translated.empty() && access(translated.data(), F_OK) < 0 &&
        StaticContentCache::TheFileCache) {
      if (StaticContentCache::TheFileCache->exists(canonicalized.data(),
                                                   false)) {
        // we use file cache's file name to make stat() work
        translated = String(RuntimeOption::FileCache);
      }
    }
    return translated;
  }

  if (RuntimeOption::SafeFileAccess) {
    const vector<string> &allowedDirectories =
      VirtualHost::GetAllowedDirectories();
    for (unsigned int i = 0; i < allowedDirectories.size();
         i++) {
      const string &directory = allowedDirectories[i];
      int len = directory.size();
      if (canonicalized.length() >= len &&
          strncmp(canonicalized.data(), directory.data(), len) == 0) {
        return canonicalized;
      }
    }

    // disallow access with an absolute path
    if (canonicalized.charAt(0) == '/') {
      return "";
    }

    // unresolvable paths are all considered as unsafe
    if (canonicalized.find("..") >= 0) {
      assert(canonicalized.find("..") == 0);
      return "";
    }
  }

  if (canonicalized.charAt(0) == '/' || keepRelative) {
    return canonicalized;
  }

  String cwd = g_context->getCwd();
  if (!cwd.empty() && cwd[cwd.length() - 1] == '/') {
    return cwd + canonicalized;
  }
  return cwd + "/" + canonicalized;
}