forked from mirrors/gecko-dev
Bug 1705659 - Static-analysis check auto fix for auth code r=necko-reviewers,dragana
Depends on D112604 Differential Revision: https://phabricator.services.mozilla.com/D112605
This commit is contained in:
parent
d2935ca6c0
commit
0cfda7bb4a
8 changed files with 68 additions and 57 deletions
|
|
@ -192,10 +192,10 @@ static nsresult gssInit() {
|
|||
|
||||
LOG(("Attempting to load gss functions\n"));
|
||||
|
||||
for (size_t i = 0; i < ArrayLength(gssFuncs); ++i) {
|
||||
gssFuncs[i].func = PR_FindFunctionSymbol(lib, gssFuncs[i].str);
|
||||
if (!gssFuncs[i].func) {
|
||||
LOG(("Fail to load %s function from gssapi library\n", gssFuncs[i].str));
|
||||
for (auto& gssFunc : gssFuncs) {
|
||||
gssFunc.func = PR_FindFunctionSymbol(lib, gssFunc.str);
|
||||
if (!gssFunc.func) {
|
||||
LOG(("Fail to load %s function from gssapi library\n", gssFunc.str));
|
||||
PR_UnloadLibrary(lib);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
|
@ -447,17 +447,19 @@ nsAuthGSSAPI::GetNextToken(const void* inToken, uint32_t inTokenLen,
|
|||
}
|
||||
|
||||
*outTokenLen = output_token.length;
|
||||
if (output_token.length != 0)
|
||||
if (output_token.length != 0) {
|
||||
*outToken = moz_xmemdup(output_token.value, output_token.length);
|
||||
else
|
||||
} else {
|
||||
*outToken = nullptr;
|
||||
}
|
||||
|
||||
gss_release_buffer_ptr(&minor_status, &output_token);
|
||||
|
||||
if (major_status == GSS_S_COMPLETE)
|
||||
if (major_status == GSS_S_COMPLETE) {
|
||||
rv = NS_SUCCESS_AUTH_FINISHED;
|
||||
else
|
||||
} else {
|
||||
rv = NS_OK;
|
||||
}
|
||||
|
||||
end:
|
||||
gss_release_name_ptr(&minor_status, &server);
|
||||
|
|
@ -489,10 +491,11 @@ nsAuthGSSAPI::Unwrap(const void* inToken, uint32_t inTokenLen, void** outToken,
|
|||
|
||||
*outTokenLen = output_token.length;
|
||||
|
||||
if (output_token.length)
|
||||
if (output_token.length) {
|
||||
*outToken = moz_xmemdup(output_token.value, output_token.length);
|
||||
else
|
||||
} else {
|
||||
*outToken = nullptr;
|
||||
}
|
||||
|
||||
gss_release_buffer_ptr(&minor_status, &output_token);
|
||||
|
||||
|
|
|
|||
|
|
@ -48,8 +48,9 @@ static bool SpawnIOChild(char* const* aArgs, PRProcess** aPID,
|
|||
PRFileDesc** aFromChildFD, PRFileDesc** aToChildFD) {
|
||||
PRFileDesc* toChildPipeRead;
|
||||
PRFileDesc* toChildPipeWrite;
|
||||
if (PR_CreatePipe(&toChildPipeRead, &toChildPipeWrite) != PR_SUCCESS)
|
||||
if (PR_CreatePipe(&toChildPipeRead, &toChildPipeWrite) != PR_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
PR_SetFDInheritable(toChildPipeRead, true);
|
||||
PR_SetFDInheritable(toChildPipeWrite, false);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class nsAuthSambaNTLM final : public nsIAuthModule {
|
|||
void Shutdown();
|
||||
|
||||
uint8_t* mInitialMessage; /* free with free() */
|
||||
uint32_t mInitialMessageLen;
|
||||
uint32_t mInitialMessageLen{};
|
||||
PRProcess* mChildPID;
|
||||
PRFileDesc* mFromChildFD;
|
||||
PRFileDesc* mToChildFD;
|
||||
|
|
|
|||
|
|
@ -175,10 +175,9 @@ class nsHttpAuthCache {
|
|||
// null, then the entry is deleted.
|
||||
[[nodiscard]] nsresult SetAuthEntry(
|
||||
const nsACString& scheme, const nsACString& host, int32_t port,
|
||||
const nsACString& directory, const nsACString& realm,
|
||||
const nsACString& credentials, const nsACString& challenge,
|
||||
nsACString const& originSuffix, const nsHttpAuthIdentity* ident,
|
||||
nsISupports* metadata);
|
||||
const nsACString& path, const nsACString& realm, const nsACString& creds,
|
||||
const nsACString& challenge, nsACString const& originSuffix,
|
||||
const nsHttpAuthIdentity* ident, nsISupports* metadata);
|
||||
|
||||
void ClearAuthEntry(const nsACString& scheme, const nsACString& host,
|
||||
int32_t port, const nsACString& realm,
|
||||
|
|
|
|||
|
|
@ -56,13 +56,11 @@ nsHttpAuthManager::GetAuthIdentity(
|
|||
}
|
||||
|
||||
if (!aPath.IsEmpty()) {
|
||||
rv = auth_cache->GetAuthEntryForPath(
|
||||
aScheme, aHost,
|
||||
aPort, aPath, originSuffix, &entry);
|
||||
rv = auth_cache->GetAuthEntryForPath(aScheme, aHost, aPort, aPath,
|
||||
originSuffix, &entry);
|
||||
} else {
|
||||
rv = auth_cache->GetAuthEntryForDomain(
|
||||
aScheme, aHost,
|
||||
aPort, aRealm, originSuffix, &entry);
|
||||
rv = auth_cache->GetAuthEntryForDomain(aScheme, aHost, aPort, aRealm,
|
||||
originSuffix, &entry);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class nsHttpDigestAuth final : public nsIHttpAuthenticator {
|
|||
[[nodiscard]] nsresult CalculateHA2(const nsCString& http_method,
|
||||
const nsCString& http_uri_path,
|
||||
uint16_t algorithm, uint16_t qop,
|
||||
const char* body_digest, char* result);
|
||||
const char* bodyDigest, char* result);
|
||||
|
||||
// result is in mHashBuf
|
||||
[[nodiscard]] nsresult DigestHash(const char* buf, uint32_t len,
|
||||
|
|
|
|||
|
|
@ -184,10 +184,11 @@ static void LogBuf(const char* tag, const uint8_t* buf, uint32_t bufLen) {
|
|||
snprintf(line + len, sizeof(line) - len, " ");
|
||||
for (i = 0; i < count; ++i) {
|
||||
len = strlen(line);
|
||||
if (isprint(buf[i]))
|
||||
if (isprint(buf[i])) {
|
||||
snprintf(line + len, sizeof(line) - len, "%c", buf[i]);
|
||||
else
|
||||
} else {
|
||||
snprintf(line + len, sizeof(line) - len, ".");
|
||||
}
|
||||
}
|
||||
PR_LogPrint("%s\n", line);
|
||||
|
||||
|
|
@ -407,17 +408,19 @@ static nsresult ParseType2Msg(const void* inBuf, uint32_t inLen,
|
|||
//
|
||||
if (inLen < NTLM_TYPE2_HEADER_LEN) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
auto cursor = static_cast<const uint8_t*>(inBuf);
|
||||
const auto* cursor = static_cast<const uint8_t*>(inBuf);
|
||||
|
||||
// verify NTLMSSP signature
|
||||
if (memcmp(cursor, NTLM_SIGNATURE, sizeof(NTLM_SIGNATURE)) != 0)
|
||||
if (memcmp(cursor, NTLM_SIGNATURE, sizeof(NTLM_SIGNATURE)) != 0) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
cursor += sizeof(NTLM_SIGNATURE);
|
||||
|
||||
// verify Type-2 marker
|
||||
if (memcmp(cursor, NTLM_TYPE2_MARKER, sizeof(NTLM_TYPE2_MARKER)) != 0)
|
||||
if (memcmp(cursor, NTLM_TYPE2_MARKER, sizeof(NTLM_TYPE2_MARKER)) != 0) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
cursor += sizeof(NTLM_TYPE2_MARKER);
|
||||
|
||||
|
|
@ -488,7 +491,7 @@ static nsresult GenerateType3Msg(const nsString& domain,
|
|||
// inBuf contains Type-2 msg (the challenge) from server
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
nsresult rv;
|
||||
Type2Msg msg;
|
||||
Type2Msg msg{};
|
||||
|
||||
rv = ParseType2Msg(inBuf, inLen, &msg);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
|
@ -497,8 +500,7 @@ static nsresult GenerateType3Msg(const nsString& domain,
|
|||
|
||||
// There is no negotiation for NTLMv2, so we just do it unless we are forced
|
||||
// by explict user configuration to use the older DES-based cryptography.
|
||||
bool ntlmv2 =
|
||||
mozilla::StaticPrefs::network_auth_force_generic_ntlm_v1() == false;
|
||||
bool ntlmv2 = !mozilla::StaticPrefs::network_auth_force_generic_ntlm_v1();
|
||||
|
||||
// temporary buffers for unicode strings
|
||||
#ifdef IS_BIG_ENDIAN
|
||||
|
|
@ -790,7 +792,7 @@ static nsresult GenerateType3Msg(const nsString& domain,
|
|||
return rv;
|
||||
}
|
||||
|
||||
auto sessionHash = mozilla::BitwiseCast<const uint8_t*, const char*>(
|
||||
const auto* sessionHash = mozilla::BitwiseCast<const uint8_t*, const char*>(
|
||||
sessionHashString.get());
|
||||
|
||||
LogBuf("NTLM2 effective key: ", sessionHash, 8);
|
||||
|
|
@ -1001,10 +1003,11 @@ nsNTLMAuthModule::Wrap(const void* inToken, uint32_t inTokenLen,
|
|||
static uint8_t des_setkeyparity(uint8_t x) {
|
||||
if ((((x >> 7) ^ (x >> 6) ^ (x >> 5) ^ (x >> 4) ^ (x >> 3) ^ (x >> 2) ^
|
||||
(x >> 1)) &
|
||||
0x01) == 0)
|
||||
0x01) == 0) {
|
||||
x |= 0x01;
|
||||
else
|
||||
} else {
|
||||
x &= 0xfe;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,31 +51,35 @@ TEST(Tokenizer, HTTPResponse)
|
|||
p.SkipWhites();
|
||||
|
||||
p.Record();
|
||||
while (p.Next(t) && t.Type() != Tokenizer::TOKEN_EOL)
|
||||
while (p.Next(t) && t.Type() != Tokenizer::TOKEN_EOL) {
|
||||
;
|
||||
}
|
||||
EXPECT_FALSE(p.HasFailed());
|
||||
nsAutoCString h;
|
||||
p.Claim(h);
|
||||
EXPECT_TRUE(h == "Not modified");
|
||||
|
||||
p.Record();
|
||||
while (p.CheckChar(HttpHeaderCharacter))
|
||||
while (p.CheckChar(HttpHeaderCharacter)) {
|
||||
;
|
||||
}
|
||||
p.Claim(h, Tokenizer::INCLUDE_LAST);
|
||||
EXPECT_TRUE(h == "ETag");
|
||||
p.SkipWhites();
|
||||
EXPECT_TRUE(p.CheckChar(':'));
|
||||
p.SkipWhites();
|
||||
p.Record();
|
||||
while (p.Next(t) && t.Type() != Tokenizer::TOKEN_EOL)
|
||||
while (p.Next(t) && t.Type() != Tokenizer::TOKEN_EOL) {
|
||||
;
|
||||
}
|
||||
EXPECT_FALSE(p.HasFailed());
|
||||
p.Claim(h);
|
||||
EXPECT_TRUE(h == "hallo");
|
||||
|
||||
p.Record();
|
||||
while (p.CheckChar(HttpHeaderCharacter))
|
||||
while (p.CheckChar(HttpHeaderCharacter)) {
|
||||
;
|
||||
}
|
||||
p.Claim(h, Tokenizer::INCLUDE_LAST);
|
||||
EXPECT_TRUE(h == "Content-Length");
|
||||
p.SkipWhites();
|
||||
|
|
@ -88,8 +92,9 @@ TEST(Tokenizer, HTTPResponse)
|
|||
EXPECT_TRUE(p.CheckEOL());
|
||||
|
||||
p.Record();
|
||||
while (p.Next(t) && t.Type() != Tokenizer::TOKEN_EOF)
|
||||
while (p.Next(t) && t.Type() != Tokenizer::TOKEN_EOF) {
|
||||
;
|
||||
}
|
||||
nsAutoCString b;
|
||||
p.Claim(b);
|
||||
EXPECT_TRUE(b == "This is the body");
|
||||
|
|
@ -389,8 +394,9 @@ TEST(Tokenizer, HasFailed)
|
|||
|
||||
Tokenizer p1("a b"_ns);
|
||||
|
||||
while (p1.Next(t) && t.Type() != Tokenizer::TOKEN_CHAR)
|
||||
while (p1.Next(t) && t.Type() != Tokenizer::TOKEN_CHAR) {
|
||||
;
|
||||
}
|
||||
EXPECT_TRUE(p1.HasFailed());
|
||||
|
||||
Tokenizer p2("a b ?!c"_ns);
|
||||
|
|
@ -417,8 +423,9 @@ TEST(Tokenizer, HasFailed)
|
|||
EXPECT_TRUE(p2.Check(t));
|
||||
EXPECT_FALSE(p2.HasFailed());
|
||||
|
||||
while (p2.Next(t) && t.Type() != Tokenizer::TOKEN_CHAR)
|
||||
while (p2.Next(t) && t.Type() != Tokenizer::TOKEN_CHAR) {
|
||||
;
|
||||
}
|
||||
EXPECT_TRUE(p2.HasFailed());
|
||||
}
|
||||
|
||||
|
|
@ -938,7 +945,7 @@ TEST(Tokenizer, CustomRaw)
|
|||
|
||||
TEST(Tokenizer, Incremental)
|
||||
{
|
||||
typedef IncrementalTokenizer::Token Token;
|
||||
using Token = IncrementalTokenizer::Token;
|
||||
|
||||
int test = 0;
|
||||
IncrementalTokenizer i(
|
||||
|
|
@ -974,8 +981,8 @@ TEST(Tokenizer, Incremental)
|
|||
});
|
||||
|
||||
constexpr auto input = "test1,test2,,,test3"_ns;
|
||||
auto cur = input.BeginReading();
|
||||
auto end = input.EndReading();
|
||||
const auto* cur = input.BeginReading();
|
||||
const auto* end = input.EndReading();
|
||||
for (; cur < end; ++cur) {
|
||||
i.FeedInput(nsDependentCSubstring(cur, 1));
|
||||
}
|
||||
|
|
@ -987,7 +994,7 @@ TEST(Tokenizer, Incremental)
|
|||
|
||||
TEST(Tokenizer, IncrementalRollback)
|
||||
{
|
||||
typedef IncrementalTokenizer::Token Token;
|
||||
using Token = IncrementalTokenizer::Token;
|
||||
|
||||
int test = 0;
|
||||
IncrementalTokenizer i(
|
||||
|
|
@ -1027,8 +1034,8 @@ TEST(Tokenizer, IncrementalRollback)
|
|||
});
|
||||
|
||||
constexpr auto input = "test1,test2,,,test3"_ns;
|
||||
auto cur = input.BeginReading();
|
||||
auto end = input.EndReading();
|
||||
const auto* cur = input.BeginReading();
|
||||
const auto* end = input.EndReading();
|
||||
for (; cur < end; ++cur) {
|
||||
i.FeedInput(nsDependentCSubstring(cur, 1));
|
||||
}
|
||||
|
|
@ -1040,7 +1047,7 @@ TEST(Tokenizer, IncrementalRollback)
|
|||
|
||||
TEST(Tokenizer, IncrementalNeedMoreInput)
|
||||
{
|
||||
typedef IncrementalTokenizer::Token Token;
|
||||
using Token = IncrementalTokenizer::Token;
|
||||
|
||||
int test = 0;
|
||||
IncrementalTokenizer i(
|
||||
|
|
@ -1078,8 +1085,8 @@ TEST(Tokenizer, IncrementalNeedMoreInput)
|
|||
});
|
||||
|
||||
constexpr auto input = "a bb,c"_ns;
|
||||
auto cur = input.BeginReading();
|
||||
auto end = input.EndReading();
|
||||
const auto* cur = input.BeginReading();
|
||||
const auto* end = input.EndReading();
|
||||
|
||||
nsresult rv;
|
||||
for (; cur < end; ++cur) {
|
||||
|
|
@ -1099,7 +1106,7 @@ TEST(Tokenizer, IncrementalNeedMoreInput)
|
|||
|
||||
TEST(Tokenizer, IncrementalCustom)
|
||||
{
|
||||
typedef IncrementalTokenizer::Token Token;
|
||||
using Token = IncrementalTokenizer::Token;
|
||||
|
||||
int test = 0;
|
||||
Token custom;
|
||||
|
|
@ -1134,7 +1141,7 @@ TEST(Tokenizer, IncrementalCustom)
|
|||
|
||||
TEST(Tokenizer, IncrementalCustomRaw)
|
||||
{
|
||||
typedef IncrementalTokenizer::Token Token;
|
||||
using Token = IncrementalTokenizer::Token;
|
||||
|
||||
int test = 0;
|
||||
Token custom;
|
||||
|
|
@ -1177,8 +1184,8 @@ TEST(Tokenizer, IncrementalCustomRaw)
|
|||
i.SetTokenizingMode(Tokenizer::Mode::CUSTOM_ONLY);
|
||||
|
||||
constexpr auto input = "test1,test2!,,test3test2tes"_ns;
|
||||
auto cur = input.BeginReading();
|
||||
auto end = input.EndReading();
|
||||
const auto* cur = input.BeginReading();
|
||||
const auto* end = input.EndReading();
|
||||
for (; cur < end; ++cur) {
|
||||
i.FeedInput(nsDependentCSubstring(cur, 1));
|
||||
}
|
||||
|
|
@ -1190,7 +1197,7 @@ TEST(Tokenizer, IncrementalCustomRaw)
|
|||
|
||||
TEST(Tokenizer, IncrementalCustomRemove)
|
||||
{
|
||||
typedef IncrementalTokenizer::Token Token;
|
||||
using Token = IncrementalTokenizer::Token;
|
||||
|
||||
int test = 0;
|
||||
Token custom;
|
||||
|
|
@ -1223,7 +1230,7 @@ TEST(Tokenizer, IncrementalCustomRemove)
|
|||
|
||||
TEST(Tokenizer, IncrementalBuffering1)
|
||||
{
|
||||
typedef IncrementalTokenizer::Token Token;
|
||||
using Token = IncrementalTokenizer::Token;
|
||||
|
||||
int test = 0;
|
||||
Token custom;
|
||||
|
|
@ -1283,7 +1290,7 @@ TEST(Tokenizer, IncrementalBuffering1)
|
|||
|
||||
TEST(Tokenizer, IncrementalBuffering2)
|
||||
{
|
||||
typedef IncrementalTokenizer::Token Token;
|
||||
using Token = IncrementalTokenizer::Token;
|
||||
|
||||
int test = 0;
|
||||
Token custom;
|
||||
|
|
|
|||
Loading…
Reference in a new issue