Replace ke::SafeSprintf with ke::SafeStrcpy (#784)
This commit is contained in:
committed by
Asher Baker
parent
0a91b1f5b1
commit
956f264b85
@@ -575,7 +575,7 @@ void CExtensionManager::TryAutoload()
|
||||
}
|
||||
|
||||
char file[PLATFORM_MAX_PATH];
|
||||
len = ke::SafeSprintf(file, sizeof(file), "%s", lfile);
|
||||
len = ke::SafeStrcpy(file, sizeof(file), lfile);
|
||||
strcpy(&file[len - 9], ".ext");
|
||||
|
||||
LoadAutoExtension(file);
|
||||
@@ -591,7 +591,7 @@ IExtension *CExtensionManager::LoadAutoExtension(const char *path, bool bErrorOn
|
||||
if (strcmp(ext, PLATFORM_LIB_EXT) == 0)
|
||||
{
|
||||
char path2[PLATFORM_MAX_PATH];
|
||||
ke::SafeSprintf(path2, sizeof(path2), "%s", path);
|
||||
ke::SafeStrcpy(path2, sizeof(path2), path);
|
||||
path2[strlen(path) - strlen(PLATFORM_LIB_EXT) - 1] = '\0';
|
||||
return LoadAutoExtension(path2, bErrorOnMissing);
|
||||
}
|
||||
@@ -683,7 +683,7 @@ IExtension *CExtensionManager::LoadExtension(const char *file, char *error, size
|
||||
if (strcmp(ext, PLATFORM_LIB_EXT) == 0)
|
||||
{
|
||||
char path2[PLATFORM_MAX_PATH];
|
||||
ke::SafeSprintf(path2, sizeof(path2), "%s", file);
|
||||
ke::SafeStrcpy(path2, sizeof(path2), file);
|
||||
path2[strlen(file) - strlen(PLATFORM_LIB_EXT) - 1] = '\0';
|
||||
return LoadExtension(path2, error, maxlength);
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ void LibrarySystem::GetPlatformErrorEx(int code, char *error, size_t maxlength)
|
||||
const char *ae = strerror_r(code, error, maxlength);
|
||||
if (ae != error)
|
||||
{
|
||||
ke::SafeSprintf(error, maxlength, "%s", ae);
|
||||
ke::SafeStrcpy(error, maxlength, ae);
|
||||
}
|
||||
#elif defined PLATFORM_POSIX
|
||||
strerror_r(code, error, maxlength);
|
||||
@@ -309,12 +309,12 @@ size_t LibrarySystem::GetFileFromPath(char *buffer, size_t maxlength, const char
|
||||
#endif
|
||||
)
|
||||
{
|
||||
return ke::SafeSprintf(buffer, maxlength, "%s", &path[i+1]);
|
||||
return ke::SafeStrcpy(buffer, maxlength, &path[i+1]);
|
||||
}
|
||||
}
|
||||
|
||||
/* We scanned and found no path separator */
|
||||
return ke::SafeSprintf(buffer, maxlength, "%s", path);
|
||||
return ke::SafeStrcpy(buffer, maxlength, path);
|
||||
}
|
||||
|
||||
bool LibrarySystem::FileTime(const char *path, FileTimeType type, time_t *pTime)
|
||||
|
||||
@@ -56,7 +56,7 @@ ConfigResult Logger::OnSourceModConfigChanged(const char *key,
|
||||
} else if (strcasecmp(value, "off") == 0) {
|
||||
state = false;
|
||||
} else {
|
||||
ke::SafeSprintf(error, maxlength, "Invalid value: must be \"on\" or \"off\"");
|
||||
ke::SafeStrcpy(error, maxlength, "Invalid value: must be \"on\" or \"off\"");
|
||||
return ConfigResult_Reject;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ ConfigResult Logger::OnSourceModConfigChanged(const char *key,
|
||||
} else if (strcasecmp(value, "game") == 0) {
|
||||
m_Mode = LoggingMode_Game;
|
||||
} else {
|
||||
ke::SafeSprintf(error, maxlength, "Invalid value: must be [daily|map|game]");
|
||||
ke::SafeStrcpy(error, maxlength, "Invalid value: must be [daily|map|game]");
|
||||
return ConfigResult_Reject;
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -77,7 +77,7 @@ CPlugin::CPlugin(const char *file)
|
||||
m_serial = ++MySerial;
|
||||
m_errormsg[0] = '\0';
|
||||
m_DateTime[0] = '\0';
|
||||
ke::SafeSprintf(m_filename, sizeof(m_filename), "%s", file);
|
||||
ke::SafeStrcpy(m_filename, sizeof(m_filename), file);
|
||||
|
||||
memset(&m_info, 0, sizeof(m_info));
|
||||
|
||||
@@ -907,7 +907,7 @@ void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpa
|
||||
if (localpath == NULL)
|
||||
{
|
||||
/* If no path yet, don't add a former slash */
|
||||
ke::SafeSprintf(new_local, sizeof(new_local), "%s", dir->GetEntryName());
|
||||
ke::SafeStrcpy(new_local, sizeof(new_local), dir->GetEntryName());
|
||||
} else {
|
||||
libsys->PathFormat(new_local, sizeof(new_local), "%s/%s", localpath, dir->GetEntryName());
|
||||
}
|
||||
@@ -922,7 +922,7 @@ void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpa
|
||||
char plugin[PLATFORM_MAX_PATH];
|
||||
if (localpath == NULL)
|
||||
{
|
||||
ke::SafeSprintf(plugin, sizeof(plugin), "%s", name);
|
||||
ke::SafeStrcpy(plugin, sizeof(plugin), name);
|
||||
} else {
|
||||
libsys->PathFormat(plugin, sizeof(plugin), "%s/%s", localpath, name);
|
||||
}
|
||||
@@ -1019,9 +1019,9 @@ IPlugin *CPluginManager::LoadPlugin(const char *path, bool debug, PluginType typ
|
||||
|
||||
if (res == LoadRes_NeverLoad) {
|
||||
if (m_LoadingLocked)
|
||||
ke::SafeSprintf(error, maxlength, "There is a global plugin loading lock in effect");
|
||||
ke::SafeStrcpy(error, maxlength, "There is a global plugin loading lock in effect");
|
||||
else
|
||||
ke::SafeSprintf(error, maxlength, "This plugin is blocked from loading (see plugin_settings.cfg)");
|
||||
ke::SafeStrcpy(error, maxlength, "This plugin is blocked from loading (see plugin_settings.cfg)");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1302,7 +1302,7 @@ bool CPluginManager::MalwareCheckPass(CPlugin *pPlugin)
|
||||
unsigned char *pCodeHash = pPlugin->GetRuntime()->GetCodeHash();
|
||||
|
||||
char codeHashBuf[40];
|
||||
ke::SafeSprintf(codeHashBuf, 40, "plugin_");
|
||||
ke::SafeStrcpy(codeHashBuf, sizeof(codeHashBuf), "plugin_");
|
||||
for (int i = 0; i < 16; i++)
|
||||
ke::SafeSprintf(codeHashBuf + 7 + (i * 2), 3, "%02x", pCodeHash[i]);
|
||||
|
||||
@@ -1632,7 +1632,7 @@ ConfigResult CPluginManager::OnSourceModConfigChanged(const char *key,
|
||||
} else if (strcasecmp(value, "no") == 0) {
|
||||
m_bBlockBadPlugins = false;
|
||||
} else {
|
||||
ke::SafeSprintf(error, maxlength, "Invalid value: must be \"yes\" or \"no\"");
|
||||
ke::SafeStrcpy(error, maxlength, "Invalid value: must be \"yes\" or \"no\"");
|
||||
return ConfigResult_Reject;
|
||||
}
|
||||
return ConfigResult_Accept;
|
||||
@@ -1758,7 +1758,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg
|
||||
if (pl->GetStatus() < Plugin_Created || pl->GetStatus() == Plugin_Evicted)
|
||||
{
|
||||
if (pl->IsSilentlyFailed())
|
||||
len += ke::SafeSprintf(&buffer[len], sizeof(buffer)-len, " Disabled:");
|
||||
len += ke::SafeStrcpy(&buffer[len], sizeof(buffer)-len, " Disabled:");
|
||||
len += ke::SafeSprintf(&buffer[len], sizeof(buffer)-len, " \"%s\"", (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename());
|
||||
if (IS_STR_FILLED(info->version))
|
||||
{
|
||||
@@ -1867,11 +1867,11 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg
|
||||
if (pl->GetStatus() < Plugin_Created)
|
||||
{
|
||||
const sm_plugininfo_t *info = pl->GetPublicInfo();
|
||||
ke::SafeSprintf(name, sizeof(name), (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename());
|
||||
ke::SafeStrcpy(name, sizeof(name), (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename());
|
||||
}
|
||||
else
|
||||
{
|
||||
ke::SafeSprintf(name, sizeof(name), "%s", pl->GetFilename());
|
||||
ke::SafeStrcpy(name, sizeof(name), pl->GetFilename());
|
||||
}
|
||||
|
||||
if (UnloadPlugin(pl))
|
||||
|
||||
@@ -256,7 +256,7 @@ static bool sm_dump_handles(int client, const ICommandArgs *args)
|
||||
auto write_handles_to_game = [] (const char *str) -> void
|
||||
{
|
||||
char buffer[1024];
|
||||
size_t len = ke::SafeSprintf(buffer, sizeof(buffer)-2, "%s", str);
|
||||
size_t len = ke::SafeStrcpy(buffer, sizeof(buffer)-2, str);
|
||||
|
||||
buffer[len] = '\n';
|
||||
buffer[len+1] = '\0';
|
||||
|
||||
@@ -144,7 +144,7 @@ SMCError TextParsers::ParseSMCFile(const char *file,
|
||||
fclose(fp);
|
||||
|
||||
errstr = GetSMCErrorString(result);
|
||||
ke::SafeSprintf(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error");
|
||||
ke::SafeStrcpy(buffer, maxsize, errstr != NULL ? errstr : "Unknown error");
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -195,7 +195,7 @@ SMCError TextParsers::ParseSMCStream(const char *stream,
|
||||
result = ParseStream_SMC(&rs, RawStreamReader, smc_listener, states);
|
||||
|
||||
const char *errstr = GetSMCErrorString(result);
|
||||
ke::SafeSprintf(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error");
|
||||
ke::SafeStrcpy(buffer, maxsize, errstr != NULL ? errstr : "Unknown error");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -940,7 +940,7 @@ bool Translator::AddLanguage(const char *langcode, const char *description)
|
||||
Language *pLanguage = new Language;
|
||||
idx = m_Languages.size();
|
||||
|
||||
ke::SafeSprintf(pLanguage->m_code2, sizeof(pLanguage->m_code2), "%s", langcode);
|
||||
ke::SafeStrcpy(pLanguage->m_code2, sizeof(pLanguage->m_code2), langcode);
|
||||
pLanguage->m_CanonicalName = m_pStringTab->AddString(lower);
|
||||
|
||||
m_LCodeLookup.insert(langcode, idx);
|
||||
|
||||
@@ -68,7 +68,7 @@ static cell_t sm_LoadTranslations(IPluginContext *pCtx, const cell_t *params)
|
||||
IPlugin *pl = pluginsys->FindPluginByContext(pCtx->GetContext());
|
||||
|
||||
pCtx->LocalToString(params[1], &filename);
|
||||
ke::SafeSprintf(buffer, sizeof(buffer), "%s", filename);
|
||||
ke::SafeStrcpy(buffer, sizeof(buffer), filename);
|
||||
|
||||
/* Make sure there is no extension */
|
||||
if ((ext = strstr(buffer, ".txt")) != NULL
|
||||
|
||||
@@ -1171,18 +1171,12 @@ reswitch:
|
||||
int userid;
|
||||
if (!bridge->DescribePlayer(*value, &name, &auth, &userid))
|
||||
return pCtx->ThrowNativeError("Client index %d is invalid (arg %d)", *value, arg);
|
||||
ke::SafeSprintf(buffer,
|
||||
sizeof(buffer),
|
||||
"%s<%d><%s><>",
|
||||
name,
|
||||
userid,
|
||||
auth);
|
||||
|
||||
ke::SafeSprintf(buffer, sizeof(buffer), "%s<%d><%s><>", name, userid, auth);
|
||||
}
|
||||
else
|
||||
{
|
||||
ke::SafeSprintf(buffer,
|
||||
sizeof(buffer),
|
||||
"Console<0><Console><Console>");
|
||||
ke::SafeStrcpy(buffer, sizeof(buffer), "Console<0><Console><Console>");
|
||||
}
|
||||
if (!AddString(&buf_p, llen, buffer, width, prec, flags))
|
||||
return pCtx->ThrowNativeError("Escaped string would be truncated (arg %d)", arg);
|
||||
|
||||
Reference in New Issue
Block a user