[Crash Fix] Fix crash when creating Frogloks/Drakkin (#4016)

* [Crash Fix] Fix crash when creating Frogloks/Drakkin

# Notes
- https://github.com/EQEmu/Server/pull/3920 introduced an issue where we were using `uchar` for `race_selection` and `class_selection` which was not functioning properly within `IsPlayerRace()`.

* Update client.cpp
This commit is contained in:
Alex King 2024-01-25 06:19:59 -05:00 committed by GitHub
parent e9285fd2ca
commit 9ac25338bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 37 deletions

View File

@ -631,6 +631,12 @@ struct ConsentResponse_Struct {
char zonename[32]; char zonename[32];
}; };
struct NameApproval_Struct {
char name[64];
uint32 race_id;
uint32 class_id;
};
/* /*
** Name Generator Struct ** Name Generator Struct
** Length: 72 bytes ** Length: 72 bytes

View File

@ -535,67 +535,64 @@ bool Client::HandleNameApprovalPacket(const EQApplicationPacket *app)
return false; return false;
} }
auto length = snprintf(char_name, 64, "%s", (char*)app->pBuffer); auto n = (NameApproval_Struct*) app->pBuffer;
uchar race_selection = app->pBuffer[64]; strn0cpy(char_name, n->name, sizeof(char_name));
uchar class_selection = app->pBuffer[68];
if (!IsPlayerRace(race_selection)) { const uint32 length = strlen(n->name);
const uint32 race_id = n->race_id;
const uint32 class_id = n->class_id;
if (!IsPlayerRace(race_id)) {
LogInfo("Invalid Race ID."); LogInfo("Invalid Race ID.");
return false; return false;
} }
if (!EQ::ValueWithin(class_selection, Class::Warrior, Class::Berserker)) { if (!EQ::ValueWithin(class_id, Class::Warrior, Class::Berserker)) {
LogInfo("Invalid Class ID."); LogInfo("Invalid Class ID.");
return false; return false;
} }
LogInfo("Name approval request. Name=[{}], race_selection=[{}], class=[{}]", char_name, GetRaceIDName(race_selection), GetClassIDName(class_selection));
EQApplicationPacket *outapp; LogInfo(
outapp = new EQApplicationPacket; "char_name [{}] race_id [{}] class_id [{}]",
outapp->SetOpcode(OP_ApproveName); char_name,
outapp->pBuffer = new uchar[1]; GetRaceIDName(race_id),
outapp->size = 1; GetClassIDName(class_id)
);
bool valid = true; bool is_valid = true;
/* Name must be between 4 and 15 characters long, packet forged if this is true */
if (length < 4 || length > 15) { if (!EQ::ValueWithin(length, 4, 15)) { /* Name must be between 4 and 15 characters long, packet forged if this is true */
valid = false; is_valid = false;
} } else if (islower(char_name[0])) { /* Name must begin with an upper-case letter, can be sent with some tricking of the client */
/* Name must begin with an upper-case letter, can be sent with some tricking of the client */ is_valid = false;
else if (islower(char_name[0])) { } else if (strstr(char_name, " ")) { /* Name must not have any spaces, packet forged if this is true */
valid = false; is_valid = false;
} } else if (!database.CheckNameFilter(char_name)) { /* I would like to do this later, since it's likely more expensive, but oh well */
/* Name must not have any spaces, packet forged if this is true */ is_valid = false;
else if (strstr(char_name, " ")) { } else { /* Name must not contain any uppercase letters, can be sent with some tricking of the client */
valid = false;
}
/* I would like to do this later, since it's likely more expensive, but oh well */
else if (!database.CheckNameFilter(char_name)) {
valid = false;
}
else {
/* Name must not not contain any uppercase letters, can be sent with some tricking of the client */
for (int i = 1; i < length; ++i) { for (int i = 1; i < length; ++i) {
if (isupper(char_name[i])) { if (isupper(char_name[i])) {
valid = false; is_valid = false;
break; break;
} }
} }
} }
/* Still not invalid, let's see if it's taken */ if (is_valid) { /* Still not invalid, let's see if it's taken */
if (valid) { is_valid = database.ReserveName(GetAccountID(), char_name);
valid = database.ReserveName(GetAccountID(), char_name);
} }
outapp->pBuffer[0] = valid ? 1 : 0; auto outapp = new EQApplicationPacket(OP_ApproveName, 1);
outapp->pBuffer[0] = is_valid ? 1 : 0;
QueuePacket(outapp); QueuePacket(outapp);
safe_delete(outapp); safe_delete(outapp);
if (!valid) if (!is_valid) {
memset(char_name, 0, sizeof(char_name)); memset(char_name, 0, sizeof(char_name));
}
return true; return true;
} }