Coverage Report

Created: 2026-01-13 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libesedb/libesedb/libesedb_space_tree_value.c
Line
Count
Source
1
/*
2
 * Space tree value functions
3
 *
4
 * Copyright (C) 2009-2025, 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 <byte_stream.h>
24
#include <memory.h>
25
#include <types.h>
26
27
#include "libesedb_libcerror.h"
28
#include "libesedb_libcnotify.h"
29
#include "libesedb_space_tree_value.h"
30
31
/* Creates a space tree value
32
 * Make sure the value space_tree_value is referencing, is set to NULL
33
 * Returns 1 if successful or -1 on error
34
 */
35
int libesedb_space_tree_value_initialize(
36
     libesedb_space_tree_value_t **space_tree_value,
37
     libcerror_error_t **error )
38
0
{
39
0
  static char *function = "libesedb_space_tree_value_initialize";
40
41
0
  if( space_tree_value == NULL )
42
0
  {
43
0
    libcerror_error_set(
44
0
     error,
45
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
46
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
47
0
     "%s: invalid space tree value.",
48
0
     function );
49
50
0
    return( -1 );
51
0
  }
52
0
  if( *space_tree_value != NULL )
53
0
  {
54
0
    libcerror_error_set(
55
0
     error,
56
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
57
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
58
0
     "%s: invalid space tree value value already set.",
59
0
     function );
60
61
0
    return( -1 );
62
0
  }
63
0
  *space_tree_value = memory_allocate_structure(
64
0
                       libesedb_space_tree_value_t );
65
66
0
  if( *space_tree_value == NULL )
67
0
  {
68
0
    libcerror_error_set(
69
0
     error,
70
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
71
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
72
0
     "%s: unable to create space tree value.",
73
0
     function );
74
75
0
    goto on_error;
76
0
  }
77
0
  if( memory_set(
78
0
       *space_tree_value,
79
0
       0,
80
0
       sizeof( libesedb_space_tree_value_t ) ) == NULL )
81
0
  {
82
0
    libcerror_error_set(
83
0
     error,
84
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
85
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
86
0
     "%s: unable to clear space tree value.",
87
0
     function );
88
89
0
    goto on_error;
90
0
  }
91
0
  return( 1 );
92
93
0
on_error:
94
0
  if( *space_tree_value != NULL )
95
0
  {
96
0
    memory_free(
97
0
     *space_tree_value );
98
99
0
    *space_tree_value = NULL;
100
0
  }
101
0
  return( -1 );
102
0
}
103
104
/* Frees a space tree value
105
 * Returns 1 if successful or -1 on error
106
 */
107
int libesedb_space_tree_value_free(
108
     libesedb_space_tree_value_t **space_tree_value,
109
     libcerror_error_t **error )
110
0
{
111
0
  static char *function = "libesedb_space_tree_value_free";
112
113
0
  if( space_tree_value == NULL )
114
0
  {
115
0
    libcerror_error_set(
116
0
     error,
117
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
118
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
119
0
     "%s: invalid space tree value.",
120
0
     function );
121
122
0
    return( -1 );
123
0
  }
124
0
  if( *space_tree_value != NULL )
125
0
  {
126
0
    memory_free(
127
0
     *space_tree_value );
128
129
0
    *space_tree_value = NULL;
130
0
  }
131
0
  return( 1 );
132
0
}
133
134
/* Reads a space tree value
135
 * Returns 1 if successful or -1 on error
136
 */
137
int libesedb_space_tree_value_read_data(
138
     libesedb_space_tree_value_t *space_tree_value,
139
     const uint8_t *data,
140
     size_t data_size,
141
     libcerror_error_t **error )
142
0
{
143
0
  static char *function = "libesedb_space_tree_value_read_data";
144
145
0
  if( space_tree_value == NULL )
146
0
  {
147
0
    libcerror_error_set(
148
0
     error,
149
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
150
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
151
0
     "%s: invalid space tree value.",
152
0
     function );
153
154
0
    return( -1 );
155
0
  }
156
0
  if( data == NULL )
157
0
  {
158
0
    libcerror_error_set(
159
0
     error,
160
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
161
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
162
0
     "%s: invalid data.",
163
0
     function );
164
165
0
    return( -1 );
166
0
  }
167
0
  if( ( data_size < 4 )
168
0
   || ( data_size > (size_t) SSIZE_MAX ) )
169
0
  {
170
0
    libcerror_error_set(
171
0
     error,
172
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
173
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
174
0
     "%s: invalid data size value out of bounds.",
175
0
     function );
176
177
0
    return( -1 );
178
0
  }
179
#if defined( HAVE_DEBUG_OUTPUT )
180
  if( libcnotify_verbose != 0 )
181
  {
182
    libcnotify_printf(
183
     "%s: space tree value:\n",
184
     function );
185
    libcnotify_print_data(
186
     data,
187
     data_size,
188
     LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
189
  }
190
#endif
191
0
  byte_stream_copy_to_uint32_little_endian(
192
0
   data,
193
0
   space_tree_value->number_of_pages );
194
195
#if defined( HAVE_DEBUG_OUTPUT )
196
  if( libcnotify_verbose != 0 )
197
  {
198
    libcnotify_printf(
199
     "%s: number of pages\t\t\t: %" PRIu32 "\n",
200
     function,
201
     space_tree_value->number_of_pages );
202
203
    libcnotify_printf(
204
     "\n" );
205
  }
206
#endif
207
0
  return( 1 );
208
0
}
209