]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
klocwork: fix risk issues
authorHong, Yang A <yang.a.hong@intel.com>
Tue, 31 May 2022 06:30:18 +0000 (06:30 +0000)
committerKonstantinos Margaritis <markos@freevec.org>
Tue, 5 Sep 2023 10:45:33 +0000 (13:45 +0300)
15 files changed:
src/nfa/goughcompile.cpp
src/nfa/repeatcompile.cpp
src/nfagraph/ng_som.cpp
src/nfagraph/ng_violet.cpp
src/parser/logical_combination.cpp
src/rose/rose_build_convert.cpp
src/smallwrite/smallwrite_build.cpp
src/util/graph_undirected.h
src/util/ue2string.h
tools/hsbench/data_corpus.cpp
tools/hsbench/main.cpp
tools/hscollider/DatabaseProxy.h
tools/hscollider/NfaGeneratedCorpora.cpp
tools/hscollider/Thread.cpp
util/ng_corpus_properties.cpp

index 3bf729b34720757c1395b669c4e897f4b38844f7..5d5c37df4056fc43db6db21707c0879bd88779cc 100644 (file)
@@ -206,6 +206,10 @@ void makeCFG_top_edge(GoughGraph &cfg, const vector<GoughVertex> &vertices,
             assert(contains(src_slots, slot_id));
 
             shared_ptr<GoughSSAVarMin> vmin = make_shared<GoughSSAVarMin>();
+            if (!vmin) {
+                assert(0);
+                throw std::bad_alloc();
+            }
             cfg[e].vars.emplace_back(vmin);
             final_var = vmin.get();
 
@@ -317,6 +321,10 @@ void makeCFG_edge(GoughGraph &cfg, const map<u32, u32> &som_creators,
             DEBUG_PRINTF("bypassing min on join %u\n", slot_id);
         } else {
             shared_ptr<GoughSSAVarMin> vmin = make_shared<GoughSSAVarMin>();
+            if (!vmin) {
+                assert(0);
+                throw std::bad_alloc();
+            }
             cfg[e].vars.emplace_back(vmin);
             final_var = vmin.get();
 
index 7376300182e7f309e31c4fffd085ed1e8b6511a0..60b513524fe3d88d2a32e688f998b0caeb2776be 100644 (file)
@@ -124,6 +124,10 @@ RepeatStateInfo::RepeatStateInfo(enum RepeatType type, const depth &repeatMin,
                                  const depth &repeatMax, u32 minPeriod)
     : stateSize(0), packedCtrlSize(0), horizon(0), patchCount(0),
       patchSize(0), encodingSize(0), patchesOffset(0) {
+    if (type == REPEAT_SPARSE_OPTIMAL_P && minPeriod == 0) {
+        assert(0);
+        throw std::domain_error("SPARSE_OPTIMAL_P must have non-zero minPeriod.");
+    }
     assert(repeatMin <= repeatMax);
     assert(repeatMax.is_reachable());
     assert(minPeriod || type != REPEAT_SPARSE_OPTIMAL_P);
index 10d93fb842288155187173e60388392339e0a9f8..3077ee9d561ff33177cae604af5dcf0c381be562 100644 (file)
@@ -2445,6 +2445,10 @@ static
 bool doLitHaigSom(NG &ng, NGHolder &g, som_type som) {
     ue2_literal lit;
     shared_ptr<NGHolder> rhs = make_shared<NGHolder>();
+    if (!rhs) {
+        assert(0);
+        throw std::bad_alloc();
+    }
     if (!ng.cc.grey.allowLitHaig) {
         return false;
     }
@@ -2509,6 +2513,11 @@ bool doHaigLitHaigSom(NG &ng, NGHolder &g,
     ue2_literal lit;
     shared_ptr<NGHolder> rhs = make_shared<NGHolder>();
     shared_ptr<NGHolder> lhs = make_shared<NGHolder>();
+    if (!rhs || !lhs) {
+        assert(0);
+        throw std::bad_alloc();
+    }
+
     if (!splitOffBestLiteral(g, regions, &lit, &*lhs, &*rhs, ng.cc)) {
         return false;
     }
index 4a5b492cc98340294b42a3c34e3edb7cac0d8852..3e6444607e452a514110d93ca7ae18a01d07057f 100644 (file)
@@ -1036,6 +1036,11 @@ bool splitRoseEdge(const NGHolder &base_graph, RoseInGraph &vg,
     shared_ptr<NGHolder> lhs = make_shared<NGHolder>();
     shared_ptr<NGHolder> rhs = make_shared<NGHolder>();
 
+    if (!lhs || !rhs) {
+        assert(0);
+        throw std::bad_alloc();
+    }
+
     unordered_map<NFAVertex, NFAVertex> lhs_map;
     unordered_map<NFAVertex, NFAVertex> rhs_map;
 
@@ -1229,6 +1234,10 @@ void splitEdgesByCut(NGHolder &h, RoseInGraph &vg,
             DEBUG_PRINTF("splitting on pivot %zu\n", h[pivot].index);
             unordered_map<NFAVertex, NFAVertex> temp_map;
             shared_ptr<NGHolder> new_lhs = make_shared<NGHolder>();
+            if (!new_lhs) {
+                assert(0);
+                throw std::bad_alloc();
+            }
             splitLHS(h, pivot, new_lhs.get(), &temp_map);
 
             /* want to cut off paths to pivot from things other than the pivot -
@@ -1310,6 +1319,10 @@ void splitEdgesByCut(NGHolder &h, RoseInGraph &vg,
             if (!contains(done_rhs, adj)) {
                 unordered_map<NFAVertex, NFAVertex> temp_map;
                 shared_ptr<NGHolder> new_rhs = make_shared<NGHolder>();
+                if (!new_rhs) {
+                    assert(0);
+                    throw std::bad_alloc();
+                }
                 splitRHS(h, adj, new_rhs.get(), &temp_map);
                 remove_edge(new_rhs->start, new_rhs->accept, *new_rhs);
                 remove_edge(new_rhs->start, new_rhs->acceptEod, *new_rhs);
@@ -2281,6 +2294,10 @@ void splitEdgesForSuffix(const NGHolder &base_graph, RoseInGraph &vg,
     assert(!splitters.empty());
 
     shared_ptr<NGHolder> lhs = make_shared<NGHolder>();
+    if (!lhs) {
+        assert(0);
+        throw bad_alloc();
+    }
     unordered_map<NFAVertex, NFAVertex> v_map;
     cloneHolder(*lhs, base_graph, &v_map);
     lhs->kind = NFA_INFIX;
index adf06bc404a6256d5b4ed0088a4b26e66493eaea..b75ca34fc05c2d8375711a96c3aa0002635ece59 100644 (file)
@@ -140,7 +140,8 @@ void ParsedLogical::validateSubIDs(const unsigned *ids,
         }
         hs_compile_error_t *compile_err = NULL;
         hs_expr_info_t *info = NULL;
-        hs_error_t err = hs_expression_info(expressions[i], flags[i], &info,
+        hs_error_t err = hs_expression_info(expressions[i],
+                                            flags ? flags[i] : 0, &info,
                                             &compile_err);
         if (err != HS_SUCCESS) {
             hs_free_compile_error(compile_err);
index b8d0a09bb3250caf59c80bbc5b00df0aed54c199..992311da2fec69278ad82863c07604396c5414da 100644 (file)
@@ -561,6 +561,10 @@ bool handleMixedPrefixCliche(const NGHolder &h, RoseGraph &g, RoseVertex v,
     DEBUG_PRINTF("woot?\n");
 
     shared_ptr<NGHolder> h_new = make_shared<NGHolder>();
+    if (!h_new) {
+        assert(0);
+        throw std::bad_alloc();
+    }
     unordered_map<NFAVertex, NFAVertex> rhs_map;
     vector<NFAVertex> exits_vec;
     insert(&exits_vec, exits_vec.end(), exits);
index 5dad47041dce9df59a41673b85375f39ad0acc79..e1d2f1f31473db305c2f12a79ca584442871ce20 100644 (file)
@@ -77,7 +77,7 @@ namespace ue2 {
 struct LitTrieVertexProps {
     LitTrieVertexProps() = default;
     explicit LitTrieVertexProps(u8 c_in) : c(c_in) {}
-    size_t index; // managed by ue2_graph
+    size_t index = 0; // managed by ue2_graph
     u8 c = 0; //!< character reached on this vertex
     flat_set<ReportID> reports; //!< managed reports fired on this vertex
 };
index 049964ab075f141df84bf334c2ed9090154fa718..507172847386454719e84eee63e8b52f90bbdb82 100644 (file)
@@ -70,8 +70,8 @@ class undirected_graph_edge_descriptor
     using base_vertex_type = typename base_graph_traits::vertex_descriptor;
 
     base_edge_type underlying_edge;
-    const base_graph_type *g;
-    bool reverse; // if true, reverse vertices in source() and target()
+    const base_graph_type *g = nullptr;
+    bool reverse = false; // if true, reverse vertices in source() and target()
 
     inline std::pair<base_vertex_type, base_vertex_type>
     canonical_edge() const {
index 0aa846896efcdc1b9c286c8875857c3972b4cf67..f436936d710b9a7301ba2784d43b2cfe60af3798 100644 (file)
@@ -133,7 +133,7 @@ public:
             : lit(&lit_in), idx(idx_in) {}
 
         const ue2_literal *lit = nullptr;
-        size_t idx;
+        size_t idx = 0;
     };
 
     using const_reverse_iterator = std::reverse_iterator<const_iterator>;
index 8e761ec34fc503aa2ea82d682935181672fb1121..b23da1fb3b3a6722d7986dff684ad2aee0484d45 100644 (file)
@@ -58,7 +58,10 @@ void readRow(sqlite3_stmt *statement, vector<DataBlock> &blocks,
     }
     auto internal_stream_index = stream_indices[stream_id];
 
-    assert(blob || bytes > 0);
+    if (!(blob &&  bytes > 0)) {
+        assert(0);
+        throw std::domain_error("Invalid blob or bytes from sqlite3.");
+    }
     blocks.emplace_back(id, stream_id, internal_stream_index,
                         string(blob, blob + bytes));
 }
index c5a6221b87685332134ae1ac68e4e0e700a7eec4..6d091d38940991688a707fcf622b97b18ba3ea3d 100644 (file)
@@ -740,6 +740,11 @@ u64a byte_size(const vector<DataBlock> &corpus_blocks) {
         total += block.payload.size();
     }
 
+    if (total == 0) {
+        assert(0);
+        throw std::invalid_argument("Empty corpus.");
+    }
+
     return total;
 }
 
index 831ab1484f5dd8e79ed79082150344d2a6c4af90..f6957d2968aa597e056b5aec052a6a3fa4c9bda7 100644 (file)
@@ -61,7 +61,7 @@ public:
         std::lock_guard<std::mutex> lock(mutex);
         if (failed) {
             // We have previously failed to compile this database.
-            return nullptr;
+            throw CompileFailed("Unable to compile db previously.");
         }
         if (db) {
             return db;
index 66ae270be8af91963afb3dcad5f4655db0f0e92b..4de320e172e0707b2f5bfb2206665c4e8be18227 100644 (file)
@@ -101,7 +101,7 @@ void NfaGeneratedCorpora::generate(unsigned id, vector<Corpus> &data) {
         pl.logicalKeyRenumber();
         const auto &m_lkey = pl.getLkeyMap();
         assert(!m_lkey.empty());
-        u32 a_subid; // arbitrary sub id
+        u32 a_subid = 0; // arbitrary sub id
         unordered_map<u32, vector<Corpus>> m_data;
         for (const auto &it : m_lkey) {
             a_subid = it.first;
index 5fff82398ce62f014fb972962ca29dfcf15a97ff..c63793d963dd4093b1c17c4245ca21b6bb1b6dc4 100644 (file)
@@ -98,6 +98,6 @@ void *Thread::runThread(void *thr) {
 }
 
 
-Thread::Thread(size_t num) : thread_id(num) {}
+Thread::Thread(size_t num) : thread_id(num), thread() {}
 
 Thread::~Thread() {}
index e784e05827a75059abea40aaf35805a7fbc7a9ad..511ad60ac9c618d68cc2cba93cbb080a99ee5d72 100644 (file)
@@ -42,7 +42,7 @@ CorpusProperties::CorpusProperties()
     : matchness(100), unmatchness(0), randomness(0), prefixRange(0, 0),
       suffixRange(0, 0), cycleMin(1), cycleMax(1),
       corpusLimit(DEFAULT_CORPUS_GENERATOR_LIMIT), editDistance(0),
-      alphabetSize(~0) {
+      alphabetSize(~0), rngSeed(0) {
     // empty
 }