/src/libfsntfs/libfsntfs/libfsntfs_volume_name_values.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Volume name attribute ($VOLUME_NAME) values functions |
3 | | * |
4 | | * Copyright (C) 2010-2024, 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 <narrow_string.h> |
25 | | #include <system_string.h> |
26 | | #include <types.h> |
27 | | #include <wide_string.h> |
28 | | |
29 | | #include "libfsntfs_debug.h" |
30 | | #include "libfsntfs_definitions.h" |
31 | | #include "libfsntfs_libcerror.h" |
32 | | #include "libfsntfs_libcnotify.h" |
33 | | #include "libfsntfs_libuna.h" |
34 | | #include "libfsntfs_mft_attribute.h" |
35 | | #include "libfsntfs_volume_name_values.h" |
36 | | |
37 | | /* Creates volume name values |
38 | | * Make sure the value volume_name_values is referencing, is set to NULL |
39 | | * Returns 1 if successful or -1 on error |
40 | | */ |
41 | | int libfsntfs_volume_name_values_initialize( |
42 | | libfsntfs_volume_name_values_t **volume_name_values, |
43 | | libcerror_error_t **error ) |
44 | 0 | { |
45 | 0 | static char *function = "libfsntfs_volume_name_values_initialize"; |
46 | |
|
47 | 0 | if( volume_name_values == NULL ) |
48 | 0 | { |
49 | 0 | libcerror_error_set( |
50 | 0 | error, |
51 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
52 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
53 | 0 | "%s: invalid volume name values.", |
54 | 0 | function ); |
55 | |
|
56 | 0 | return( -1 ); |
57 | 0 | } |
58 | 0 | if( *volume_name_values != NULL ) |
59 | 0 | { |
60 | 0 | libcerror_error_set( |
61 | 0 | error, |
62 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
63 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
64 | 0 | "%s: invalid volume name values value already set.", |
65 | 0 | function ); |
66 | |
|
67 | 0 | return( -1 ); |
68 | 0 | } |
69 | 0 | *volume_name_values = memory_allocate_structure( |
70 | 0 | libfsntfs_volume_name_values_t ); |
71 | |
|
72 | 0 | if( *volume_name_values == NULL ) |
73 | 0 | { |
74 | 0 | libcerror_error_set( |
75 | 0 | error, |
76 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
77 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
78 | 0 | "%s: unable to create volume name values.", |
79 | 0 | function ); |
80 | |
|
81 | 0 | goto on_error; |
82 | 0 | } |
83 | 0 | if( memory_set( |
84 | 0 | *volume_name_values, |
85 | 0 | 0, |
86 | 0 | sizeof( libfsntfs_volume_name_values_t ) ) == NULL ) |
87 | 0 | { |
88 | 0 | libcerror_error_set( |
89 | 0 | error, |
90 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
91 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
92 | 0 | "%s: unable to clear volume name values.", |
93 | 0 | function ); |
94 | |
|
95 | 0 | goto on_error; |
96 | 0 | } |
97 | 0 | return( 1 ); |
98 | | |
99 | 0 | on_error: |
100 | 0 | if( *volume_name_values != NULL ) |
101 | 0 | { |
102 | 0 | memory_free( |
103 | 0 | *volume_name_values ); |
104 | |
|
105 | 0 | *volume_name_values = NULL; |
106 | 0 | } |
107 | 0 | return( -1 ); |
108 | 0 | } |
109 | | |
110 | | /* Frees volume name values |
111 | | * Returns 1 if successful or -1 on error |
112 | | */ |
113 | | int libfsntfs_volume_name_values_free( |
114 | | libfsntfs_volume_name_values_t **volume_name_values, |
115 | | libcerror_error_t **error ) |
116 | 0 | { |
117 | 0 | static char *function = "libfsntfs_volume_name_values_free"; |
118 | |
|
119 | 0 | if( volume_name_values == NULL ) |
120 | 0 | { |
121 | 0 | libcerror_error_set( |
122 | 0 | error, |
123 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
124 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
125 | 0 | "%s: invalid volume name values.", |
126 | 0 | function ); |
127 | |
|
128 | 0 | return( -1 ); |
129 | 0 | } |
130 | 0 | if( *volume_name_values != NULL ) |
131 | 0 | { |
132 | 0 | if( ( *volume_name_values )->name != NULL ) |
133 | 0 | { |
134 | 0 | memory_free( |
135 | 0 | ( *volume_name_values )->name ); |
136 | 0 | } |
137 | 0 | memory_free( |
138 | 0 | *volume_name_values ); |
139 | |
|
140 | 0 | *volume_name_values = NULL; |
141 | 0 | } |
142 | 0 | return( 1 ); |
143 | 0 | } |
144 | | |
145 | | /* Reads the volume name values |
146 | | * Returns 1 if successful or -1 on error |
147 | | */ |
148 | | int libfsntfs_volume_name_values_read_data( |
149 | | libfsntfs_volume_name_values_t *volume_name_values, |
150 | | const uint8_t *data, |
151 | | size_t data_size, |
152 | | libcerror_error_t **error ) |
153 | 0 | { |
154 | 0 | static char *function = "libfsntfs_volume_name_values_read_data"; |
155 | |
|
156 | 0 | if( volume_name_values == 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 volume name values.", |
163 | 0 | function ); |
164 | |
|
165 | 0 | return( -1 ); |
166 | 0 | } |
167 | 0 | if( volume_name_values->name != NULL ) |
168 | 0 | { |
169 | 0 | libcerror_error_set( |
170 | 0 | error, |
171 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
172 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
173 | 0 | "%s: invalid volume name values - name already set.", |
174 | 0 | function ); |
175 | |
|
176 | 0 | return( -1 ); |
177 | 0 | } |
178 | | /* The volume name attribute can contain an empty volume name |
179 | | */ |
180 | 0 | if( data_size > 0 ) |
181 | 0 | { |
182 | 0 | if( data == NULL ) |
183 | 0 | { |
184 | 0 | libcerror_error_set( |
185 | 0 | error, |
186 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
187 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
188 | 0 | "%s: invalid data.", |
189 | 0 | function ); |
190 | |
|
191 | 0 | goto on_error; |
192 | 0 | } |
193 | 0 | } |
194 | 0 | if( data_size > (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) |
195 | 0 | { |
196 | 0 | libcerror_error_set( |
197 | 0 | error, |
198 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
199 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
200 | 0 | "%s: invalid data size value out of bounds.", |
201 | 0 | function ); |
202 | |
|
203 | 0 | goto on_error; |
204 | 0 | } |
205 | | #if defined( HAVE_DEBUG_OUTPUT ) |
206 | | if( libcnotify_verbose != 0 ) |
207 | | { |
208 | | libcnotify_printf( |
209 | | "%s: volume name data:\n", |
210 | | function ); |
211 | | libcnotify_print_data( |
212 | | data, |
213 | | data_size, |
214 | | 0 ); |
215 | | } |
216 | | #endif |
217 | | /* The size of the data can be 0 if the name is not set. |
218 | | */ |
219 | 0 | if( data_size > 0 ) |
220 | 0 | { |
221 | 0 | volume_name_values->name = (uint8_t *) memory_allocate( |
222 | 0 | sizeof( uint8_t ) * data_size ); |
223 | |
|
224 | 0 | if( volume_name_values->name == NULL ) |
225 | 0 | { |
226 | 0 | libcerror_error_set( |
227 | 0 | error, |
228 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
229 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
230 | 0 | "%s: unable to create name.", |
231 | 0 | function ); |
232 | |
|
233 | 0 | goto on_error; |
234 | 0 | } |
235 | 0 | volume_name_values->name_size = data_size; |
236 | |
|
237 | 0 | if( memory_copy( |
238 | 0 | volume_name_values->name, |
239 | 0 | data, |
240 | 0 | volume_name_values->name_size ) == NULL ) |
241 | 0 | { |
242 | 0 | libcerror_error_set( |
243 | 0 | error, |
244 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
245 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
246 | 0 | "%s: unable to copy volume name.", |
247 | 0 | function ); |
248 | |
|
249 | 0 | goto on_error; |
250 | 0 | } |
251 | | #if defined( HAVE_DEBUG_OUTPUT ) |
252 | | if( libcnotify_verbose != 0 ) |
253 | | { |
254 | | if( libfsntfs_debug_print_utf16_string_value( |
255 | | function, |
256 | | "name\t\t\t\t", |
257 | | volume_name_values->name, |
258 | | volume_name_values->name_size, |
259 | | LIBUNA_ENDIAN_LITTLE, |
260 | | error ) != 1 ) |
261 | | { |
262 | | libcerror_error_set( |
263 | | error, |
264 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
265 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
266 | | "%s: unable to print UTF-16 string value.", |
267 | | function ); |
268 | | |
269 | | goto on_error; |
270 | | } |
271 | | libcnotify_printf( |
272 | | "\n" ); |
273 | | } |
274 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
275 | 0 | } |
276 | 0 | return( 1 ); |
277 | | |
278 | 0 | on_error: |
279 | 0 | if( volume_name_values->name != NULL ) |
280 | 0 | { |
281 | 0 | memory_free( |
282 | 0 | volume_name_values->name ); |
283 | |
|
284 | 0 | volume_name_values->name = NULL; |
285 | 0 | } |
286 | 0 | volume_name_values->name_size = 0; |
287 | |
|
288 | 0 | return( -1 ); |
289 | 0 | } |
290 | | |
291 | | /* Reads the volume name values from an MFT attribute |
292 | | * Returns 1 if successful or -1 on error |
293 | | */ |
294 | | int libfsntfs_volume_name_values_read_from_mft_attribute( |
295 | | libfsntfs_volume_name_values_t *volume_name_values, |
296 | | libfsntfs_mft_attribute_t *mft_attribute, |
297 | | libcerror_error_t **error ) |
298 | 0 | { |
299 | 0 | uint8_t *data = NULL; |
300 | 0 | static char *function = "libfsntfs_volume_name_values_read_from_mft_attribute"; |
301 | 0 | size_t data_size = 0; |
302 | 0 | uint32_t attribute_type = 0; |
303 | 0 | int result = 0; |
304 | |
|
305 | 0 | if( volume_name_values == NULL ) |
306 | 0 | { |
307 | 0 | libcerror_error_set( |
308 | 0 | error, |
309 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
310 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
311 | 0 | "%s: invalid volume name values.", |
312 | 0 | function ); |
313 | |
|
314 | 0 | return( -1 ); |
315 | 0 | } |
316 | 0 | if( libfsntfs_mft_attribute_get_type( |
317 | 0 | mft_attribute, |
318 | 0 | &attribute_type, |
319 | 0 | error ) != 1 ) |
320 | 0 | { |
321 | 0 | libcerror_error_set( |
322 | 0 | error, |
323 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
324 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
325 | 0 | "%s: unable to retrieve type from attribute.", |
326 | 0 | function ); |
327 | |
|
328 | 0 | return( -1 ); |
329 | 0 | } |
330 | 0 | if( attribute_type != LIBFSNTFS_ATTRIBUTE_TYPE_VOLUME_NAME ) |
331 | 0 | { |
332 | 0 | libcerror_error_set( |
333 | 0 | error, |
334 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
335 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
336 | 0 | "%s: unsupported attribute type.", |
337 | 0 | function ); |
338 | |
|
339 | 0 | return( -1 ); |
340 | 0 | } |
341 | 0 | result = libfsntfs_mft_attribute_data_is_resident( |
342 | 0 | mft_attribute, |
343 | 0 | error ); |
344 | |
|
345 | 0 | if( result == -1 ) |
346 | 0 | { |
347 | 0 | libcerror_error_set( |
348 | 0 | error, |
349 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
350 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
351 | 0 | "%s: unable to determine if attribute data is resident.", |
352 | 0 | function ); |
353 | |
|
354 | 0 | return( -1 ); |
355 | 0 | } |
356 | 0 | else if( result == 0 ) |
357 | 0 | { |
358 | 0 | libcerror_error_set( |
359 | 0 | error, |
360 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
361 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
362 | 0 | "%s: unsupported non-resident attribute.", |
363 | 0 | function ); |
364 | |
|
365 | 0 | return( 1 ); |
366 | 0 | } |
367 | 0 | if( libfsntfs_mft_attribute_get_resident_data( |
368 | 0 | mft_attribute, |
369 | 0 | &data, |
370 | 0 | &data_size, |
371 | 0 | error ) != 1 ) |
372 | 0 | { |
373 | 0 | libcerror_error_set( |
374 | 0 | error, |
375 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
376 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
377 | 0 | "%s: unable to retrieve resident data from attribute.", |
378 | 0 | function ); |
379 | |
|
380 | 0 | return( -1 ); |
381 | 0 | } |
382 | 0 | if( libfsntfs_volume_name_values_read_data( |
383 | 0 | volume_name_values, |
384 | 0 | data, |
385 | 0 | data_size, |
386 | 0 | error ) != 1 ) |
387 | 0 | { |
388 | 0 | libcerror_error_set( |
389 | 0 | error, |
390 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
391 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
392 | 0 | "%s: unable to read volume name values.", |
393 | 0 | function ); |
394 | |
|
395 | 0 | return( -1 ); |
396 | 0 | } |
397 | 0 | return( 1 ); |
398 | 0 | } |
399 | | |
400 | | /* Retrieves the size of the UTF-8 encoded name |
401 | | * The returned size includes the end of string character |
402 | | * Returns 1 if successful or -1 on error |
403 | | */ |
404 | | int libfsntfs_volume_name_values_get_utf8_name_size( |
405 | | libfsntfs_volume_name_values_t *volume_name_values, |
406 | | size_t *utf8_string_size, |
407 | | libcerror_error_t **error ) |
408 | 0 | { |
409 | 0 | static char *function = "libfsntfs_volume_name_values_get_utf8_name_size"; |
410 | |
|
411 | 0 | if( volume_name_values == NULL ) |
412 | 0 | { |
413 | 0 | libcerror_error_set( |
414 | 0 | error, |
415 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
416 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
417 | 0 | "%s: invalid volume name values.", |
418 | 0 | function ); |
419 | |
|
420 | 0 | return( -1 ); |
421 | 0 | } |
422 | 0 | if( volume_name_values->name_size == 0 ) |
423 | 0 | { |
424 | 0 | if( utf8_string_size == NULL ) |
425 | 0 | { |
426 | 0 | libcerror_error_set( |
427 | 0 | error, |
428 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
429 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
430 | 0 | "%s: invalid UTF-8 string size.", |
431 | 0 | function ); |
432 | |
|
433 | 0 | return( -1 ); |
434 | 0 | } |
435 | 0 | *utf8_string_size = 0; |
436 | 0 | } |
437 | 0 | else |
438 | 0 | { |
439 | 0 | if( libuna_utf8_string_size_from_utf16_stream( |
440 | 0 | volume_name_values->name, |
441 | 0 | (size_t) volume_name_values->name_size, |
442 | 0 | LIBUNA_ENDIAN_LITTLE, |
443 | 0 | utf8_string_size, |
444 | 0 | error ) != 1 ) |
445 | 0 | { |
446 | 0 | libcerror_error_set( |
447 | 0 | error, |
448 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
449 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
450 | 0 | "%s: unable to retrieve UTF-8 string size.", |
451 | 0 | function ); |
452 | |
|
453 | 0 | return( -1 ); |
454 | 0 | } |
455 | 0 | } |
456 | 0 | return( 1 ); |
457 | 0 | } |
458 | | |
459 | | /* Retrieves the UTF-8 encoded name |
460 | | * The size should include the end of string character |
461 | | * Returns 1 if successful or -1 on error |
462 | | */ |
463 | | int libfsntfs_volume_name_values_get_utf8_name( |
464 | | libfsntfs_volume_name_values_t *volume_name_values, |
465 | | uint8_t *utf8_string, |
466 | | size_t utf8_string_size, |
467 | | libcerror_error_t **error ) |
468 | 0 | { |
469 | 0 | static char *function = "libfsntfs_volume_name_values_get_utf8_name"; |
470 | |
|
471 | 0 | if( volume_name_values == NULL ) |
472 | 0 | { |
473 | 0 | libcerror_error_set( |
474 | 0 | error, |
475 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
476 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
477 | 0 | "%s: invalid volume name values.", |
478 | 0 | function ); |
479 | |
|
480 | 0 | return( -1 ); |
481 | 0 | } |
482 | 0 | if( volume_name_values->name_size == 0 ) |
483 | 0 | { |
484 | 0 | if( utf8_string == NULL ) |
485 | 0 | { |
486 | 0 | libcerror_error_set( |
487 | 0 | error, |
488 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
489 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
490 | 0 | "%s: invalid UTF-8 string.", |
491 | 0 | function ); |
492 | |
|
493 | 0 | return( -1 ); |
494 | 0 | } |
495 | 0 | if( utf8_string_size > (size_t) SSIZE_MAX ) |
496 | 0 | { |
497 | 0 | libcerror_error_set( |
498 | 0 | error, |
499 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
500 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
501 | 0 | "%s: invalid UTF-8 string size value exceeds maximum.", |
502 | 0 | function ); |
503 | |
|
504 | 0 | return( -1 ); |
505 | 0 | } |
506 | 0 | if( utf8_string_size < 1 ) |
507 | 0 | { |
508 | 0 | libcerror_error_set( |
509 | 0 | error, |
510 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
511 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
512 | 0 | "%s: UTF-8 string size value too small.", |
513 | 0 | function ); |
514 | |
|
515 | 0 | return( -1 ); |
516 | 0 | } |
517 | 0 | utf8_string[ 0 ] = 0; |
518 | 0 | } |
519 | 0 | else |
520 | 0 | { |
521 | 0 | if( libuna_utf8_string_copy_from_utf16_stream( |
522 | 0 | utf8_string, |
523 | 0 | utf8_string_size, |
524 | 0 | volume_name_values->name, |
525 | 0 | (size_t) volume_name_values->name_size, |
526 | 0 | LIBUNA_ENDIAN_LITTLE, |
527 | 0 | error ) != 1 ) |
528 | 0 | { |
529 | 0 | libcerror_error_set( |
530 | 0 | error, |
531 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
532 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
533 | 0 | "%s: unable to retrieve UTF-8 string.", |
534 | 0 | function ); |
535 | |
|
536 | 0 | return( -1 ); |
537 | 0 | } |
538 | 0 | } |
539 | 0 | return( 1 ); |
540 | 0 | } |
541 | | |
542 | | /* Retrieves the size of the UTF-16 encoded name |
543 | | * The returned size includes the end of string character |
544 | | * Returns 1 if successful or -1 on error |
545 | | */ |
546 | | int libfsntfs_volume_name_values_get_utf16_name_size( |
547 | | libfsntfs_volume_name_values_t *volume_name_values, |
548 | | size_t *utf16_string_size, |
549 | | libcerror_error_t **error ) |
550 | 0 | { |
551 | 0 | static char *function = "libfsntfs_volume_name_values_get_utf16_name_size"; |
552 | |
|
553 | 0 | if( volume_name_values == NULL ) |
554 | 0 | { |
555 | 0 | libcerror_error_set( |
556 | 0 | error, |
557 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
558 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
559 | 0 | "%s: invalid volume name values.", |
560 | 0 | function ); |
561 | |
|
562 | 0 | return( -1 ); |
563 | 0 | } |
564 | 0 | if( volume_name_values->name_size == 0 ) |
565 | 0 | { |
566 | 0 | if( utf16_string_size == NULL ) |
567 | 0 | { |
568 | 0 | libcerror_error_set( |
569 | 0 | error, |
570 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
571 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
572 | 0 | "%s: invalid UTF-16 string size.", |
573 | 0 | function ); |
574 | |
|
575 | 0 | return( -1 ); |
576 | 0 | } |
577 | 0 | *utf16_string_size = 0; |
578 | 0 | } |
579 | 0 | else |
580 | 0 | { |
581 | 0 | if( libuna_utf16_string_size_from_utf16_stream( |
582 | 0 | volume_name_values->name, |
583 | 0 | (size_t) volume_name_values->name_size, |
584 | 0 | LIBUNA_ENDIAN_LITTLE, |
585 | 0 | utf16_string_size, |
586 | 0 | error ) != 1 ) |
587 | 0 | { |
588 | 0 | libcerror_error_set( |
589 | 0 | error, |
590 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
591 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
592 | 0 | "%s: unable to retrieve UTF-16 string size.", |
593 | 0 | function ); |
594 | |
|
595 | 0 | return( -1 ); |
596 | 0 | } |
597 | 0 | } |
598 | 0 | return( 1 ); |
599 | 0 | } |
600 | | |
601 | | /* Retrieves the UTF-16 encoded name |
602 | | * The size should include the end of string character |
603 | | * Returns 1 if successful or -1 on error |
604 | | */ |
605 | | int libfsntfs_volume_name_values_get_utf16_name( |
606 | | libfsntfs_volume_name_values_t *volume_name_values, |
607 | | uint16_t *utf16_string, |
608 | | size_t utf16_string_size, |
609 | | libcerror_error_t **error ) |
610 | 0 | { |
611 | 0 | static char *function = "libfsntfs_volume_name_values_get_utf16_name"; |
612 | |
|
613 | 0 | if( volume_name_values == NULL ) |
614 | 0 | { |
615 | 0 | libcerror_error_set( |
616 | 0 | error, |
617 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
618 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
619 | 0 | "%s: invalid volume name values.", |
620 | 0 | function ); |
621 | |
|
622 | 0 | return( -1 ); |
623 | 0 | } |
624 | 0 | if( volume_name_values->name_size == 0 ) |
625 | 0 | { |
626 | 0 | if( utf16_string == NULL ) |
627 | 0 | { |
628 | 0 | libcerror_error_set( |
629 | 0 | error, |
630 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
631 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
632 | 0 | "%s: invalid UTF-16 string.", |
633 | 0 | function ); |
634 | |
|
635 | 0 | return( -1 ); |
636 | 0 | } |
637 | 0 | if( utf16_string_size > (size_t) SSIZE_MAX ) |
638 | 0 | { |
639 | 0 | libcerror_error_set( |
640 | 0 | error, |
641 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
642 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
643 | 0 | "%s: invalid UTF-16 string size value exceeds maximum.", |
644 | 0 | function ); |
645 | |
|
646 | 0 | return( -1 ); |
647 | 0 | } |
648 | 0 | if( utf16_string_size < 1 ) |
649 | 0 | { |
650 | 0 | libcerror_error_set( |
651 | 0 | error, |
652 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
653 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
654 | 0 | "%s: UTF-16 string size value too small.", |
655 | 0 | function ); |
656 | |
|
657 | 0 | return( -1 ); |
658 | 0 | } |
659 | 0 | utf16_string[ 0 ] = 0; |
660 | 0 | } |
661 | 0 | else |
662 | 0 | { |
663 | 0 | if( libuna_utf16_string_copy_from_utf16_stream( |
664 | 0 | utf16_string, |
665 | 0 | utf16_string_size, |
666 | 0 | volume_name_values->name, |
667 | 0 | (size_t) volume_name_values->name_size, |
668 | 0 | LIBUNA_ENDIAN_LITTLE, |
669 | 0 | error ) != 1 ) |
670 | 0 | { |
671 | 0 | libcerror_error_set( |
672 | 0 | error, |
673 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
674 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
675 | 0 | "%s: unable to retrieve UTF-16 string.", |
676 | 0 | function ); |
677 | |
|
678 | 0 | return( -1 ); |
679 | 0 | } |
680 | 0 | } |
681 | 0 | return( 1 ); |
682 | 0 | } |
683 | | |