=== modified file 'includes/bootstrap.inc'
--- includes/bootstrap.inc	2009-12-07 07:25:24 +0000
+++ includes/bootstrap.inc	2009-12-10 16:14:02 +0000
@@ -1614,9 +1614,12 @@ function _drupal_bootstrap_database() {
   // The user agent header is used to pass a database prefix in the request when
   // running tests. However, for security reasons, it is imperative that we
   // validate we ourselves made the request.
-  if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE) && !drupal_valid_test_ua($_SERVER['HTTP_USER_AGENT'])) {
-    header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
-    exit;
+  if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE))
+    if (!drupal_valid_test_ua($_SERVER['HTTP_USER_AGENT'])) {
+      header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
+      exit;
+    }
+    register_shutdown_function('printf', chr(0));
   }
   // Initialize the database system. Note that the connection
   // won't be initialized until it is actually requested.

=== modified file 'modules/simpletest/drupal_web_test_case.php'
--- modules/simpletest/drupal_web_test_case.php	2009-12-06 18:06:22 +0000
+++ modules/simpletest/drupal_web_test_case.php	2009-12-10 16:18:13 +0000
@@ -1285,8 +1285,15 @@ class DrupalWebTestCase extends DrupalTe
     // Reset headers and the session ID.
     $this->session_id = NULL;
     $this->headers = array();
+    $response = curl_exec($this->curlHandle);
+    if (substr($response, -1) !== chr(0)) {
+      $this->error('Fatal error', t('Browser'));
+    }
+    elseif (is_string($response)) {
+      $response = substr($response, 0, -1);
+    }
 
-    $this->drupalSetContent(curl_exec($this->curlHandle), curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL));
+    $this->drupalSetContent($response, curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL));
     $message_vars = array(
       '!method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'),
       '@url' => $url,

