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

randombit / botan / 16399247596

19 Jul 2025 11:30PM UTC coverage: 90.635% (-0.07%) from 90.708%
16399247596

push

github

web-flow
Merge pull request #4998 from randombit/jack/fix-clang-tidy-readability-isolate-declaration

Enable and fix clang-tidy warning readability-isolate-declaration

99940 of 110266 relevant lines covered (90.64%)

12278552.1 hits per line

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

88.57
/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(std::span<const uint8_t> in) {
48✔
38
   static Botan::EME_PKCS1v15 pkcs1;
48✔
39

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

45
   try {
48✔
46
      lib_result.resize(in.size());
48✔
47
      auto written = (static_cast<Botan::EME*>(&pkcs1))->unpad(lib_result, in);
48✔
48
      lib_rejected = !written.has_value().as_bool();
48✔
49

50
      lib_result.resize(written.value_or(0));
48✔
51
   } catch(Botan::Decoding_Error&) {
×
52
      lib_rejected = true;
×
53
   }
×
54

55
   try {
48✔
56
      ref_result = simple_pkcs1_unpad(in.data(), in.size());
62✔
57
   } catch(Botan::Decoding_Error& e) {
34✔
58
      ref_rejected = true;
34✔
59
   }
34✔
60

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

© 2026 Coveralls, Inc