LCOV - code coverage report
Current view: top level - libelf - elf32_getchdr.c (source / functions) Hit Total Coverage
Test: elfutils-0.187 Lines: 12 18 66.7 %
Date: 2022-04-26 02:07:47 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 14 64.3 %

           Branch data     Line data    Source code
       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                 :        931 : elfw2(LIBELFBITS,getchdr) (Elf_Scn *scn)
      44                 :            : {
      45                 :        931 :   ElfW2(LIBELFBITS,Shdr) *shdr = elfw2(LIBELFBITS,getshdr) (scn);
      46         [ +  + ]:        931 :   if (shdr == NULL)
      47                 :            :     return NULL;
      48                 :            : 
      49                 :            :   /* Must have SHF_COMPRESSED flag set.  Allocated or no bits sections
      50                 :            :      can never be compressed.  */
      51         [ -  + ]:        930 :   if ((shdr->sh_flags & SHF_ALLOC) != 0)
      52                 :            :     {
      53                 :          0 :       __libelf_seterrno (ELF_E_INVALID_SECTION_FLAGS);
      54                 :          0 :       return NULL;
      55                 :            :     }
      56                 :            : 
      57                 :        930 :   if (shdr->sh_type == SHT_NULL
      58         [ -  + ]:        930 :       || shdr->sh_type == SHT_NOBITS)
      59                 :            :     {
      60                 :          0 :       __libelf_seterrno (ELF_E_INVALID_SECTION_TYPE);
      61                 :          0 :       return NULL;
      62                 :            :     }
      63                 :            : 
      64         [ +  + ]:        930 :   if ((shdr->sh_flags & SHF_COMPRESSED) == 0)
      65                 :            :     {
      66                 :        114 :       __libelf_seterrno (ELF_E_NOT_COMPRESSED);
      67                 :        114 :       return NULL;
      68                 :            :     }
      69                 :            : 
      70                 :            :   /* This makes sure the data is in the correct format, so we don't
      71                 :            :      need to swap fields. */
      72                 :        816 :   Elf_Data *d  = elf_getdata (scn, NULL);
      73         [ +  - ]:        816 :   if (d == NULL)
      74                 :            :     return NULL;
      75                 :            : 
      76   [ +  -  -  + ]:        816 :   if (d->d_size < sizeof (ElfW2(LIBELFBITS,Chdr)) || d->d_buf == NULL)
      77                 :            :     {
      78                 :          0 :       __libelf_seterrno (ELF_E_INVALID_DATA);
      79                 :          0 :       return NULL;
      80                 :            :     }
      81                 :            : 
      82                 :            :   return (ElfW2(LIBELFBITS,Chdr) *) d->d_buf;
      83                 :            : }

Generated by: LCOV version 1.14