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

randombit / botan / 5134090420

31 May 2023 03:12PM UTC coverage: 91.721% (-0.3%) from 91.995%
5134090420

push

github

randombit
Merge GH #3565 Disable noisy/pointless pylint warnings

76048 of 82912 relevant lines covered (91.72%)

11755290.1 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
   if(in[0] != 0 || in[1] != 2)
39✔
19
      throw Botan::Decoding_Error("bad header field");
16✔
20

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

29
   throw Botan::Decoding_Error("delim not found");
4✔
30
}
31

32
}  // namespace
33

34
void fuzz(const uint8_t in[], size_t len) {
48✔
35
   static Botan::EME_PKCS1v15 pkcs1;
48✔
36

37
   Botan::secure_vector<uint8_t> lib_result;
48✔
38
   std::vector<uint8_t> ref_result;
48✔
39
   bool lib_rejected = false, ref_rejected = false;
48✔
40

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

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

55
   try {
48✔
56
      ref_result = simple_pkcs1_unpad(in, len);
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
}
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