mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 22:37:03 +00:00
[10340] Some fixes for recent chat code changes.
* Fixed crash at absent optional literal. Thanks to MysteriousSouL for reproting. * Converted mode commands use new way parsing functions with fixing posible crash cases.
This commit is contained in:
parent
a202b33702
commit
8b99ac7298
4 changed files with 115 additions and 153 deletions
|
|
@ -2202,33 +2202,40 @@ char* ChatHandler::ExtractLiteralArg(char** args, char const* lit /*= NULL*/)
|
|||
|
||||
if (lit)
|
||||
{
|
||||
int diff = strncmp(head, lit, strlen(lit));
|
||||
int l = strlen(lit);
|
||||
int diff = strncmp(head, lit, l);
|
||||
|
||||
if (diff > 0)
|
||||
if (diff != 0)
|
||||
return NULL;
|
||||
|
||||
if (diff < 0 && !head[-diff] && !isWhiteSpace(head[-diff]))
|
||||
if (head[l] && !isWhiteSpace(head[l]))
|
||||
return NULL;
|
||||
|
||||
char* arg = head;
|
||||
|
||||
if (head[-diff])
|
||||
if (head[l])
|
||||
{
|
||||
head[-diff] = '\0';
|
||||
head[l] = '\0';
|
||||
|
||||
head += -diff + 1;
|
||||
head += l + 1;
|
||||
|
||||
*args = head;
|
||||
}
|
||||
else
|
||||
*args = NULL;
|
||||
*args = head + l;
|
||||
|
||||
SkipWhiteSpaces(args);
|
||||
return arg;
|
||||
}
|
||||
|
||||
char* name = strtok(head, " ");
|
||||
*args = strtok(NULL, "");
|
||||
|
||||
char* tail = strtok(NULL, "");
|
||||
|
||||
*args = tail ? tail : (char*)""; // *args don't must be NULL
|
||||
|
||||
SkipWhiteSpaces(args);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
|
@ -2255,7 +2262,8 @@ char* ChatHandler::ExtractQuotedArg( char** args )
|
|||
|
||||
char* str = strtok((*args)+1, guard); // skip start guard symbol
|
||||
|
||||
*args = strtok(NULL, "");
|
||||
char* tail = strtok(NULL, "");
|
||||
*args = tail ? tail : (char*)""; // *args don't must be NULL
|
||||
|
||||
SkipWhiteSpaces(args);
|
||||
|
||||
|
|
@ -2522,7 +2530,7 @@ char* ChatHandler::ExtractOptNotLastArg(char** args)
|
|||
return arg;
|
||||
|
||||
// optional name not found
|
||||
*args = arg;
|
||||
*args = arg ? arg : (char*)""; // *args don't must be NULL
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue