• 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

91.43
/src/fuzzer/pkcs1.cpp
1
/*
2
* (C) 2015,2016 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/eme_pkcs.h>
11

12
namespace {
13

14
std::vector<uint8_t> simple_pkcs1_unpad(const uint8_t in[], size_t len) {
48✔
15
   if(len < 10) {
48✔
16
      throw Botan::Decoding_Error("bad len");
9✔
17
   }
18

19
   if(in[0] != 0 || in[1] != 2) {
39✔
20
      throw Botan::Decoding_Error("bad header field");
16✔
21
   }
22

23
   for(size_t i = 2; i < len; ++i) {
1,128✔
24
      if(in[i] == 0) {
1,124✔
25
         if(i < 10) {  // at least 8 padding bytes required
19✔
26
            throw Botan::Decoding_Error("insufficient padding bytes");
5✔
27
         }
28
         return std::vector<uint8_t>(in + i + 1, in + len);
14✔
29
      }
30
   }
31

32
   throw Botan::Decoding_Error("delim not found");
4✔
33
}
34

35
}  // namespace
36

37
void fuzz(const uint8_t in[], size_t len) {
48✔
38
   static Botan::EME_PKCS1v15 pkcs1;
48✔
39

40
   Botan::secure_vector<uint8_t> lib_result;
48✔
41
   std::vector<uint8_t> ref_result;
48✔
42
   bool lib_rejected = false, ref_rejected = false;
48✔
43

44
   try {
48✔
45
      uint8_t valid_mask = 0;
48✔
46
      Botan::secure_vector<uint8_t> decoded = (static_cast<Botan::EME*>(&pkcs1))->unpad(valid_mask, in, len);
48✔
47

48
      if(valid_mask == 0) {
48✔
49
         lib_rejected = true;
50
      } else if(valid_mask == 0xFF) {
14✔
51
         lib_rejected = false;
52
      } else {
53
         FUZZER_WRITE_AND_CRASH("Invalid valid_mask from unpad");
48✔
54
      }
55
   } catch(Botan::Decoding_Error&) {
48✔
56
      lib_rejected = true;
×
57
   }
×
58

59
   try {
48✔
60
      ref_result = simple_pkcs1_unpad(in, len);
62✔
61
   } catch(Botan::Decoding_Error& e) {
34✔
62
      ref_rejected = true;
34✔
63
   }
34✔
64

65
   if(lib_rejected == true && ref_rejected == false) {
48✔
66
      FUZZER_WRITE_AND_CRASH("Library rejected input accepted by ref " << Botan::hex_encode(ref_result));
×
67
   } else if(ref_rejected == true && lib_rejected == false) {
48✔
68
      FUZZER_WRITE_AND_CRASH("Library accepted input rejected by ref " << Botan::hex_encode(lib_result));
48✔
69
   }
70
   // otherwise the two implementations agree
71
}
48✔
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