Actually, it is now possible to reply to non existent comments, which enters a comment parent (pid) in the database that may break comment rendering or other unexpected results.

The patch checks is the comment exists, and generates a page not found if it doesn't.

Please, review.

Comments

eaton’s picture

StatusFileSize
new955 bytes

When I tested the patch it generated a page not found screen, but ALSO displayed the normal drupal page output below that. Added a simple return; after the drupal_page_not_found(); and it seems to work fine.

Also tested some bogus scenerios (like creating a comment that is a parent of itself)... default comment rendering doesn't seem to break, though obviously it doesn't display a parent.

eaton’s picture

Priority: Critical » Minor

Changing the status of this one, as it's a legitimate bug but it's very minor, has no ill effects, and would only occur if the user deliberately entered a bad pid.

markus_petrux’s picture

Status: Needs review » Reviewed & tested by the community

This is a trivial fix, does it worth to spend a couple of minutes to commit?

john.money’s picture

This condition could occur if user A started replying to a legitimate comment, say a spam, but before they completed submitting it (went to get a beverage or something), a moderator deleted the original spam comment. It doen't require any "bad behavior" on the part of user A.

dries’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.54 KB

This patch looks more in line with the rest of the function.

One could argue that we should use drupal_not_found() as that will generate the proper HTTP headers.

I'm fine with that but in that case we need to be consistent and change the drupal_set_message(t('You are not authorized to post comments.'), 'error'); lines (and friends) into drupal_access_denied().

dries’s picture

StatusFileSize
new67.99 KB

Here is a patch that uses drupal_not_found() and drupal_access_denied().

This function can be cleaned up significantly, it seems. Also, some of the checks, like else if (user_access('access content')) { should probably be moved up. Also, we don't check if $node is non-empty.

dries’s picture

Nevermind that last patch. Something got messed up.

markus_petrux’s picture

StatusFileSize
new2.27 KB

I tested the patch in comment #5. It still shows the reply form. It lacks a return statement, just after the message is set (same thing Eaton did to my first patch).

I like this approach better than drupal_not_found(), 'cause besides consistency, it has the ability the tell the user "what" the problem is.

Well, I first tried to add a return statement after the error message is set, but the result is a page (with possible blocks around) and the message on top. Not very nice.

So... instead of generating an empty page with only the error message, I tried to use drupal_goto("node/$nid"). Much nicer, IMO, so I applied the same trick (for consistency) to the other places where an error is set.

Note that, in the context of comment_reply(), $nid is valid, it's been verified in hook_menu.

dries’s picture

Adding the possibility to display custom errors on 404 and 403 pages might get us the best of both worlds: good error messages for users and good error codes/headers for crawlers/bots/tools.

Your last patch looks good though; we can go with that for now.

markus_petrux’s picture

Status: Needs review » Reviewed & tested by the community

switching issue status then. Please, correct me if I'm wrong.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)