Coverage Report

Created: 2024-02-25 07:20

/src/libewf/libewf/libewf_case_data_section.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Case data section functions
3
 *
4
 * Copyright (C) 2006-2023, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <common.h>
23
#include <memory.h>
24
#include <types.h>
25
26
#include "libewf_case_data.h"
27
#include "libewf_case_data_section.h"
28
#include "libewf_libbfio.h"
29
#include "libewf_libcerror.h"
30
#include "libewf_libfvalue.h"
31
#include "libewf_media_values.h"
32
#include "libewf_read_io_handle.h"
33
#include "libewf_section.h"
34
#include "libewf_section_descriptor.h"
35
36
/* Reads a case data section
37
 * Returns the number of bytes read or -1 on error
38
 */
39
ssize_t libewf_case_data_section_read_file_io_pool(
40
         libewf_section_descriptor_t *section_descriptor,
41
         libewf_io_handle_t *io_handle,
42
         libbfio_pool_t *file_io_pool,
43
         int file_io_pool_entry,
44
         libewf_read_io_handle_t *read_io_handle,
45
         libewf_media_values_t *media_values,
46
         libfvalue_table_t *header_values,
47
         libcerror_error_t **error )
48
0
{
49
0
  uint8_t *string_data    = NULL;
50
0
  static char *function   = "libewf_case_data_section_read_file_io_pool";
51
0
  size_t string_data_size = 0;
52
0
  ssize_t read_count      = 0;
53
54
0
  if( section_descriptor == NULL )
55
0
  {
56
0
    libcerror_error_set(
57
0
     error,
58
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
59
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
60
0
     "%s: invalid section descriptor.",
61
0
     function );
62
63
0
    return( -1 );
64
0
  }
65
0
  if( io_handle == NULL )
66
0
  {
67
0
    libcerror_error_set(
68
0
     error,
69
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
70
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
71
0
     "%s: invalid IO handle.",
72
0
     function );
73
74
0
    return( -1 );
75
0
  }
76
0
  if( read_io_handle == NULL )
77
0
  {
78
0
    libcerror_error_set(
79
0
     error,
80
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
81
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
82
0
     "%s: invalid read IO handle.",
83
0
     function );
84
85
0
    return( -1 );
86
0
  }
87
0
  read_count = libewf_section_compressed_string_read(
88
0
          section_descriptor,
89
0
          io_handle,
90
0
          file_io_pool,
91
0
          file_io_pool_entry,
92
0
          io_handle->compression_method,
93
0
          &string_data,
94
0
          &string_data_size,
95
0
          error );
96
97
0
  if( read_count == -1 )
98
0
  {
99
0
    libcerror_error_set(
100
0
     error,
101
0
     LIBCERROR_ERROR_DOMAIN_IO,
102
0
     LIBCERROR_IO_ERROR_READ_FAILED,
103
0
     "%s: unable to read case data file object string.",
104
0
     function );
105
106
0
    goto on_error;
107
0
  }
108
0
  else if( read_count != 0 )
109
0
  {
110
0
    if( read_io_handle->case_data == NULL )
111
0
    {
112
0
      if( libewf_case_data_parse(
113
0
           string_data,
114
0
           string_data_size,
115
0
           media_values,
116
0
           header_values,
117
0
           &( io_handle->format ),
118
0
           error ) != 1 )
119
0
      {
120
0
        libcerror_error_set(
121
0
         error,
122
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
123
0
         LIBCERROR_RUNTIME_ERROR_SET_FAILED,
124
0
         "%s: unable to parse case data.",
125
0
         function );
126
127
0
        goto on_error;
128
0
      }
129
0
      read_io_handle->case_data      = string_data;
130
0
      read_io_handle->case_data_size = string_data_size;
131
0
    }
132
0
    else
133
0
    {
134
0
      if( ( read_io_handle->case_data_size != string_data_size )
135
0
       || ( memory_compare(
136
0
             read_io_handle->case_data,
137
0
             string_data,
138
0
             string_data_size ) != 0 ) )
139
0
      {
140
0
        libcerror_error_set(
141
0
         error,
142
0
         LIBCERROR_ERROR_DOMAIN_INPUT,
143
0
         LIBCERROR_INPUT_ERROR_VALUE_MISMATCH,
144
0
         "%s: case data does not match.",
145
0
         function );
146
147
0
        goto on_error;
148
0
      }
149
0
      memory_free(
150
0
       string_data );
151
0
    }
152
0
  }
153
0
  return( read_count );
154
155
0
on_error:
156
0
  if( string_data != NULL )
157
0
  {
158
0
    memory_free(
159
0
     string_data );
160
0
  }
161
0
  return( -1 );
162
0
}
163