Commit message: None
CVE: CVE-2013-6627
CWE: CWE-119
Vulnerability description: net/http/http_stream_parser.cc in Google Chrome before 31.0.1650.48 does not properly process HTTP Informational (aka 1xx) status codes, which allows remote web servers to cause a denial of service (out-of-bounds read) via a crafted response.

Project: Chrome

scoped_ptr<base::MessagePump> CreateMessagePumpForUI() {
  return scoped_ptr<base::MessagePump>(new content::NestedMessagePumpAndroid());
}

Project: Chrome

void EnsureCreateFIFO(const base::FilePath& path) {
  unlink(path.value().c_str());
  CHECK(base::android::CreateFIFO(path, 0666))
    << "Unable to create the Android's FIFO: " << path.value().c_str();
}

Project: Chrome

base::FilePath GetTestFilesDirectory(JNIEnv* env) {
  ScopedJavaLocalRef<jstring> directory =
      content::Java_ShellLayoutTestUtils_getApplicationFilesDirectory(
          env, base::android::GetApplicationContext());
  return base::FilePath(ConvertJavaStringToUTF8(directory));
}

Project: Chrome

bool GetTestUrlForAndroid(std::string& path_or_url, GURL* url) {
  if (path_or_url.find(kAndroidLayoutTestPath) == std::string::npos)
    return false;

  std::string test_location(kAndroidLayoutTestBase);
  test_location.append(path_or_url.substr(strlen(kAndroidLayoutTestPath)));

  *url = GURL(test_location);
  return true;
 }

Project: Chrome

bool GetNextTest(const CommandLine::StringVector& args,
                 size_t* position,
                 std::string* test) {
  if (*position >= args.size())
    return false;
  if (args[*position] == FILE_PATH_LITERAL("-"))
    return !!std::getline(std::cin, *test, '\n');
#if defined(OS_WIN)
  *test = base::WideToUTF8(args[(*position)++]);
#else
  *test = args[(*position)++];
#endif
  return true;
}

Project: Chrome

GURL GetURLForLayoutTest(const std::string& test_name,
                         base::FilePath* current_working_directory,
                         bool* enable_pixel_dumping,
                         std::string* expected_pixel_hash) {
  std::string path_or_url = test_name;
  std::string pixel_switch;
  std::string pixel_hash;
  std::string::size_type separator_position = path_or_url.find('\'');
  if (separator_position != std::string::npos) {
    pixel_switch = path_or_url.substr(separator_position + 1);
    path_or_url.erase(separator_position);
  }
  separator_position = pixel_switch.find('\'');
  if (separator_position != std::string::npos) {
    pixel_hash = pixel_switch.substr(separator_position + 1);
    pixel_switch.erase(separator_position);
  }
  if (enable_pixel_dumping) {
    *enable_pixel_dumping =
        (pixel_switch == "--pixel-test" || pixel_switch == "-p");
  }
  if (expected_pixel_hash)
    *expected_pixel_hash = pixel_hash;

  GURL test_url;
#if defined(OS_ANDROID)
  if (content::GetTestUrlForAndroid(path_or_url, &test_url))
    return test_url;
#endif

  test_url = GURL(path_or_url);
  if (!(test_url.is_valid() && test_url.has_scheme())) {
    base::ThreadRestrictions::ScopedAllowIO allow_io;
#if defined(OS_WIN)
    base::FilePath::StringType wide_path_or_url =
        base::SysNativeMBToWide(path_or_url);
    base::FilePath local_file(wide_path_or_url);
#else
    base::FilePath local_file(path_or_url);
#endif
    if (!base::PathExists(local_file)) {
      local_file = content::GetWebKitRootDirFilePath()
                       .Append(FILE_PATH_LITERAL("LayoutTests"))
                       .Append(local_file);
    }
    test_url = net::FilePathToFileURL(base::MakeAbsoluteFilePath(local_file));
  }
  base::FilePath local_path;
  if (current_working_directory) {
    base::ThreadRestrictions::ScopedAllowIO allow_io;
    if (net::FileURLToFilePath(test_url, &local_path))
      *current_working_directory = local_path.DirName();
    else
      base::GetCurrentDirectory(current_working_directory);
  }
  return test_url;
}

Project: Chrome

int LayoutTestBrowserMain(
    const content::MainFunctionParams& parameters,
    const scoped_ptr<content::BrowserMainRunner>& main_runner) {
  base::ScopedTempDir browser_context_path_for_layout_tests;

  CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir());
  CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty());
  CommandLine::ForCurrentProcess()->AppendSwitchASCII(
      switches::kContentShellDataPath,
      browser_context_path_for_layout_tests.path().MaybeAsASCII());

#if defined(OS_ANDROID)
  content::EnsureInitializeForAndroidLayoutTests();
#endif

  int exit_code = main_runner->Initialize(parameters);
  DCHECK_LT(exit_code, 0)
      << "BrowserMainRunner::Initialize failed in LayoutTestBrowserMain";

  if (exit_code >= 0)
    return exit_code;

  if (CommandLine::ForCurrentProcess()->HasSwitch(
          switches::kCheckLayoutTestSysDeps)) {
    base::MessageLoop::current()->PostTask(FROM_HERE,
                                           base::MessageLoop::QuitClosure());
    main_runner->Run();
    content::Shell::CloseAllWindows();
    main_runner->Shutdown();
    return 0;
  }

  content::WebKitTestController test_controller;
  {
    base::ThreadRestrictions::ScopedAllowIO allow_io;
    base::FilePath temp_path;
    base::GetTempDir(&temp_path);
    test_controller.SetTempPath(temp_path);
  }
  std::string test_string;
  CommandLine::StringVector args = CommandLine::ForCurrentProcess()->GetArgs();
  size_t command_line_position = 0;
  bool ran_at_least_once = false;

  std::cout << "#READY\n";
  std::cout.flush();

  while (GetNextTest(args, &command_line_position, &test_string)) {
    if (!RunOneTest(test_string, &ran_at_least_once, main_runner))
      break;
  }
  if (!ran_at_least_once) {
    base::MessageLoop::current()->PostTask(FROM_HERE,
                                           base::MessageLoop::QuitClosure());
    main_runner->Run();
  }

#if defined(OS_ANDROID)
  main_runner->Shutdown();
#endif

  exit_code = 0;

#if !defined(OS_ANDROID)
  main_runner->Shutdown();
#endif

  return exit_code;
}

Project: Chrome

bool RunOneTest(const std::string& test_string,
                bool* ran_at_least_once,
                const scoped_ptr<content::BrowserMainRunner>& main_runner) {
  if (test_string.empty())
    return true;
  if (test_string == "QUIT")
    return false;

  bool enable_pixel_dumps;
  std::string pixel_hash;
  base::FilePath cwd;
  GURL test_url =
      GetURLForLayoutTest(test_string, &cwd, &enable_pixel_dumps, &pixel_hash);
  if (!content::WebKitTestController::Get()->PrepareForLayoutTest(
          test_url, cwd, enable_pixel_dumps, pixel_hash)) {
    return false;
  }

  *ran_at_least_once = true;
#if defined(OS_ANDROID)
  base::RunLoop run_loop;
  run_loop.Run();
#else
  main_runner->Run();
#endif

  if (!content::WebKitTestController::Get()->ResetAfterLayoutTest())
    return false;

#if defined(OS_ANDROID)
  base::MessageLoop::current()->RunUntilIdle();
#endif
  return true;
}