NodeAccess use db_query for everything, but it can fails when SQL contains a IN / NOT IN clause.
Here's the current code performing a user search :

    // Perform search.
    if ($form_values['keys']) {
      // @todo rewrite
      $params = array();
      $sql = "SELECT uid, name FROM {users} WHERE name LIKE :name";
      $name = preg_replace('!\*+!', '%', $form_values['keys']);
      $params[':name'] = $name;
      $users = '';
      if (isset($form_values['uid']) && is_array($form_values['uid'])) {
        $sql .= ' AND uid NOT IN (:uid)';
        $users = implode(',', array_keys($form_values['uid']));
        $params[':uid'] = $users;
      }

      $result = db_query($sql, $params);
      foreach ($result as $account) {

        $form_values['uid'][$account->uid] = array(
          'name' => $account->name,
          'keep' => 0,
        );
      }
    }

If there're already 2 users in the GRANT table (uid 1, 2), this is the final query:

SELECT uid, name FROM {users} WHERE name LIKE 'xxx' 
AND uid NOT IN ('1, 2')

This will make the query to fail, and prevents you to add a third user.
Instead, we need to use the db_select function, to get a well-formed NOT IN clause:

    // Perform search.
    if ($form_values['keys']) {
      $name = preg_replace('!\*+!', '%', $form_values['keys']);
      if (isset($form_values['uid']) && is_array($form_values['uid'])) {
        $result = db_select('users', 'u')
            ->fields('u', array('uid', 'name'))
            ->condition('name', $name, 'LIKE')
            ->condition('uid', array_keys($form_values['uid']), 'NOT IN')
            ->execute();
      } else {
        $result = db_select('users', 'u')
            ->fields('u', array('uid', 'name'))
            ->condition('name', $name, 'LIKE')
            ->execute();
      }

      foreach ($result as $account) {
        $form_values['uid'][$account->uid] = array(
          'name' => $account->name,
          'keep' => 0,
        );
      }
    }

Comments

zessx created an issue. See original summary.

joelpittet’s picture

Status: Needs review » Active

The "needs review" status is reserved for when there is a patch on the issue.
https://www.drupal.org/node/156119#needs-review

A test case would be nice since this is a bug to ensure if it's fixed that it doesn't regress.

d.fisher’s picture

Status: Active » Postponed (maintainer needs more info)

Drupal 7 security support has ended as of 5 January 2025.

We are doing some housekeeping on the nodeaccess issue queue and moving all Drupal 7 issues to "postponed (maintainer needs more info)". See https://www.drupal.org/project/nodeaccess/issues/3516593.

If this issue persists on the latest dev branch of nodeaccess (2.0.x-dev) then please feel free to comment and we will change the version against this issue. If we do not hear any feedback within 2 weeks (9th October 2025) we will go ahead and close this issue as outdated.

Thank you.

d.fisher’s picture

Assigned: zessx » Unassigned
d.fisher’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

As per the above, as there has been no response we will now close this issue as outdated.

If this issue persists on the latest dev branch of nodeaccess (2.0.x-dev) then please feel free to update the version on this issue and reopen it.

Thank you.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.