Access /drupal/comment/1blah (any comment-id starting with a number, but containing non-numeric chars)

With default installation and MySQL, I get a 404 page that also includes PHP undefined index notices:

Notice: Undefined index: 1blah in comment_load() (line 1685 of /var/www/drupal/modules/comment/comment.module).
Notice: Undefined index: 1blah in comment_load() (line 1685 of /var/www/drupal/modules/comment/comment.module).
Notice: Trying to get property of non-object in comment_access() (line 1443 of /var/www/drupal/modules/comment/comment.module).

An erroneous request shouldn't make it this far, as such unexpected conditions may lead to attack vectors (apart from the annoyance of PHP notices). Failfast and all that.

Steps to reproduce

  1. Clean install of Drupal 7.x
  2. Log in as admin
  3. Add Article
  4. Add Comment
  5. Navigate to /comment/1blah

With PostgreSQL, I get database errors:

PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "1blah" at character 609: SELECT base.cid AS cid, base.pid AS pid, base.nid AS nid, base.uid AS uid, base.subject AS subject, base.hostname AS hostname, base.created AS created, base.changed AS changed, base.status AS status, base.thread AS thread, base.name AS name, base.mail AS mail, base.homepage AS homepage, base.language AS language, n.type AS node_type, u.name AS registered_name, u.uid AS u_uid, u.signature AS signature, u.signature_format AS signature_format, u.picture AS picture FROM {comment} base INNER JOIN {node} n ON base.nid = n.nid INNER JOIN {users} u ON base.uid = u.uid WHERE (base.cid IN (:db_condition_placeholder_0)) ; Array ( [:db_condition_placeholder_0] => 1blah ) in DrupalDefaultEntityController->load() (line 196 of /var/www/.../news/includes/entity.inc).

(presumably because MySQL silently, "cleverly", ignores conversion errors, while PG does not).

In fact for PostgreSQL it's not even /comment/blah (no leading digit) yields the same error, and comment/reply/blah as well.

I'm seeing the same problem with non-numeric node ID's and PG, but that is presumably a separate issue.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lbainbridge’s picture

Version: 7.17 » 7.x-dev
FileSize
95.47 KB

Not an issue in Drupal 8.x

Steps to reproduce:

  1. Clean install of Drupal 7.x
  2. Log in as admin
  3. Add Article
  4. Add Comment
  5. Navigate to /comment/1blah
paravibe’s picture

Status: Active » Needs review
FileSize
1.35 KB

Maybe should be like this?

heddn’s picture

+++ b/modules/comment/comment.module
@@ -1681,8 +1681,10 @@ function comment_load_multiple($cids = array(), $conditions = array(), $reset =
+  if (is_numeric($cid)) {

Probably should use is_int().
http://php.net/manual/en/function.is-numeric.php

heddn’s picture

Issue summary: View changes
Status: Needs review » Needs work
paravibe’s picture

Status: Needs work » Needs review
FileSize
1.3 KB

OK, I think now it's better.

Status: Needs review » Needs work
paravibe’s picture

paravibe’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
paravibe’s picture

Status: Needs work » Needs review
FileSize
1.33 KB

Status: Needs review » Needs work
rakeshfalke’s picture

Tested @drupalrv code working good :).

rakeshfalke’s picture

Steps to Followed:

  1. Clean install of Drupal 7.x
  2. Log in as admin
  3. Add Article
  4. Add Comment
  5. Navigate to /comment/1blah

Working properly so closing this issue.

star-szr’s picture

Issue summary: View changes
Status: Fixed » Needs work

I'm still able to reproduce this using the steps to reproduce, adding them to the issue summary.

@rakeshfalke - for future reference if this wasn't reproducible we'd use the status "Closed (cannot reproduce)" :)

star-szr’s picture

Issue tags: +Needs tests

Oh maybe I misunderstood - I missed comment #12.

So @rakeshfalke maybe you tested with the patch and it worked? That still means the issue needs to stay open for further reviews and adding tests to cover this bug would be a good idea.

moertle’s picture

Another try with is_numeric

moertle’s picture

Status: Needs work » Needs review
poker10’s picture

Status: Needs review » Closed (outdated)

I have tried this on clean D7.97 install and accessing such link /comment/1blah does not throw notices/warnings for me (on PHP8). This is probably outdated, but feel free to reopen, if this is still an issue. Thanks!