• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5356685938

23 Jun 2023 01:39PM UTC coverage: 91.746% (+0.02%) from 91.728%
5356685938

push

github

randombit
Merge GH #3595 Apply clang-tidy more universally

Previously clang-tidy ruleset disabled certain rules for the cli and
tests. Remove these exceptions, and fix the relevant warnings.

Also fix compile_commands.json which had previously not provided information for
the examples, BoGo shim, or fuzzers. As a result, clang-tidy was effectively
blind to them. Fix various clang-tidy findings in these files.

Additionally fix clang-tidy warnings that were in Boost or Sqlite3 specific
code, which had been accidentally omitted in past checks.

Modify the nightly clang-tidy run to additionally check the examples, fuzzers,
shim, and Sqlite3/Boost specific code.

78183 of 85217 relevant lines covered (91.75%)

12364366.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/fuzzer/oaep.cpp
1
/*
2
* (C) 2018 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "fuzzers.h"
8

9
#include <botan/hex.h>
10
#include <botan/internal/oaep.h>
11

12
namespace {
13

14
Botan::secure_vector<uint8_t> ref_oaep_unpad(uint8_t& valid_mask,
1,000✔
15
                                             const uint8_t in[],
16
                                             size_t len,
17
                                             const Botan::secure_vector<uint8_t>& Phash) {
18
   const size_t hlen = Phash.size();
1,000✔
19

20
   if(len < 2 * hlen + 1) {
1,000✔
21
      return Botan::secure_vector<uint8_t>();
9✔
22
   }
23

24
   for(size_t i = hlen; i != 2 * hlen; ++i) {
994✔
25
      if(in[i] != Phash[i - hlen]) {
994✔
26
         return Botan::secure_vector<uint8_t>();
991✔
27
      }
28
   }
29

30
   for(size_t i = 2 * hlen; i != len; ++i) {
×
31
      if(in[i] != 0x00 && in[i] != 0x01) {
×
32
         return Botan::secure_vector<uint8_t>();
×
33
      }
34

35
      if(in[i] == 0x01) {
×
36
         valid_mask = 0xFF;
×
37
         return Botan::secure_vector<uint8_t>(in + i + 1, in + len);
×
38
      }
39
   }
40

41
   return Botan::secure_vector<uint8_t>();
×
42
}
43

44
inline bool all_zeros(const Botan::secure_vector<uint8_t>& v) {
45
   for(size_t i = 0; i != v.size(); ++i) {
2,000✔
46
      if(v[i] != 0) {
×
47
         return false;
48
      }
49
   }
50
   return true;
51
}
52

53
}  // namespace
54

55
void fuzz(const uint8_t in[], size_t len) {
1,000✔
56
   static const Botan::secure_vector<uint8_t> Phash = {1, 2, 3, 4};
1,000✔
57

58
   uint8_t lib_valid_mask = 0;
1,000✔
59
   const Botan::secure_vector<uint8_t> lib_output = Botan::oaep_find_delim(lib_valid_mask, in, len, Phash);
1,000✔
60
   FUZZER_ASSERT_TRUE(lib_valid_mask == 0 || lib_valid_mask == 0xFF);
1,000✔
61

62
   uint8_t ref_valid_mask = 0;
1,000✔
63
   const Botan::secure_vector<uint8_t> ref_output = ref_oaep_unpad(ref_valid_mask, in, len, Phash);
1,000✔
64
   FUZZER_ASSERT_TRUE(ref_valid_mask == 0 || ref_valid_mask == 0xFF);
1,000✔
65

66
   if(ref_valid_mask == 0xFF && lib_valid_mask == 0x00) {
1,000✔
67
      FUZZER_WRITE_AND_CRASH("Ref accepted but library rejected, output " << Botan::hex_encode(ref_output) << "\n");
×
68
   } else if(ref_valid_mask == 0x00 && lib_valid_mask == 0xFF) {
1,000✔
69
      FUZZER_WRITE_AND_CRASH("Lib accepted but ref rejected, output = " << Botan::hex_encode(lib_output) << "\n");
×
70
   }
71

72
   if(ref_valid_mask == 0x00) {
1,000✔
73
      FUZZER_ASSERT_TRUE(all_zeros(ref_output));
1,000✔
74
   }
75

76
   if(lib_valid_mask == 0x00) {
1,000✔
77
      FUZZER_ASSERT_TRUE(all_zeros(lib_output));
1,000✔
78
   }
79

80
   if(ref_valid_mask && lib_valid_mask) {
1,000✔
81
      if(ref_output != lib_output) {
×
82
         FUZZER_WRITE_AND_CRASH("Ref and lib both accepted but produced different output:"
×
83
                                << " ref = " << Botan::hex_encode(ref_output)
84
                                << " lib = " << Botan::hex_encode(lib_output));
85
      }
86
   }
87
}
1,991✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc