aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Common/clearPasswordFromCommandLine.cpp
blob: 930ce523ce98edf57dfb961baa4560f279cf35fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <cstring>
#include <string_view>
#include <Common/clearPasswordFromCommandLine.h>

using namespace std::literals;

void clearPasswordFromCommandLine(int argc, char ** argv)
{
    for (int arg = 1; arg < argc; ++arg)
    {
        if (arg + 1 < argc && argv[arg] == "--password"sv)
        {
            ++arg;
            memset(argv[arg], 0, strlen(argv[arg]));
        }
        else if (0 == strncmp(argv[arg], "--password=", strlen("--password=")))
        {
            memset(argv[arg] + strlen("--password="), 0, strlen(argv[arg]) - strlen("--password="));
        }
    }
}