Coverage Report

Created: 2026-02-26 06:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libbpf/elfutils/libelf/elf32_getchdr.c
Line
Count
Source
1
/* Return section compression header.
2
   Copyright (C) 2015 Red Hat, Inc.
3
   This file is part of elfutils.
4
5
   This file is free software; you can redistribute it and/or modify
6
   it under the terms of either
7
8
     * the GNU Lesser General Public License as published by the Free
9
       Software Foundation; either version 3 of the License, or (at
10
       your option) any later version
11
12
   or
13
14
     * the GNU General Public License as published by the Free
15
       Software Foundation; either version 2 of the License, or (at
16
       your option) any later version
17
18
   or both in parallel, as here.
19
20
   elfutils is distributed in the hope that it will be useful, but
21
   WITHOUT ANY WARRANTY; without even the implied warranty of
22
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23
   General Public License for more details.
24
25
   You should have received copies of the GNU General Public License and
26
   the GNU Lesser General Public License along with this program.  If
27
   not, see <http://www.gnu.org/licenses/>.  */
28
29
#ifdef HAVE_CONFIG_H
30
# include <config.h>
31
#endif
32
33
#include <libelf.h>
34
#include "libelfP.h"
35
#include "common.h"
36
37
#ifndef LIBELFBITS
38
# define LIBELFBITS 32
39
#endif
40
41
42
ElfW2(LIBELFBITS,Chdr) *
43
elfw2(LIBELFBITS,getchdr) (Elf_Scn *scn)
44
2.46k
{
45
2.46k
  ElfW2(LIBELFBITS,Shdr) *shdr = elfw2(LIBELFBITS,getshdr) (scn);
46
2.46k
  if (shdr == NULL)
47
0
    return NULL;
48
49
  /* Must have SHF_COMPRESSED flag set.  Allocated or no bits sections
50
     can never be compressed.  */
51
2.46k
  if ((shdr->sh_flags & SHF_ALLOC) != 0)
52
208
    {
53
208
      __libelf_seterrno (ELF_E_INVALID_SECTION_FLAGS);
54
208
      return NULL;
55
208
    }
56
57
2.26k
  if (shdr->sh_type == SHT_NULL
58
2.26k
      || shdr->sh_type == SHT_NOBITS)
59
0
    {
60
0
      __libelf_seterrno (ELF_E_INVALID_SECTION_TYPE);
61
0
      return NULL;
62
0
    }
63
64
2.26k
  if ((shdr->sh_flags & SHF_COMPRESSED) == 0)
65
0
    {
66
0
      __libelf_seterrno (ELF_E_NOT_COMPRESSED);
67
0
      return NULL;
68
0
    }
69
70
  /* This makes sure the data is in the correct format, so we don't
71
     need to swap fields. */
72
2.26k
  Elf_Data *d  = elf_getdata (scn, NULL);
73
2.26k
  if (d == NULL)
74
292
    return NULL;
75
76
1.96k
  if (d->d_size < sizeof (ElfW2(LIBELFBITS,Chdr)) || d->d_buf == NULL)
77
348
    {
78
348
      __libelf_seterrno (ELF_E_INVALID_DATA);
79
348
      return NULL;
80
348
    }
81
82
1.62k
  return (ElfW2(LIBELFBITS,Chdr) *) d->d_buf;
83
1.96k
}
Unexecuted instantiation: elf32_getchdr
elf64_getchdr
Line
Count
Source
44
2.46k
{
45
2.46k
  ElfW2(LIBELFBITS,Shdr) *shdr = elfw2(LIBELFBITS,getshdr) (scn);
46
2.46k
  if (shdr == NULL)
47
0
    return NULL;
48
49
  /* Must have SHF_COMPRESSED flag set.  Allocated or no bits sections
50
     can never be compressed.  */
51
2.46k
  if ((shdr->sh_flags & SHF_ALLOC) != 0)
52
208
    {
53
208
      __libelf_seterrno (ELF_E_INVALID_SECTION_FLAGS);
54
208
      return NULL;
55
208
    }
56
57
2.26k
  if (shdr->sh_type == SHT_NULL
58
2.26k
      || shdr->sh_type == SHT_NOBITS)
59
0
    {
60
0
      __libelf_seterrno (ELF_E_INVALID_SECTION_TYPE);
61
0
      return NULL;
62
0
    }
63
64
2.26k
  if ((shdr->sh_flags & SHF_COMPRESSED) == 0)
65
0
    {
66
0
      __libelf_seterrno (ELF_E_NOT_COMPRESSED);
67
0
      return NULL;
68
0
    }
69
70
  /* This makes sure the data is in the correct format, so we don't
71
     need to swap fields. */
72
2.26k
  Elf_Data *d  = elf_getdata (scn, NULL);
73
2.26k
  if (d == NULL)
74
292
    return NULL;
75
76
1.96k
  if (d->d_size < sizeof (ElfW2(LIBELFBITS,Chdr)) || d->d_buf == NULL)
77
348
    {
78
348
      __libelf_seterrno (ELF_E_INVALID_DATA);
79
348
      return NULL;
80
348
    }
81
82
1.62k
  return (ElfW2(LIBELFBITS,Chdr) *) d->d_buf;
83
1.96k
}