Coverage Report

Created: 2026-04-02 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/boringssl/fuzz/session.cc
Line
Count
Source
1
// Copyright 2016 The BoringSSL Authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include <stdio.h>
16
17
#include <openssl/mem.h>
18
#include <openssl/ssl.h>
19
20
struct GlobalState {
21
2
  GlobalState() : ctx(SSL_CTX_new(TLS_method())) {}
22
23
  bssl::UniquePtr<SSL_CTX> ctx;
24
};
25
26
static GlobalState g_state;
27
28
4.50k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
29
  // Parse in our session.
30
4.50k
  bssl::UniquePtr<SSL_SESSION> session(
31
4.50k
      SSL_SESSION_from_bytes(buf, len, g_state.ctx.get()));
32
33
  // If the format was invalid, just return.
34
4.50k
  if (!session) {
35
4.01k
    return 0;
36
4.01k
  }
37
38
  // Stress the encoder.
39
494
  size_t encoded_len;
40
494
  uint8_t *encoded;
41
494
  if (!SSL_SESSION_to_bytes(session.get(), &encoded, &encoded_len)) {
42
0
    fprintf(stderr, "SSL_SESSION_to_bytes failed.\n");
43
0
    return 1;
44
0
  }
45
46
494
  OPENSSL_free(encoded);
47
494
  return 0;
48
494
}