Check if source and destination overlap in serverAddMonUser
The source and destination strings for snprintf must not overlap. A simple check for the address of the source and destination should solve the case where they are the same. Behavior is undefined if the pointers aren't the same but the memory overlaps.
This commit is contained in:
@ -804,12 +804,15 @@ server_transfer_status(SERVER *dest_server, SERVER *source_server)
|
||||
void
|
||||
serverAddMonUser(SERVER *server, char *user, char *passwd)
|
||||
{
|
||||
if (snprintf(server->monuser, sizeof(server->monuser), "%s", user) > sizeof(server->monuser))
|
||||
if (user != server->monuser &&
|
||||
snprintf(server->monuser, sizeof(server->monuser), "%s", user) > sizeof(server->monuser))
|
||||
{
|
||||
MXS_WARNING("Truncated monitor user for server '%s', maximum username "
|
||||
"length is %lu characters.", server->unique_name, sizeof(server->monuser));
|
||||
}
|
||||
if (snprintf(server->monpw, sizeof(server->monpw), "%s", passwd) > sizeof(server->monpw))
|
||||
|
||||
if (passwd != server->monpw &&
|
||||
snprintf(server->monpw, sizeof(server->monpw), "%s", passwd) > sizeof(server->monpw))
|
||||
{
|
||||
MXS_WARNING("Truncated monitor password for server '%s', maximum password "
|
||||
"length is %lu characters.", server->unique_name, sizeof(server->monpw));
|
||||
|
Reference in New Issue
Block a user