Skip to content

Commit fa869ea

Browse files
jasnelladuh95
authored andcommitted
deps: fixup some minor coverity warnings
Fixes: #56611 PR-URL: #56612 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
1 parent 8c9eaf8 commit fa869ea

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

deps/ncrypto/ncrypto.cc

+16-2
Original file line numberDiff line numberDiff line change
@@ -1346,8 +1346,11 @@ DHPointer DHPointer::New(BignumPointer&& p, BignumPointer&& g) {
13461346
if (DH_set0_pqg(dh.get(), p.get(), nullptr, g.get()) != 1) return {};
13471347

13481348
// If the call above is successful, the DH object takes ownership of the
1349-
// BIGNUMs, so we must release them here.
1349+
// BIGNUMs, so we must release them here. Unfortunately coverity does not
1350+
// know that so we need to tell it not to complain.
1351+
// coverity[resource_leak]
13501352
p.release();
1353+
// coverity[resource_leak]
13511354
g.release();
13521355

13531356
return dh;
@@ -1430,7 +1433,10 @@ DataPointer DHPointer::generateKeys() const {
14301433

14311434
size_t DHPointer::size() const {
14321435
if (!dh_) return 0;
1433-
return DH_size(dh_.get());
1436+
int ret = DH_size(dh_.get());
1437+
// DH_size can return a -1 on error but we just want to return a 0
1438+
// in that case so we don't wrap around when returning the size_t.
1439+
return ret >= 0 ? static_cast<size_t>(ret) : 0;
14341440
}
14351441

14361442
DataPointer DHPointer::computeSecret(const BignumPointer& peer) const {
@@ -1459,6 +1465,10 @@ DataPointer DHPointer::computeSecret(const BignumPointer& peer) const {
14591465
bool DHPointer::setPublicKey(BignumPointer&& key) {
14601466
if (!dh_) return false;
14611467
if (DH_set0_key(dh_.get(), key.get(), nullptr) == 1) {
1468+
// If DH_set0_key returns successfully, then dh_ takes ownership of the
1469+
// BIGNUM, so we must release it here. Unfortunately coverity does not
1470+
// know that so we need to tell it not to complain.
1471+
// coverity[resource_leak]
14621472
key.release();
14631473
return true;
14641474
}
@@ -1468,6 +1478,10 @@ bool DHPointer::setPublicKey(BignumPointer&& key) {
14681478
bool DHPointer::setPrivateKey(BignumPointer&& key) {
14691479
if (!dh_) return false;
14701480
if (DH_set0_key(dh_.get(), nullptr, key.get()) == 1) {
1481+
// If DH_set0_key returns successfully, then dh_ takes ownership of the
1482+
// BIGNUM, so we must release it here. Unfortunately coverity does not
1483+
// know that so we need to tell it not to complain.
1484+
// coverity[resource_leak]
14711485
key.release();
14721486
return true;
14731487
}

0 commit comments

Comments
 (0)