aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Keresztes Schmidt <carbenium@outlook.com>2020-08-16 21:32:31 +0200
committerGitHub <noreply@github.com>2020-08-16 21:32:31 +0200
commit7edad0d601a7ae925cba850c5a23019f99be2a1e (patch)
tree889abb5eaecdca2a2b950d9fa233c3f3275ba7bb
parentca25e8d0199730c0976ebc37317e9407aceccc34 (diff)
Core/ChatCommands: Do not parse partial strings for numeric paramters (PR #25259)
Check if integral/floating point type arguments were parsed successfully. std::stoull will happily parse floating point strings until the decimal separator and return the value. Make sure for all parsing methods that we actually parsed the whole token. This allows to use handler arguments like Variant<uint32, float> which will be populated with the right type depending on the token value (e.g "10" vs "10.0").
-rw-r--r--src/server/game/Chat/ChatCommands/ChatCommandArgs.h24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h
index 242b806446d..c9e0723fbf8 100644
--- a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h
+++ b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h
@@ -51,7 +51,13 @@ struct ArgInfo<T, std::enable_if_t<std::is_integral_v<T> && std::is_signed_v<T>>
{
char const* next = args;
std::string token(args, tokenize(next));
- try { val = std::stoll(token); }
+ try
+ {
+ size_t processedChars = 0;
+ val = std::stoll(token, &processedChars, 0);
+ if (processedChars != token.length())
+ return nullptr;
+ }
catch (...) { return nullptr; }
return next;
}
@@ -65,7 +71,13 @@ struct ArgInfo<T, std::enable_if_t<std::is_integral_v<T> && std::is_unsigned_v<T
{
char const* next = args;
std::string token(args, tokenize(next));
- try { val = std::stoull(token); }
+ try
+ {
+ size_t processedChars = 0;
+ val = std::stoull(token, &processedChars, 0);
+ if (processedChars != token.length())
+ return nullptr;
+ }
catch (...) { return nullptr; }
return next;
}
@@ -79,7 +91,13 @@ struct ArgInfo<T, std::enable_if_t<std::is_floating_point_v<T>>>
{
char const* next = args;
std::string token(args, tokenize(next));
- try { val = std::stold(token); }
+ try
+ {
+ size_t processedChars = 0;
+ val = std::stold(token, &processedChars);
+ if (processedChars != token.length())
+ return nullptr;
+ }
catch (...) { return nullptr; }
return std::isfinite(val) ? next : nullptr;
}