This report is similar to the issue for node/$nid where $nid does not exist: http://drupal.org/node/82764
There are two related bugs, here.
In user_menu():
if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0) {
$account = user_load(array('uid' => arg(1)));
if ($user !== FALSE) {
//...
}
$user !== FALSE obviously should be $account !== FALSE.
And when it is false, it means that there are no user with this $uid, and we should return "page not found" instead of "access denied": i.e. do not imply that the user exists when it does not.
The patch creates a callback to a function that will call drupal_not_found();
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | user_not_found.3.diff | 992 bytes | beginner |
| #5 | user_not_found.2.diff | 1.06 KB | beginner |
| user_not_found.diff | 1.39 KB | beginner |
Comments
Comment #1
beginner commentedThe patch here and the one there http://drupal.org/node/82764 both propose a menu callback that are very similar, that simply call drupal_not_found().
Maybe a simple function could be created in some required .inc file, to be used in every similar cases:
Comment #2
ChrisKennedy commentedConfirmed that this error exists for anonymous users and that the patch fixes the problem.
Since we aren't checking if $user === FALSE now, don't a few of the $user->uid checks within that IF block need to ensure that $user isn't FALSE?
Comment #3
beginner commentedThe $user object within that block are all related to the user currently requesting the page, and it is used in this context only to check whether the user is requesting her own user page or not. As such, $user is always a properly declared object and has nothing to do with the $account object in the if statement at the beginning of the block.
The one check that could be removed is at the top of user_view():
$account === FALSE ||could be removed from the if statement, but I am not sure, so I didn't include it in my patch.Comment #4
beginner commentedActually, it seems wasteful to load the same $account twice in the same page view: once in user_menu() and once at the top of user_view().
Instead of passing the $uid, shouldn't we be passing the whole $account object??
Comment #5
beginner commentedRobRoy most rightly pointed out the obvious to me: drupal_not_found() can itself be used as a callback!!
What was I thinking?
Comment #6
ChrisKennedy commentedRighteo.
Comment #7
pwolanin commentedThis is a very minor issue, but I don't think you need to set the title in this callback. drupal_not_found() set its own page title.
Comment #8
RobRoy commentedAlso, drupal_not_found() doesn't take any arguments so you should remove the 'callback arguments' key.
Comment #9
beginner commentedOf course. Done.
Comment #10
pwolanin commentedOne mire minor thing- you probably don't need the 'access' element.
Comment #11
beginner commentedYes, we do, precisely for the reason you mentioned in the other issue: we need to be consistent.
If a user, anonymous or not, does not have the 'view profiles' perm, then accessing user/1 to user/9999999999 will all give "access denied" regardless of anything else.
If they have that perm, they will be able to infer the nb of registered members by checking from which user they get 404.
I am not sure I am explaining this clearly, but if you think it through and test it, you'll see what I mean.
Comment #12
pwolanin commentedAh, I think I understand, but i'll have to look at the code again.
Comment #13
joshk commentedApplies cleanly, works as advertised and seems "right" to me.
Comment #14
drummComment #15
pwolanin commentedbump
Comment #16
dries commentedThis patch does not apply to CVS HEAD and needs to be re-rolled. It might apply against DRUPAL-5 though.
Comment #17
pwolanin commentedSince the menu system has changed, the last patch cannot work for 6.x and, in fact, the bug is already fixed in 6.x.
Probably it's still RTBC for 5.x. as a backport of the behavior in 6.x
Comment #18
drummAlready fixed in 5.x.
Comment #19
toemaz commentedApplied patch attached at #9 to D5.16 and I confirm that it works as advertised.