RFC 2616:

The User-Agent request-header field contains information about the
user agent originating the request. This is for statistical purposes,
the tracing of protocol violations, and automated recognition of user
agents for the sake of tailoring responses to avoid particular user
agent limitations. User agents SHOULD include this field with
requests.
The field can contain multiple product tokens (section 3.8)
and comments identifying the agent and any subproducts which form a
significant part of the user agent. By convention, the product tokens
are listed in order of their significance for identifying the
application.

As it is not required ("MUST"/"SHOULD"), Drupal should not trigger a notice when it is missing. I noticed this with telnet:

Undefined index: HTTP_USER_AGENT in includes/database.inc on line 155

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cburschka’s picture

The variable is used here:

$ grep HTTP_USER_AGENT -R *
includes/database.inc:    if (preg_match("/^simpletest\d+$/", $_SERVER['HTTP_USER_AGENT'])) {
includes/database.inc:      $db_prefix = $_SERVER['HTTP_USER_AGENT'];
modules/simpletest/simpletest.module:  $batch_mode = !preg_match("/^simpletest\d+$/", $_SERVER['HTTP_USER_AGENT']);
modules/simpletest/simpletest.test:    return preg_match("/^simpletest\d+/", $_SERVER['HTTP_USER_AGENT']);

Alternatives for solving this:

1.) Use safe coding in all four places by checking isset().
2.) Do if (!isset($_SERVER['HTTP_USER_AGENT']) $_SERVER['HTTP_USER_AGENT'] = ''; once somewhere at system startup.

The first approach is more in line with what is done with other variables, while the second will prevent many potential bugs in contrib which are extremely hard to identify (because the user agent is rarely missing). Discuss...

cburschka’s picture

Status: Active » Needs review
FileSize
2.31 KB

This patch adds isset checks to the three relevant conditions in database.inc, simpletest.module and simpletest.test.

c960657’s picture

Status: Needs review » Needs work

Patch no longer applies to HEAD.

lilou’s picture

Status: Needs work » Needs review
FileSize
1.72 KB

Reroll against HEAD.

Dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.