From 862f25b2234f4da4875fec5246a3bf2c07330a0d Mon Sep 17 00:00:00 2001 From: Borja Ferrer Date: Mon, 19 Mar 2007 19:19:41 +0000 Subject: [PATCH] fixed possible overflow cases --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40657 --- core/sm_srvcmds.cpp | 2 +- core/sm_stringutil.cpp | 8 +++++++- core/systems/LibrarySys.cpp | 2 +- plugins/include/sourcemod.inc | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/sm_srvcmds.cpp b/core/sm_srvcmds.cpp index 6f6119a3..568f3b28 100644 --- a/core/sm_srvcmds.cpp +++ b/core/sm_srvcmds.cpp @@ -158,7 +158,7 @@ void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text) char buffer[255]; size_t len, cmdlen = strlen(cmd); - len = snprintf(buffer, sizeof(buffer), " %s", cmd); + len = UTIL_Format(buffer, sizeof(buffer), " %s", cmd); if (cmdlen < 16) { size_t num = 16 - cmdlen; diff --git a/core/sm_stringutil.cpp b/core/sm_stringutil.cpp index 235a790b..57806aa1 100644 --- a/core/sm_stringutil.cpp +++ b/core/sm_stringutil.cpp @@ -890,7 +890,13 @@ size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...) size_t len = vsnprintf(buffer, maxlength, fmt, ap); va_end(ap); - return (len >= maxlength) ? (maxlength - 1) : len; + if (len >= maxlength) + { + buffer[maxlength - 1] = '\0'; + return (maxlength - 1); + } else { + return len; + } } char *sm_strdup(const char *str) diff --git a/core/systems/LibrarySys.cpp b/core/systems/LibrarySys.cpp index aa3b1d25..cc52530d 100644 --- a/core/systems/LibrarySys.cpp +++ b/core/systems/LibrarySys.cpp @@ -305,7 +305,7 @@ size_t LibrarySystem::PathFormat(char *buffer, size_t len, const char *fmt, ...) size_t mylen = vsnprintf(buffer, len, fmt, ap); va_end(ap); - mylen = (mylen >= len) ? (len - 1) : mylen; + mylen = (mylen >= len) ? len : mylen; for (size_t i=0; i