Use strncpy instead of strcpy because again, buffer overflows

This commit is contained in:
Glenn Smith 2018-03-06 01:59:05 -05:00
parent 1728fe39ad
commit a94587af43
92 changed files with 298 additions and 279 deletions

View file

@ -447,7 +447,7 @@ bool afxMagicMissileData::onAdd()
// make a copy of points_string
char* tokCopy = new char[dStrlen(wiggle_axis_string) + 1];
dStrcpy(tokCopy, wiggle_axis_string);
dStrcpy(tokCopy, wiggle_axis_string, dStrlen(wiggle_axis_string) + 1);
// extract tokens one by one, adding them to dataBlocks
char* currTok = dStrtok(tokCopy, " \t");

View file

@ -142,7 +142,7 @@ bool afxParticleEmitterData::onAdd()
{
Vector<char*> dataBlocks(__FILE__, __LINE__);
char* tokCopy = new char[dStrlen(tpaths_string) + 1];
dStrcpy(tokCopy, tpaths_string);
dStrcpy(tokCopy, tpaths_string, dStrlen(tpaths_string) + 1);
char* currTok = dStrtok(tokCopy, " \t");
while (currTok != NULL)
@ -468,7 +468,7 @@ bool afxParticleEmitterPathData::onAdd()
{
Vector<char*> dataBlocks(__FILE__, __LINE__);
char* tokCopy = new char[dStrlen(epaths_string) + 1];
dStrcpy(tokCopy, epaths_string);
dStrcpy(tokCopy, epaths_string, dStrlen(epaths_string) + 1);
char* currTok = dStrtok(tokCopy, " \t");
while (currTok != NULL)
@ -553,7 +553,7 @@ void afxParticleEmitterPathData::onPerformSubstitutions()
{
Vector<char*> dataBlocks(__FILE__, __LINE__);
char* tokCopy = new char[dStrlen(epaths_string) + 1];
dStrcpy(tokCopy, epaths_string);
dStrcpy(tokCopy, epaths_string, dStrlen(epaths_string) + 1);
char* currTok = dStrtok(tokCopy, " \t");
while (currTok != NULL)

View file

@ -272,10 +272,10 @@ void afxEA_PhraseEffect::trigger_new_phrase()
if (phrase_fx_data->on_trig_cmd != ST_NULLSTRING)
{
char obj_str[32];
dStrcpy(obj_str, Con::getIntArg(choreographer->getId()));
dStrcpy(obj_str, Con::getIntArg(choreographer->getId()), 32);
char index_str[32];
dStrcpy(index_str, Con::getIntArg(group_index));
dStrcpy(index_str, Con::getIntArg(group_index), 32);
char buffer[1024];
char* b = buffer;
@ -382,4 +382,4 @@ bool afxEA_PhraseEffectDesc::requiresStop(const afxEffectWrapperData* ew, const
return (timing.lifetime < 0);
}
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//

View file

@ -194,7 +194,7 @@ char* afxRPGMagicSpellData::fmt_placeholder_desc(char* buffer, int len) const
{
char pack_str[32];
if (source_pack == ST_NULLSTRING)
dStrcpy(pack_str, "unknown");
dStrcpy(pack_str, "unknown", 32);
else
dSprintf(pack_str, 32, "%s", source_pack);
@ -225,7 +225,7 @@ char* afxRPGMagicSpellData::formatDesc(char* buffer, int len) const
{
if (spell_target != TARGET_NOTHING)
{
dStrcpy(target_str, _afxRPGMagicSpell_TargetType::_sEnumTable[i].mName);
dStrcpy(target_str, _afxRPGMagicSpell_TargetType::_sEnumTable[i].mName, 32);
if (spell_target != TARGET_FREE && target_optional)
dStrcat(target_str, " (opt)", 32);
}
@ -245,13 +245,13 @@ char* afxRPGMagicSpellData::formatDesc(char* buffer, int len) const
char casting_str[32];
if (casting_dur <= 0)
dStrcpy(casting_str, "instant");
dStrcpy(casting_str, "instant", 32);
else
dSprintf(casting_str, 32, "%.1f sec cast", casting_dur);
char pack_str[32];
if (source_pack == ST_NULLSTRING)
dStrcpy(pack_str, "unknown");
dStrcpy(pack_str, "unknown", 32);
else
dSprintf(pack_str, 32, "%s", source_pack);

View file

@ -171,10 +171,11 @@ void afxSpellButton::setBitmap(const char *name, bool placeholder)
if (placeholder)
{
dStrcpy(buffer, name);
dStrcpy(buffer, name, 1024);
S32 pLen = 1024 - dStrlen(buffer);
p = buffer + dStrlen(buffer);
dStrcpy(p, "_i");
dStrcpy(p, "_i", pLen);
mTextureInactive.set(buffer, COOLDOWN_PROFILE);
mTextureNormal = mTextureInactive;
mTextureHilight = mTextureInactive;
@ -183,19 +184,20 @@ void afxSpellButton::setBitmap(const char *name, bool placeholder)
}
else
{
dStrcpy(buffer, name);
dStrcpy(buffer, name, 1024);
S32 pLen = 1024 - dStrlen(buffer);
p = buffer + dStrlen(buffer);
dStrcpy(p, "_n");
dStrcpy(p, "_n", pLen);
mTextureNormal.set(buffer, COOLDOWN_PROFILE);
dStrcpy(p, "_h");
dStrcpy(p, "_h", pLen);
mTextureHilight.set(buffer, COOLDOWN_PROFILE);
if (!mTextureHilight)
mTextureHilight = mTextureNormal;
dStrcpy(p, "_d");
dStrcpy(p, "_d", pLen);
mTextureDepressed.set(buffer, COOLDOWN_PROFILE);
if (!mTextureDepressed)
mTextureDepressed = mTextureHilight;
dStrcpy(p, "_i");
dStrcpy(p, "_i", pLen);
mTextureInactive.set(buffer, COOLDOWN_PROFILE);
if (!mTextureInactive)
mTextureInactive = mTextureNormal;

View file

@ -195,7 +195,7 @@ bool afxXM_PathConformData::onAdd()
{
Vector<char*> dataBlocks(__FILE__, __LINE__);
char* tokCopy = new char[dStrlen(paths_string) + 1];
dStrcpy(tokCopy, paths_string);
dStrcpy(tokCopy, paths_string, dStrlen(paths_string) + 1);
char* currTok = dStrtok(tokCopy, " \t");
while (currTok != NULL)