mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 06:55:30 +00:00
Merge branch '3930-gcc-12-static-analyzer-warning-dereference-of-null-in-in-siphash-c' into 'main'
Resolve "GCC 12 static analyzer: warning: dereference of NULL 'in' in siphash.c" Closes #3930 See merge request isc-projects/bind9!7656
This commit is contained in:
@@ -90,51 +90,52 @@ isc_siphash24(const uint8_t *k, const uint8_t *in, const size_t inlen,
|
|||||||
|
|
||||||
uint64_t b = ((uint64_t)inlen) << 56;
|
uint64_t b = ((uint64_t)inlen) << 56;
|
||||||
|
|
||||||
const uint8_t *end = (in == NULL)
|
if (in != NULL && inlen != 0) {
|
||||||
? NULL
|
const uint8_t *end = in + inlen - (inlen % sizeof(uint64_t));
|
||||||
: in + inlen - (inlen % sizeof(uint64_t));
|
const size_t left = inlen & 7;
|
||||||
const size_t left = inlen & 7;
|
|
||||||
|
|
||||||
for (; in != end; in += 8) {
|
for (; in != end; in += 8) {
|
||||||
uint64_t m = case_sensitive
|
uint64_t m =
|
||||||
? ISC_U8TO64_LE(in)
|
case_sensitive
|
||||||
: isc_ascii_tolower8(ISC_U8TO64_LE(in));
|
? ISC_U8TO64_LE(in)
|
||||||
|
: isc_ascii_tolower8(ISC_U8TO64_LE(in));
|
||||||
|
|
||||||
v3 ^= m;
|
v3 ^= m;
|
||||||
|
|
||||||
for (size_t i = 0; i < cROUNDS; ++i) {
|
for (size_t i = 0; i < cROUNDS; ++i) {
|
||||||
SIPROUND(v0, v1, v2, v3);
|
SIPROUND(v0, v1, v2, v3);
|
||||||
|
}
|
||||||
|
|
||||||
|
v0 ^= m;
|
||||||
}
|
}
|
||||||
|
|
||||||
v0 ^= m;
|
switch (left) {
|
||||||
}
|
case 7:
|
||||||
|
b |= U8TO64_ONE(case_sensitive, in[6]) << 48;
|
||||||
switch (left) {
|
FALLTHROUGH;
|
||||||
case 7:
|
case 6:
|
||||||
b |= U8TO64_ONE(case_sensitive, in[6]) << 48;
|
b |= U8TO64_ONE(case_sensitive, in[5]) << 40;
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case 6:
|
case 5:
|
||||||
b |= U8TO64_ONE(case_sensitive, in[5]) << 40;
|
b |= U8TO64_ONE(case_sensitive, in[4]) << 32;
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case 5:
|
case 4:
|
||||||
b |= U8TO64_ONE(case_sensitive, in[4]) << 32;
|
b |= U8TO64_ONE(case_sensitive, in[3]) << 24;
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case 4:
|
case 3:
|
||||||
b |= U8TO64_ONE(case_sensitive, in[3]) << 24;
|
b |= U8TO64_ONE(case_sensitive, in[2]) << 16;
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case 3:
|
case 2:
|
||||||
b |= U8TO64_ONE(case_sensitive, in[2]) << 16;
|
b |= U8TO64_ONE(case_sensitive, in[1]) << 8;
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case 2:
|
case 1:
|
||||||
b |= U8TO64_ONE(case_sensitive, in[1]) << 8;
|
b |= U8TO64_ONE(case_sensitive, in[0]);
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case 1:
|
case 0:
|
||||||
b |= U8TO64_ONE(case_sensitive, in[0]);
|
break;
|
||||||
FALLTHROUGH;
|
default:
|
||||||
case 0:
|
UNREACHABLE();
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v3 ^= b;
|
v3 ^= b;
|
||||||
@@ -173,39 +174,40 @@ isc_halfsiphash24(const uint8_t *k, const uint8_t *in, const size_t inlen,
|
|||||||
|
|
||||||
uint32_t b = ((uint32_t)inlen) << 24;
|
uint32_t b = ((uint32_t)inlen) << 24;
|
||||||
|
|
||||||
const uint8_t *end = (in == NULL)
|
if (in != NULL && inlen != 0) {
|
||||||
? NULL
|
const uint8_t *end = in + inlen - (inlen % sizeof(uint32_t));
|
||||||
: in + inlen - (inlen % sizeof(uint32_t));
|
const int left = inlen & 3;
|
||||||
const int left = inlen & 3;
|
|
||||||
|
|
||||||
for (; in != end; in += 4) {
|
for (; in != end; in += 4) {
|
||||||
uint32_t m = case_sensitive
|
uint32_t m =
|
||||||
? ISC_U8TO32_LE(in)
|
case_sensitive
|
||||||
: isc_ascii_tolower4(ISC_U8TO32_LE(in));
|
? ISC_U8TO32_LE(in)
|
||||||
|
: isc_ascii_tolower4(ISC_U8TO32_LE(in));
|
||||||
|
|
||||||
v3 ^= m;
|
v3 ^= m;
|
||||||
|
|
||||||
for (size_t i = 0; i < cROUNDS; ++i) {
|
for (size_t i = 0; i < cROUNDS; ++i) {
|
||||||
HALFSIPROUND(v0, v1, v2, v3);
|
HALFSIPROUND(v0, v1, v2, v3);
|
||||||
|
}
|
||||||
|
|
||||||
|
v0 ^= m;
|
||||||
}
|
}
|
||||||
|
|
||||||
v0 ^= m;
|
switch (left) {
|
||||||
}
|
case 3:
|
||||||
|
b |= U8TO32_ONE(case_sensitive, in[2]) << 16;
|
||||||
switch (left) {
|
FALLTHROUGH;
|
||||||
case 3:
|
case 2:
|
||||||
b |= U8TO32_ONE(case_sensitive, in[2]) << 16;
|
b |= U8TO32_ONE(case_sensitive, in[1]) << 8;
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case 2:
|
case 1:
|
||||||
b |= U8TO32_ONE(case_sensitive, in[1]) << 8;
|
b |= U8TO32_ONE(case_sensitive, in[0]);
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case 1:
|
case 0:
|
||||||
b |= U8TO32_ONE(case_sensitive, in[0]);
|
break;
|
||||||
FALLTHROUGH;
|
default:
|
||||||
case 0:
|
UNREACHABLE();
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v3 ^= b;
|
v3 ^= b;
|
||||||
|
Reference in New Issue
Block a user