Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

admin-sql-threaded: SQL Query has improper syntax in FetchUser() #2148

Open
6 tasks done
ArcalaAlien opened this issue May 4, 2024 · 0 comments
Open
6 tasks done

Comments

@ArcalaAlien
Copy link

ArcalaAlien commented May 4, 2024

Help us help you

  • I have checked that my issue doesn't exist yet.
  • I have tried my absolute best to reduce the problem-space and have provided the absolute smallest test-case possible.
  • I can always reproduce the issue with the provided description below.

Environment

  • Operating System version: ubuntu 20.04
  • Game/AppID (with version if applicable): 440
  • Current SourceMod version: 1.12
  • Current SourceMod snapshot: 7125
  • Current Metamod: Source snapshot: 1.12.0-dev+1192

Description

When using admin-sql-threaded.smx, the error in the picture is thrown when an admin joins a server.

The SQL Query in the SELECT statement in lines 510-529 has incorrect syntax. COUNT() is an aggregate function, and so all values that aren't in an aggregate function must be in the GROUP BY clause. However, adding all the additional columns needed causes the SQL query to get truncated so the length of the array should be increased.

Problematic Code (or Steps to Reproduce)

Lines 510-529

// Increase the char buffer's size or the query gets truncated with the new GROUP BY clause
char query[512];
int len = 0;
	
len += Format(query[len], sizeof(query)-len, "SELECT a.id, a.authtype, a.identity, a.password, a.flags, a.name, COUNT(ag.group_id), immunity");
len += Format(query[len], sizeof(query)-len, " FROM sm_admins a LEFT JOIN sm_admins_groups ag ON a.id = ag.admin_id WHERE ");
len += Format(query[len], sizeof(query)-len, " (a.authtype = 'ip' AND a.identity = '%s')", ipaddr);
len += Format(query[len], sizeof(query)-len, " OR (a.authtype = 'name' AND a.identity = '%s')", safe_name);
if (steamid2[0] != '\0' && steamid3[0] != '\0' && steamid64[0] != '\0')
{
	strcopy(steamid2alt, sizeof(steamid2alt), steamid2);
	steamid2alt[6] = (steamid2[6] == '0') ? '1' : '0';

	len += Format(query[len], sizeof(query)-len,
		" OR (a.authtype = 'steam' AND (a.identity = '%s' OR a.identity = '%s' OR a.identity = '%s' OR a.identity = '%s'))",
		steamid2, steamid2alt, steamid3, steamid64);
}
// Should be: GROUP BY a.id, a.authtype, a.identity, a.password, a.flags, a.name, immunity
len += Format(query[len], sizeof(query)-len, " GROUP BY a.id");

Logs

  • Please attach in separate files: game output, library logs, kernel logs, and any other supporting information.
  • In case of a crash, please attach minidump or dump analyze output.
    SQL_error
@ArcalaAlien ArcalaAlien changed the title admin-sql-threaded: SQL Query has improper syntax and is truncated when called in FetchUser() admin-sql-threaded: SQL Query has improper syntax in FetchUser() May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant