nsCAutoString spec = CBufDescriptor(str, PR_FALSE, len + 1, len);
nsCAutoString spec( CBufDescriptor(str, PR_FALSE, len + 1, len) );
SplitURL(nsIURI* aChromeURI, nsCString& aPackage, nsCString& aProvider, nsCString& aFile){  // Splits a "chrome:" URL into its package, provider, and file parts.  // Here are the current portions of a   // chrome: url that make up the chrome-  //  //     chrome://global/skin/foo?bar  //     \------/ \----/\---/ \-----/  //         |       |     |     |  //         |       |     |     `-- RemainingPortion  //         |       |     |  //         |       |     `-- Provider   //         |       |  //         |       `-- Package  //         |  //         `-- Always "chrome://"  //  //  nsresult rv;  char* str;  rv = aChromeURI->GetSpec(&str);  if (NS_FAILED(rv)) return rv;  if (! str)    return NS_ERROR_INVALID_ARG;  PRInt32 len = PL_strlen(str);  nsCAutoString spec = CBufDescriptor(str, PR_FALSE, len + 1, len);  // We only want to deal with "chrome:" URLs here. We could return  // an error code if the URL isn't properly prefixed here...  if (PL_strncmp(spec, kChromePrefix, sizeof(kChromePrefix) - 1) != 0)    return NS_ERROR_INVALID_ARG;  // Cull out the "package" string; e.g., "navigator"  spec.Right(aPackage, spec.Length() - (sizeof(kChromePrefix) - 1));  PRInt32 idx;  idx = aPackage.FindChar('/');  if (idx < 0)    return NS_OK;  // Cull out the "provider" string; e.g., "content"  aPackage.Right(aProvider, aPackage.Length() - (idx + 1));  aPackage.Truncate(idx);  idx = aProvider.FindChar('/');  if (idx < 0) {    // Force the provider to end with a '/'    idx = aProvider.Length();    aProvider.Append('/');  }  // Cull out the "file"; e.g., "navigator.xul"  aProvider.Right(aFile, aProvider.Length() - (idx + 1));  aProvider.Truncate(idx);  if (aFile.Length() == 0) {    // If there is no file, then construct the default file    aFile = aPackage;    if (aProvider.Equals("content")) {        aFile += ".xul";    }    else if (aProvider.Equals("skin")) {        aFile += ".css";    }    else if (aProvider.Equals("locale")) {        aFile += ".dtd";    }    else {        NS_ERROR("unknown provider");        return NS_ERROR_FAILURE;    }  } else {      // Protect against URIs containing .. that reach up out of the       // chrome directory to grant chrome privileges to non-chrome files.      int depth = 0;      PRBool sawSlash = PR_TRUE;  // .. at the beginning is suspect as well as /..      for (const char* p=aFile; *p; p++) {        if (sawSlash) {          if (p[0] == '.' && p[1] == '.'){            depth--;    // we have /.., decrement depth.          } else {            static const char escape[] = "%2E%2E";            if(PL_strncasecmp(p, escape, sizeof(escape)-1) == 0)                depth--;   // we have /%2E%2E, the HTML escape form of /.., decrement depth.          }        }else if (p[0] != '/') {          depth++;        // we have /x for some x that is not /              }               sawSlash = (p[0] == '/');                if (depth < 0) {          return NS_ERROR_FAILURE;                }      }  }  return NS_OK;}