/src/libewf/libewf/libewf_restart_data.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Restart data 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_libcerror.h" |
27 | | #include "libewf_libcnotify.h" |
28 | | #include "libewf_libuna.h" |
29 | | #include "libewf_restart_data.h" |
30 | | |
31 | | /* Parses EWF version 2 restart data |
32 | | * Returns 1 if successful or -1 on error |
33 | | */ |
34 | | int libewf_restart_data_parse( |
35 | | const uint8_t *restart_data, |
36 | | size_t restart_data_size, |
37 | | libcerror_error_t **error ) |
38 | 0 | { |
39 | 0 | uint8_t *restart_data_string = NULL; |
40 | 0 | static char *function = "libewf_restart_data_parse"; |
41 | 0 | size_t restart_data_string_size = 0; |
42 | |
|
43 | 0 | if( restart_data == NULL ) |
44 | 0 | { |
45 | 0 | libcerror_error_set( |
46 | 0 | error, |
47 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
48 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
49 | 0 | "%s: invalid restart data.", |
50 | 0 | function ); |
51 | |
|
52 | 0 | return( -1 ); |
53 | 0 | } |
54 | 0 | if( libuna_utf8_string_size_from_utf16_stream( |
55 | 0 | restart_data, |
56 | 0 | restart_data_size, |
57 | 0 | 0, |
58 | 0 | &restart_data_string_size, |
59 | 0 | error ) != 1 ) |
60 | 0 | { |
61 | 0 | libcerror_error_set( |
62 | 0 | error, |
63 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
64 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
65 | 0 | "%s: unable to determine restart data string size.", |
66 | 0 | function ); |
67 | |
|
68 | 0 | goto on_error; |
69 | 0 | } |
70 | 0 | if( ( restart_data_string_size == 0 ) |
71 | 0 | || ( restart_data_string_size > MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
72 | 0 | { |
73 | 0 | libcerror_error_set( |
74 | 0 | error, |
75 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
76 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
77 | 0 | "%s: invalid restart data string size value out of bounds.", |
78 | 0 | function ); |
79 | |
|
80 | 0 | goto on_error; |
81 | 0 | } |
82 | 0 | restart_data_string = (uint8_t *) memory_allocate( |
83 | 0 | sizeof( uint8_t ) * restart_data_string_size ); |
84 | |
|
85 | 0 | if( restart_data_string == NULL ) |
86 | 0 | { |
87 | 0 | libcerror_error_set( |
88 | 0 | error, |
89 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
90 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
91 | 0 | "%s: unable to create restart data string.", |
92 | 0 | function ); |
93 | |
|
94 | 0 | goto on_error; |
95 | 0 | } |
96 | 0 | if( libuna_utf8_string_copy_from_utf16_stream( |
97 | 0 | restart_data_string, |
98 | 0 | restart_data_string_size, |
99 | 0 | restart_data, |
100 | 0 | restart_data_size, |
101 | 0 | 0, |
102 | 0 | error ) != 1 ) |
103 | 0 | { |
104 | 0 | libcerror_error_set( |
105 | 0 | error, |
106 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
107 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
108 | 0 | "%s: unable to set restart data string.", |
109 | 0 | function ); |
110 | |
|
111 | 0 | goto on_error; |
112 | 0 | } |
113 | | #if defined( HAVE_DEBUG_OUTPUT ) |
114 | | if( libcnotify_verbose != 0 ) |
115 | | { |
116 | | libcnotify_printf( |
117 | | "%s: restart data string:\n%s", |
118 | | function, |
119 | | restart_data_string ); |
120 | | } |
121 | | #endif |
122 | | /* TODO |
123 | | if( libewf_restart_data_parse_string( |
124 | | restart_data_string, |
125 | | restart_data_string_size, |
126 | | media_values, |
127 | | header_values, |
128 | | error ) != 1 ) |
129 | | { |
130 | | libcerror_error_set( |
131 | | error, |
132 | | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
133 | | LIBCERROR_CONVERSION_ERROR_GENERIC, |
134 | | "%s: unable to parse restart data string.", |
135 | | function ); |
136 | | |
137 | | goto on_error; |
138 | | } |
139 | | */ |
140 | 0 | memory_free( |
141 | 0 | restart_data_string ); |
142 | |
|
143 | 0 | return( 1 ); |
144 | | |
145 | 0 | on_error: |
146 | 0 | if( restart_data_string != NULL ) |
147 | 0 | { |
148 | 0 | memory_free( |
149 | 0 | restart_data_string ); |
150 | 0 | } |
151 | 0 | return( -1 ); |
152 | 0 | } |
153 | | |