void censorArgvArray(int argc, char** argv) { invariant(gGatherOptionsDone); // Algorithm: For each arg in argv: // Look for an equal sign in arg; if there is one, temporarily nul it out. // check to see if arg is a password switch. If so, overwrite the value // component with xs. // restore the nul'd out equal sign, if any. for (int i = 0; i < argc; ++i) { char* const arg = argv[i]; char* const firstEqSign = strchr(arg, '='); if (nullptr != firstEqSign) { *firstEqSign = '\0'; } if (_isPasswordSwitch(arg)) { if (nullptr == firstEqSign) { if (i + 1 < argc) { _redact(argv[i + 1]); } } else { _redact(firstEqSign + 1); } } else if ((strlen(arg) > 2) && _isPasswordSwitch(std::string(arg, 2))) { // e.g. "-ppassword" _redact(argv[i] + 2); } if (nullptr != firstEqSign) { *firstEqSign = '='; } } }
void CmdLine::censor(int argc, char** argv) { // Algorithm: For each arg in argv: // Look for an equal sign in arg; if there is one, temporarily nul it out. // check to see if arg is a password switch. If so, overwrite the value // component with xs. // restore the nul'd out equal sign, if any. for (int i = 0; i < argc; ++i) { char* const arg = argv[i]; char* const firstEqSign = strchr(arg, '='); if (NULL != firstEqSign) { *firstEqSign = '\0'; } if (_isPasswordSwitch(arg)) { if (NULL == firstEqSign) { if (i + 1 < argc) { _redact(argv[i + 1]); } } else { _redact(firstEqSign + 1); } } if (NULL != firstEqSign) { *firstEqSign = '='; } } }