Use strn0cpy instead of strcpy when copying consent name buffers

Add nullptr checks to consent functions that accept char pointers
This commit is contained in:
hg 2020-01-30 20:00:01 -05:00
parent 9689787e56
commit 14c070f845
3 changed files with 22 additions and 15 deletions

View File

@ -6257,7 +6257,10 @@ void Client::DragCorpses()
void Client::ConsentCorpses(const char* consent_name, bool deny) void Client::ConsentCorpses(const char* consent_name, bool deny)
{ {
if (strcasecmp(consent_name, GetName()) == 0) { if (!consent_name) {
return;
}
else if (strcasecmp(consent_name, GetName()) == 0) {
MessageString(Chat::Red, CONSENT_YOURSELF); MessageString(Chat::Red, CONSENT_YOURSELF);
} }
else if (!consent_throttle_timer.Check()) { else if (!consent_throttle_timer.Check()) {
@ -6266,9 +6269,9 @@ void Client::ConsentCorpses(const char* consent_name, bool deny)
else { else {
auto pack = new ServerPacket(ServerOP_Consent, sizeof(ServerOP_Consent_Struct)); auto pack = new ServerPacket(ServerOP_Consent, sizeof(ServerOP_Consent_Struct));
ServerOP_Consent_Struct* scs = (ServerOP_Consent_Struct*)pack->pBuffer; ServerOP_Consent_Struct* scs = (ServerOP_Consent_Struct*)pack->pBuffer;
strcpy(scs->grantname, consent_name); strn0cpy(scs->grantname, consent_name, sizeof(scs->grantname));
strcpy(scs->ownername, GetName()); strn0cpy(scs->ownername, GetName(), sizeof(scs->ownername));
strcpy(scs->zonename, "Unknown"); strn0cpy(scs->zonename, "Unknown", sizeof(scs->zonename));
scs->message_string_id = 0; scs->message_string_id = 0;
scs->permission = deny ? 0 : 1; scs->permission = deny ? 0 : 1;
scs->zone_id = zone->GetZoneID(); scs->zone_id = zone->GetZoneID();

View File

@ -662,6 +662,7 @@ void Corpse::DepopPlayerCorpse() {
void Corpse::AddConsentName(const char* add_name) void Corpse::AddConsentName(const char* add_name)
{ {
if (add_name) {
for (const auto& n : consent_names) { for (const auto& n : consent_names) {
if (strcasecmp(n.c_str(), add_name) == 0) { if (strcasecmp(n.c_str(), add_name) == 0) {
return; return;
@ -669,15 +670,18 @@ void Corpse::AddConsentName(const char* add_name)
} }
consent_names.emplace_back(add_name); consent_names.emplace_back(add_name);
} }
}
void Corpse::RemoveConsentName(const char* rem_name) void Corpse::RemoveConsentName(const char* rem_name)
{ {
if (rem_name) {
consent_names.erase(std::remove_if(consent_names.begin(), consent_names.end(), consent_names.erase(std::remove_if(consent_names.begin(), consent_names.end(),
[rem_name](const std::string& n) { [rem_name](const std::string& n) {
return strcasecmp(n.c_str(), rem_name) == 0; return strcasecmp(n.c_str(), rem_name) == 0;
} }
), consent_names.end()); ), consent_names.end());
} }
}
uint32 Corpse::CountItems() { uint32 Corpse::CountItems() {
return itemlist.size(); return itemlist.size();

View File

@ -1489,8 +1489,8 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
// send the message to the client being granted or denied permission // send the message to the client being granted or denied permission
auto outapp = new EQApplicationPacket(OP_ConsentResponse, sizeof(ConsentResponse_Struct)); auto outapp = new EQApplicationPacket(OP_ConsentResponse, sizeof(ConsentResponse_Struct));
ConsentResponse_Struct* crs = (ConsentResponse_Struct*)outapp->pBuffer; ConsentResponse_Struct* crs = (ConsentResponse_Struct*)outapp->pBuffer;
strcpy(crs->grantname, s->grantname); strn0cpy(crs->grantname, s->grantname, sizeof(crs->grantname));
strcpy(crs->ownername, s->ownername); strn0cpy(crs->ownername, s->ownername, sizeof(crs->ownername));
crs->permission = s->permission; crs->permission = s->permission;
strn0cpy(crs->zonename, s->zonename, sizeof(crs->zonename)); strn0cpy(crs->zonename, s->zonename, sizeof(crs->zonename));
grant_client->QueuePacket(outapp); grant_client->QueuePacket(outapp);