Skip to content

Commit

Permalink
fix(Scripts/Commands): Prevent crash if you use doublequotes in go cr… (
Browse files Browse the repository at this point in the history
#20012)

fix(Scripts/Commands): Prevent crash if you use doublequotes in go creature name

* closes #20010
  • Loading branch information
Kitzunu committed Sep 21, 2024
1 parent cfd7bf4 commit d227ed9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/server/scripts/Commands/cs_go.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ class go_commandscript : public CommandScript
if (!name.data())
return false;

QueryResult result = WorldDatabase.Query("SELECT entry FROM creature_template WHERE name = \"{}\" LIMIT 1" , name.data());
// Make sure we don't pass double quotes into the SQL query. Otherwise it causes a MySQL error
std::string str = name.data(); // Making subtractions to the last character does not with in string_view
if (str.front() == '"')
str = str.substr(1);
if (str.back() == '"')
str = str.substr(0, str.size() - 1);

QueryResult result = WorldDatabase.Query("SELECT entry FROM creature_template WHERE name = \"{}\" LIMIT 1", str);
if (!result)
{
handler->SendErrorMessage(LANG_COMMAND_GOCREATNOTFOUND);
Expand Down

0 comments on commit d227ed9

Please sign in to comment.