From 5e00f7892099a3f6e75a7ce72c4c6dcee2ff3b0c Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Fri, 2 Jul 2021 11:14:54 -0700 Subject: [PATCH] Fix a number of Coverity findings - 1458048: Use-after-free in the SQLite logger - 1457823: Missing a break statement in script-opt reduction - 1453966: Dead code in CompHash - 1445417: Unintialized variable in StaticHash64 - 1437716: Unintialized variables in FileInfo in scan.l --- src/CompHash.cc | 2 +- src/Hash.cc | 2 +- src/logging/writers/sqlite/SQLite.cc | 3 ++- src/scan.l | 6 +++--- src/script_opt/Reduce.cc | 1 + 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/CompHash.cc b/src/CompHash.cc index cd556017cc..ad42a221a1 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -512,7 +512,7 @@ int CompositeHash::SingleTypeKeySize(Type* bt, const Val* v, if ( ! v ) return (optional && ! calc_static_size) ? sz : 0; - const RecordVal* rv = v ? v->AsRecordVal() : nullptr; + const RecordVal* rv = v->AsRecordVal(); RecordType* rt = bt->AsRecordType(); int num_fields = rt->NumFields(); diff --git a/src/Hash.cc b/src/Hash.cc index a056ce753d..a408b8504c 100644 --- a/src/Hash.cc +++ b/src/Hash.cc @@ -67,7 +67,7 @@ void KeyedHash::Hash256(const void* bytes, uint64_t size, hash256_t* result) hash64_t KeyedHash::StaticHash64(const void* bytes, uint64_t size) { - hash64_t result; + hash64_t result = 0; highwayhash::InstructionSets::Run(cluster_highwayhash_key, reinterpret_cast(bytes), size, &result); return result; } diff --git a/src/logging/writers/sqlite/SQLite.cc b/src/logging/writers/sqlite/SQLite.cc index af0e48bad3..faf80547c2 100644 --- a/src/logging/writers/sqlite/SQLite.cc +++ b/src/logging/writers/sqlite/SQLite.cc @@ -169,15 +169,16 @@ bool SQLite::DoInit(const WriterInfo& info, int arg_num_fields, } create += fieldname; - sqlite3_free(fieldname); string type = GetTableType(field->type, field->subtype); if ( type == "" ) { InternalError(Fmt("Could not determine type for field %u:%s", i, fieldname)); + sqlite3_free(fieldname); return false; } + sqlite3_free(fieldname); create += " " + type; /* if ( !field->optional ) { diff --git a/src/scan.l b/src/scan.l index 6948fe1022..e6af14cd89 100644 --- a/src/scan.l +++ b/src/scan.l @@ -106,9 +106,9 @@ public: YY_BUFFER_STATE buffer_state; std::string restore_module; - const char* name; - int line; - int level; + const char* name = nullptr; + int line = 0; + int level = 0; }; // A stack of input buffers we're scanning. file_stack[len-1] is the diff --git a/src/script_opt/Reduce.cc b/src/script_opt/Reduce.cc index cd4ba8d9ca..481e3a9afd 100644 --- a/src/script_opt/Reduce.cc +++ b/src/script_opt/Reduce.cc @@ -959,6 +959,7 @@ TraversalCode CSE_ValidityChecker::PreExpr(const Expr* e) return TC_ABORTALL; } } + break; case EXPR_APPEND_TO: // This doesn't directly change any identifiers, but does