Coverage Report

Created: 2024-11-25 06:26

/src/gnutls/fuzz/mem.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2017 Nikos Mavrogiannopoulos
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a
5
 * copy of this software and associated documentation files (the "Software"),
6
 * to deal in the Software without restriction, including without limitation
7
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
 * and/or sell copies of the Software, and to permit persons to whom the
9
 * Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in
12
 * all copies or substantial portions of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
 * DEALINGS IN THE SOFTWARE.
21
 *
22
 */
23
24
#ifndef MEM_H
25
#define MEM_H
26
27
typedef struct mem_st {
28
  const uint8_t *data;
29
  size_t size;
30
} mem_st;
31
32
0
#define MIN(x, y) ((x) < (y) ? (x) : (y))
33
static ssize_t mem_push(gnutls_transport_ptr_t tr, const void *data, size_t len)
34
0
{
35
0
  return len;
36
0
}
37
38
static ssize_t mem_pull(gnutls_transport_ptr_t tr, void *data, size_t len)
39
0
{
40
0
  struct mem_st *p = (struct mem_st *)tr;
41
42
0
  if (p->size == 0) {
43
0
    return 0;
44
0
  }
45
46
0
  len = MIN(len, p->size);
47
0
  memcpy(data, p->data, len);
48
49
0
  p->size -= len;
50
0
  p->data += len;
51
52
0
  return len;
53
0
}
54
55
static int mem_pull_timeout(gnutls_transport_ptr_t tr, unsigned int ms)
56
0
{
57
0
  struct mem_st *p = (struct mem_st *)tr;
58
59
0
  if (p->size > 0)
60
0
    return 1; /* available data */
61
0
  else
62
0
    return 0; /* timeout */
63
0
}
64
65
#endif