Coverage Report

Created: 2024-02-25 07:19

/src/libewf/libfvalue/libfvalue_table.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Values table 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 <types.h>
26
27
#include "libfvalue_codepage.h"
28
#include "libfvalue_definitions.h"
29
#include "libfvalue_libcdata.h"
30
#include "libfvalue_libcerror.h"
31
#include "libfvalue_table.h"
32
#include "libfvalue_types.h"
33
#include "libfvalue_value.h"
34
#include "libfvalue_value_type.h"
35
36
/* Creates a values table
37
 * Make sure the value table is referencing, is set to NULL
38
 * Returns 1 if successful or -1 on error
39
 */
40
int libfvalue_table_initialize(
41
     libfvalue_table_t **table,
42
     int number_of_values,
43
     libcerror_error_t **error )
44
3.12k
{
45
3.12k
  libfvalue_internal_table_t *internal_table = NULL;
46
3.12k
  static char *function                      = "libfvalue_table_initialize";
47
48
3.12k
  if( table == NULL )
49
0
  {
50
0
    libcerror_error_set(
51
0
     error,
52
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
53
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
54
0
     "%s: invalid values table.",
55
0
     function );
56
57
0
    return( -1 );
58
0
  }
59
3.12k
  if( *table != NULL )
60
0
  {
61
0
    libcerror_error_set(
62
0
     error,
63
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
64
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
65
0
     "%s: invalid table value already set.",
66
0
     function );
67
68
0
    return( -1 );
69
0
  }
70
3.12k
  internal_table = memory_allocate_structure(
71
3.12k
                    libfvalue_internal_table_t );
72
73
3.12k
  if( internal_table == NULL )
74
0
  {
75
0
    libcerror_error_set(
76
0
     error,
77
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
78
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
79
0
     "%s: unable to create values table.",
80
0
     function );
81
82
0
    goto on_error;
83
0
  }
84
3.12k
  if( memory_set(
85
3.12k
       internal_table,
86
3.12k
       0,
87
3.12k
       sizeof( libfvalue_internal_table_t ) ) == NULL )
88
0
  {
89
0
    libcerror_error_set(
90
0
     error,
91
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
92
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
93
0
     "%s: unable to clear values table.",
94
0
     function );
95
96
0
    memory_free(
97
0
     internal_table );
98
99
0
    return( -1 );
100
0
  }
101
3.12k
  if( libcdata_array_initialize(
102
3.12k
       &( internal_table->values ),
103
3.12k
       number_of_values,
104
3.12k
       error ) != 1 )
105
0
  {
106
0
    libcerror_error_set(
107
0
     error,
108
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
109
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
110
0
     "%s: unable to create values array.",
111
0
     function );
112
113
0
    goto on_error;
114
0
  }
115
3.12k
  *table = (libfvalue_table_t *) internal_table;
116
117
3.12k
  return( 1 );
118
119
0
on_error:
120
0
  if( internal_table != NULL )
121
0
  {
122
0
    memory_free(
123
0
     internal_table );
124
0
  }
125
0
  return( -1 );
126
3.12k
}
127
128
/* Frees a table
129
 * Returns 1 if successful or -1 on error
130
 */
131
int libfvalue_table_free(
132
     libfvalue_table_t **table,
133
     libcerror_error_t **error )
134
3.12k
{
135
3.12k
  libfvalue_internal_table_t *internal_table = NULL;
136
3.12k
  static char *function                      = "libfvalue_table_free";
137
3.12k
  int result                                 = 1;
138
139
3.12k
  if( table == NULL )
140
0
  {
141
0
    libcerror_error_set(
142
0
     error,
143
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
144
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
145
0
     "%s: invalid table.",
146
0
     function );
147
148
0
    return( -1 );
149
0
  }
150
3.12k
  if( *table != NULL )
151
3.12k
  {
152
3.12k
    internal_table = (libfvalue_internal_table_t *) *table;
153
3.12k
    *table         = NULL;
154
155
3.12k
    if( libcdata_array_free(
156
3.12k
         &( internal_table->values ),
157
3.12k
         (int (*)(intptr_t **, libcerror_error_t **)) &libfvalue_value_free,
158
3.12k
         error ) != 1 )
159
0
    {
160
0
      libcerror_error_set(
161
0
       error,
162
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
163
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
164
0
       "%s: unable to free the values array.",
165
0
       function );
166
167
0
      result = -1;
168
0
    }
169
3.12k
    memory_free(
170
3.12k
     internal_table );
171
3.12k
  }
172
3.12k
  return( result );
173
3.12k
}
174
175
/* Empties the values table
176
 * Returns 1 if successful or -1 on error
177
 */
178
int libfvalue_table_empty(
179
     libfvalue_table_t *table,
180
     libcerror_error_t **error )
181
0
{
182
0
  libfvalue_internal_table_t *internal_table = NULL;
183
0
  static char *function                      = "libfvalue_table_empty";
184
185
0
  if( table == NULL )
186
0
  {
187
0
    libcerror_error_set(
188
0
     error,
189
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
190
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
191
0
     "%s: invalid values table.",
192
0
     function );
193
194
0
    return( -1 );
195
0
  }
196
0
  internal_table = (libfvalue_internal_table_t *) table;
197
198
0
  if( libcdata_array_empty(
199
0
       internal_table->values,
200
0
       (int (*)(intptr_t **, libcerror_error_t **)) &libfvalue_value_free,
201
0
       error ) != 1 )
202
0
  {
203
0
    libcerror_error_set(
204
0
     error,
205
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
206
0
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
207
0
     "%s: unable to empty values array.",
208
0
     function );
209
210
0
    return( -1 );
211
0
  }
212
0
  return( 1 );
213
0
}
214
215
/* Resizes the values table
216
 * Returns 1 if successful or -1 on error
217
 */
218
int libfvalue_table_resize(
219
     libfvalue_table_t *table,
220
     int number_of_values,
221
     libcerror_error_t **error )
222
0
{
223
0
  libfvalue_internal_table_t *internal_table = NULL;
224
0
  static char *function                      = "libfvalue_table_resize";
225
226
0
  if( table == NULL )
227
0
  {
228
0
    libcerror_error_set(
229
0
     error,
230
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
231
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
232
0
     "%s: invalid values table.",
233
0
     function );
234
235
0
    return( -1 );
236
0
  }
237
0
  internal_table = (libfvalue_internal_table_t *) table;
238
239
0
  if( libcdata_array_resize(
240
0
       internal_table->values,
241
0
       number_of_values,
242
0
       (int (*)(intptr_t **, libcerror_error_t **)) &libfvalue_value_free,
243
0
       error ) != 1 )
244
0
  {
245
0
    libcerror_error_set(
246
0
     error,
247
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
248
0
     LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED,
249
0
     "%s: unable to resize values array.",
250
0
     function );
251
252
0
    return( -1 );
253
0
  }
254
0
  return( 1 );
255
0
}
256
257
/* Clones a table
258
 * Returns 1 if successful or -1 on error
259
 */
260
int libfvalue_table_clone(
261
     libfvalue_table_t **destination_table,
262
     libfvalue_table_t *source_table,
263
     libcerror_error_t **error )
264
0
{
265
0
  libfvalue_internal_table_t *internal_destination_table = NULL;
266
0
  libfvalue_internal_table_t *internal_source_table      = NULL;
267
0
  static char *function                                  = "libfvalue_table_clone";
268
269
0
  if( destination_table == NULL )
270
0
  {
271
0
    libcerror_error_set(
272
0
     error,
273
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
274
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
275
0
     "%s: invalid destination table.",
276
0
     function );
277
278
0
    return( -1 );
279
0
  }
280
0
  if( *destination_table != NULL )
281
0
  {
282
0
    libcerror_error_set(
283
0
     error,
284
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
285
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
286
0
     "%s: destination table already set.",
287
0
     function );
288
289
0
    return( -1 );
290
0
  }
291
0
  if( source_table == NULL )
292
0
  {
293
0
    *destination_table = NULL;
294
295
0
    return( 1 );
296
0
  }
297
0
  internal_source_table = (libfvalue_internal_table_t *) source_table;
298
299
0
  internal_destination_table = memory_allocate_structure(
300
0
                    libfvalue_internal_table_t );
301
302
0
  if( internal_destination_table == NULL )
303
0
  {
304
0
    libcerror_error_set(
305
0
     error,
306
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
307
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
308
0
     "%s: unable to create destination values table.",
309
0
     function );
310
311
0
    goto on_error;
312
0
  }
313
0
  if( memory_set(
314
0
       internal_destination_table,
315
0
       0,
316
0
       sizeof( libfvalue_internal_table_t ) ) == NULL )
317
0
  {
318
0
    libcerror_error_set(
319
0
     error,
320
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
321
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
322
0
     "%s: unable to clear destination values table.",
323
0
     function );
324
325
0
    goto on_error;
326
0
  }
327
0
  if( libcdata_array_clone(
328
0
       &( internal_destination_table->values ),
329
0
       internal_source_table->values,
330
0
       (int (*)(intptr_t **, libcerror_error_t **)) &libfvalue_value_free,
331
0
       (int (*)(intptr_t **, intptr_t *, libcerror_error_t **) ) &libfvalue_value_clone,
332
0
       error ) != 1 )
333
0
  {
334
0
    libcerror_error_set(
335
0
     error,
336
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
337
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
338
0
     "%s: unable to create destination values array.",
339
0
     function );
340
341
0
    goto on_error;
342
0
  }
343
0
  *destination_table = (libfvalue_table_t *) internal_destination_table;
344
345
0
  return( 1 );
346
347
0
on_error:
348
0
  if( internal_destination_table != NULL )
349
0
  {
350
0
    memory_free(
351
0
     internal_destination_table );
352
0
  }
353
0
  return( -1 );
354
0
}
355
356
/* Retrieves the number of values
357
 * Returns 1 if successful or -1 on error
358
 */
359
int libfvalue_table_get_number_of_values(
360
     libfvalue_table_t *table,
361
     int *number_of_values,
362
     libcerror_error_t **error )
363
0
{
364
0
  libfvalue_internal_table_t *internal_table = NULL;
365
0
  static char *function                      = "libfvalue_table_get_number_of_values";
366
367
0
  if( table == NULL )
368
0
  {
369
0
    libcerror_error_set(
370
0
     error,
371
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
372
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
373
0
     "%s: invalid values table.",
374
0
     function );
375
376
0
    return( -1 );
377
0
  }
378
0
  internal_table = (libfvalue_internal_table_t *) table;
379
380
0
  if( libcdata_array_get_number_of_entries(
381
0
       internal_table->values,
382
0
       number_of_values,
383
0
       error ) != 1 )
384
0
  {
385
0
    libcerror_error_set(
386
0
     error,
387
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
388
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
389
0
     "%s: unable to retrieve number of entries in the values array.",
390
0
     function );
391
392
0
    return( -1 );
393
0
  }
394
0
  return( 1 );
395
0
}
396
397
/* Retrieves the index for an identifier
398
 *
399
 * When LIBFVALUE_TABLE_FLAG_ALLOW_PARTIAL_MATCH is set a match
400
 * of the first part of the identifier is allowed.
401
 *
402
 * Returns 1 if successful, 0 if no index was found or -1 on error
403
 */
404
int libfvalue_table_get_index_by_identifier(
405
     libfvalue_table_t *table,
406
     const uint8_t *identifier,
407
     size_t identifier_size,
408
     int *value_index,
409
     uint8_t flags,
410
     libcerror_error_t **error )
411
6.36k
{
412
6.36k
  libfvalue_internal_table_t *internal_table = NULL;
413
6.36k
  libfvalue_internal_value_t *internal_value = NULL;
414
6.36k
  static char *function                      = "libfvalue_table_get_index_by_identifier";
415
6.36k
  size_t compare_size                        = 0;
416
6.36k
  int number_of_values                       = 0;
417
6.36k
  int result                                 = 0;
418
419
6.36k
  if( table == NULL )
420
0
  {
421
0
    libcerror_error_set(
422
0
     error,
423
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
424
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
425
0
     "%s: invalid values table.",
426
0
     function );
427
428
0
    return( -1 );
429
0
  }
430
6.36k
  internal_table = (libfvalue_internal_table_t *) table;
431
432
6.36k
  if( identifier == NULL )
433
0
  {
434
0
    libcerror_error_set(
435
0
     error,
436
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
437
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
438
0
     "%s: invalid identifier.",
439
0
     function );
440
441
0
    return( -1 );
442
0
  }
443
6.36k
  if( ( identifier_size == 0 )
444
6.36k
   || ( identifier_size > (size_t) SSIZE_MAX ) )
445
0
  {
446
0
    libcerror_error_set(
447
0
     error,
448
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
449
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
450
0
     "%s: invalid identifier size value out of bounds.",
451
0
     function );
452
453
0
    return( -1 );
454
0
  }
455
6.36k
  if( value_index == NULL )
456
0
  {
457
0
    libcerror_error_set(
458
0
     error,
459
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
460
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
461
0
     "%s: invalid value index.",
462
0
     function );
463
464
0
    return( -1 );
465
0
  }
466
6.36k
  if( ( flags & ~( LIBFVALUE_TABLE_FLAG_ALLOW_PARTIAL_MATCH ) ) != 0 )
467
0
  {
468
0
    libcerror_error_set(
469
0
     error,
470
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
471
0
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
472
0
     "%s: unsupported flags: 0x%02" PRIx8 ".",
473
0
     function,
474
0
     flags );
475
476
0
    return( -1 );
477
0
  }
478
6.36k
  if( libcdata_array_get_number_of_entries(
479
6.36k
       internal_table->values,
480
6.36k
       &number_of_values,
481
6.36k
       error ) != 1 )
482
0
  {
483
0
    libcerror_error_set(
484
0
     error,
485
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
486
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
487
0
     "%s: unable to retrieve number of entries in the values array.",
488
0
     function );
489
490
0
    return( -1 );
491
0
  }
492
6.36k
  for( *value_index = 0;
493
34.1k
       *value_index < number_of_values;
494
27.7k
       *value_index += 1 )
495
34.1k
  {
496
34.1k
    if( libcdata_array_get_entry_by_index(
497
34.1k
         internal_table->values,
498
34.1k
         *value_index,
499
34.1k
         (intptr_t **) &internal_value,
500
34.1k
         error ) != 1 )
501
0
    {
502
0
      libcerror_error_set(
503
0
       error,
504
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
505
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
506
0
       "%s: unable to retrieve entry: %d from values array.",
507
0
       function,
508
0
       *value_index );
509
510
0
      return( -1 );
511
0
    }
512
34.1k
    if( internal_value == NULL )
513
0
    {
514
0
      libcerror_error_set(
515
0
       error,
516
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
517
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
518
0
       "%s: missing internal value.",
519
0
       function );
520
521
0
      return( -1 );
522
0
    }
523
34.1k
    if( ( flags & LIBFVALUE_TABLE_FLAG_ALLOW_PARTIAL_MATCH ) == 0 )
524
34.1k
    {
525
34.1k
      if( internal_value->identifier_size != identifier_size )
526
24.1k
      {
527
24.1k
        continue;
528
24.1k
      }
529
34.1k
    }
530
9.92k
    if( internal_value->identifier_size <= identifier_size )
531
9.92k
    {
532
9.92k
      compare_size = internal_value->identifier_size;
533
9.92k
    }
534
0
    else
535
0
    {
536
0
      compare_size = identifier_size;
537
0
    }
538
9.92k
    result = memory_compare(
539
9.92k
              internal_value->identifier,
540
9.92k
              identifier,
541
9.92k
              compare_size );
542
543
9.92k
    if( result == 0 )
544
6.36k
    {
545
6.36k
      return( 1 );
546
6.36k
    }
547
9.92k
  }
548
0
  return( 0 );
549
6.36k
}
550
551
/* Retrieves a specific value
552
 * Returns 1 if successful or -1 on error
553
 */
554
int libfvalue_table_get_value_by_index(
555
     libfvalue_table_t *table,
556
     int value_index,
557
     libfvalue_value_t **value,
558
     libcerror_error_t **error )
559
0
{
560
0
  libfvalue_internal_table_t *internal_table = NULL;
561
0
  static char *function                      = "libfvalue_table_get_value_by_index";
562
563
0
  if( table == NULL )
564
0
  {
565
0
    libcerror_error_set(
566
0
     error,
567
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
568
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
569
0
     "%s: invalid values table.",
570
0
     function );
571
572
0
    return( -1 );
573
0
  }
574
0
  internal_table = (libfvalue_internal_table_t *) table;
575
576
0
  if( libcdata_array_get_entry_by_index(
577
0
       internal_table->values,
578
0
       value_index,
579
0
       (intptr_t **) value,
580
0
       error ) != 1 )
581
0
  {
582
0
    libcerror_error_set(
583
0
     error,
584
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
585
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
586
0
     "%s: unable to retrieve entry: %d from values array.",
587
0
     function,
588
0
     value_index );
589
590
0
    return( -1 );
591
0
  }
592
0
  return( 1 );
593
0
}
594
595
/* Retrieves a value for the specific identifier
596
 *
597
 * When LIBFVALUE_TABLE_FLAG_ALLOW_PARTIAL_MATCH is set a match
598
 * of the first part of the identifier is allowed.
599
 *
600
 * Returns 1 if successful, 0 if value not available or -1 on error
601
 */
602
int libfvalue_table_get_value_by_identifier(
603
     libfvalue_table_t *table,
604
     const uint8_t *identifier,
605
     size_t identifier_size,
606
     libfvalue_value_t **value,
607
     uint8_t flags,
608
     libcerror_error_t **error )
609
0
{
610
0
  libfvalue_internal_table_t *internal_table = NULL;
611
0
  static char *function                      = "libfvalue_table_get_value_by_identifier";
612
0
  int value_index                            = 0;
613
0
  int result                                 = 0;
614
615
0
  if( table == NULL )
616
0
  {
617
0
    libcerror_error_set(
618
0
     error,
619
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
620
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
621
0
     "%s: invalid values table.",
622
0
     function );
623
624
0
    return( -1 );
625
0
  }
626
0
  internal_table = (libfvalue_internal_table_t *) table;
627
628
0
  if( value == NULL )
629
0
  {
630
0
    libcerror_error_set(
631
0
     error,
632
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
633
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
634
0
     "%s: invalid value.",
635
0
     function );
636
637
0
    return( -1 );
638
0
  }
639
0
  result = libfvalue_table_get_index_by_identifier(
640
0
            table,
641
0
            identifier,
642
0
            identifier_size,
643
0
            &value_index,
644
0
            flags,
645
0
            error );
646
647
0
  if( result == -1 )
648
0
  {
649
0
    libcerror_error_set(
650
0
     error,
651
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
652
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
653
0
     "%s: unable to find index for: %s.",
654
0
     function,
655
0
     identifier );
656
657
0
    return( -1 );
658
0
  }
659
0
  else if( result != 0 )
660
0
  {
661
0
    if( libcdata_array_get_entry_by_index(
662
0
         internal_table->values,
663
0
         value_index,
664
0
         (intptr_t **) value,
665
0
         error ) != 1 )
666
0
    {
667
0
      libcerror_error_set(
668
0
       error,
669
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
670
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
671
0
       "%s: unable to retrieve entry: %d from values array.",
672
0
       function,
673
0
       value_index );
674
675
0
      return( -1 );
676
0
    }
677
0
  }
678
0
  return( result );
679
0
}
680
681
/* Sets a specific value
682
 * Frees the stored value if necessary
683
 * Returns 1 if successful or -1 on error
684
 */
685
int libfvalue_table_set_value_by_index(
686
     libfvalue_table_t *table,
687
     int value_index,
688
     libfvalue_value_t *value,
689
     libcerror_error_t **error )
690
53.1k
{
691
53.1k
  libfvalue_internal_table_t *internal_table = NULL;
692
53.1k
  libfvalue_value_t *stored_value            = NULL;
693
53.1k
  static char *function                      = "libfvalue_table_set_value_by_index";
694
695
53.1k
  if( table == NULL )
696
0
  {
697
0
    libcerror_error_set(
698
0
     error,
699
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
700
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
701
0
     "%s: invalid values table.",
702
0
     function );
703
704
0
    return( -1 );
705
0
  }
706
53.1k
  internal_table = (libfvalue_internal_table_t *) table;
707
708
53.1k
  if( libcdata_array_get_entry_by_index(
709
53.1k
       internal_table->values,
710
53.1k
       value_index,
711
53.1k
       (intptr_t **) &stored_value,
712
53.1k
       error ) != 1 )
713
0
  {
714
0
    libcerror_error_set(
715
0
     error,
716
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
717
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
718
0
     "%s: unable to retrieve entry: %d from values array.",
719
0
     function,
720
0
     value_index );
721
722
0
    return( -1 );
723
0
  }
724
53.1k
  if( ( stored_value != NULL )
725
53.1k
   && ( stored_value != value ) )
726
0
  {
727
0
    if( libfvalue_value_free(
728
0
         &stored_value,
729
0
         error ) != 1 )
730
0
    {
731
0
      libcerror_error_set(
732
0
       error,
733
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
734
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
735
0
       "%s: unable to free value: %d.",
736
0
       function,
737
0
       value_index );
738
739
0
      return( -1 );
740
0
    }
741
0
  }
742
53.1k
  if( libcdata_array_set_entry_by_index(
743
53.1k
       internal_table->values,
744
53.1k
       value_index,
745
53.1k
       (intptr_t *) value,
746
53.1k
       error ) != 1 )
747
0
  {
748
0
    libcerror_error_set(
749
0
     error,
750
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
751
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
752
0
     "%s: unable to set entry: %d in values array.",
753
0
     function,
754
0
     value_index );
755
756
0
    return( -1 );
757
0
  }
758
53.1k
  return( 1 );
759
53.1k
}
760
761
/* Sets a value in the values table
762
 * This function appends a new value or replaces an existing value
763
 * Returns 1 if successful or -1 on error
764
 */
765
int libfvalue_table_set_value(
766
     libfvalue_table_t *table,
767
     libfvalue_value_t *value,
768
     libcerror_error_t **error )
769
6.36k
{
770
6.36k
  libfvalue_internal_table_t *internal_table = NULL;
771
6.36k
  libfvalue_internal_value_t *internal_value = NULL;
772
6.36k
  libfvalue_value_t *stored_value            = NULL;
773
6.36k
  static char *function                      = "libfvalue_table_set_value";
774
6.36k
  int value_index                            = 0;
775
6.36k
  int result                                 = 0;
776
777
6.36k
  if( table == NULL )
778
0
  {
779
0
    libcerror_error_set(
780
0
     error,
781
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
782
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
783
0
     "%s: invalid values table.",
784
0
     function );
785
786
0
    return( -1 );
787
0
  }
788
6.36k
  internal_table = (libfvalue_internal_table_t *) table;
789
790
6.36k
  if( value == NULL )
791
0
  {
792
0
    libcerror_error_set(
793
0
     error,
794
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
795
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
796
0
     "%s: invalid value.",
797
0
     function );
798
799
0
    return( -1 );
800
0
  }
801
6.36k
  internal_value = (libfvalue_internal_value_t *) value;
802
803
6.36k
  result = libfvalue_table_get_index_by_identifier(
804
6.36k
            table,
805
6.36k
            internal_value->identifier,
806
6.36k
            internal_value->identifier_size,
807
6.36k
            &value_index,
808
6.36k
            0,
809
6.36k
            error );
810
811
6.36k
  if( result == -1 )
812
0
  {
813
0
    libcerror_error_set(
814
0
     error,
815
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
816
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
817
0
     "%s: unable to find index for: %s.",
818
0
     function,
819
0
     (char *) internal_value->identifier );
820
821
0
    return( -1 );
822
0
  }
823
6.36k
  else if( result == 0 )
824
0
  {
825
0
    if( libcdata_array_insert_entry(
826
0
         internal_table->values,
827
0
         &value_index,
828
0
         (intptr_t *) value,
829
0
         &libfvalue_compare_identifier,
830
0
         LIBCDATA_INSERT_FLAG_UNIQUE_ENTRIES,
831
0
         error ) != 1 )
832
0
    {
833
0
      libcerror_error_set(
834
0
       error,
835
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
836
0
       LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
837
0
       "%s: unable to insert value: %s in values array.",
838
0
       function,
839
0
       (char *) internal_value->identifier );
840
841
0
      return( -1 );
842
0
    }
843
0
  }
844
6.36k
  else
845
6.36k
  {
846
6.36k
    if( libcdata_array_get_entry_by_index(
847
6.36k
         internal_table->values,
848
6.36k
         value_index,
849
6.36k
         (intptr_t **) &stored_value,
850
6.36k
         error ) != 1 )
851
0
    {
852
0
      libcerror_error_set(
853
0
       error,
854
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
855
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
856
0
       "%s: unable to retrieve entry: %d from values array.",
857
0
       function,
858
0
       value_index );
859
860
0
      return( -1 );
861
0
    }
862
6.36k
    if( ( stored_value != NULL )
863
6.36k
     && ( stored_value != value ) )
864
6.36k
    {
865
6.36k
      if( libcdata_array_set_entry_by_index(
866
6.36k
           internal_table->values,
867
6.36k
           value_index,
868
6.36k
           (intptr_t *) value,
869
6.36k
           error ) != 1 )
870
0
      {
871
0
        libcerror_error_set(
872
0
         error,
873
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
874
0
         LIBCERROR_RUNTIME_ERROR_SET_FAILED,
875
0
         "%s: unable to set entry: %d in values array.",
876
0
         function,
877
0
         value_index );
878
879
0
        return( -1 );
880
0
      }
881
6.36k
      if( libfvalue_value_free(
882
6.36k
           &stored_value,
883
6.36k
           error ) != 1 )
884
0
      {
885
0
        libcerror_error_set(
886
0
         error,
887
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
888
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
889
0
         "%s: unable to free value: %d.",
890
0
         function,
891
0
         value_index );
892
893
0
        return( -1 );
894
0
      }
895
6.36k
    }
896
6.36k
  }
897
6.36k
  return( 1 );
898
6.36k
}
899
900
enum LIBFVALUE_XML_TAG_TYPES
901
{
902
  LIBFVALUE_XML_TAG_TYPE_CLOSE  = (uint8_t) 'c',
903
  LIBFVALUE_XML_TAG_TYPE_OPEN = (uint8_t) 'o'
904
};
905
906
/* Copies the values table from an UTF-8 encoded XML string
907
 * Returns 1 if successful, 0 if the requested section could not be found or -1 on error
908
 */
909
int libfvalue_table_copy_from_utf8_xml_string(
910
     libfvalue_table_t *table,
911
     const uint8_t *utf8_string,
912
     size_t utf8_string_size,
913
     const uint8_t *table_name,
914
     size_t table_name_length,
915
     libcerror_error_t **error )
916
54
{
917
54
  libfvalue_internal_table_t *internal_table = NULL;
918
54
  libfvalue_value_t *value                   = NULL;
919
54
  uint8_t *value_data                        = NULL;
920
54
  uint8_t *value_identifier                  = NULL;
921
54
  const uint8_t *xml_table_name              = NULL;
922
54
  const uint8_t *xml_tag_data                = NULL;
923
54
  const uint8_t *xml_tag_name                = NULL;
924
54
  static char *function                      = "libfvalue_table_copy_from_utf8_xml_string";
925
54
  size_t string_index                        = 0;
926
54
  size_t value_identifier_length             = 0;
927
54
  size_t value_data_length                   = 0;
928
54
  size_t xml_table_name_length               = 0;
929
54
  size_t xml_tag_name_length                 = 0;
930
54
  uint8_t xml_tag_type                       = 0;
931
54
  int result                                 = 0;
932
54
  int value_index                            = 0;
933
934
54
  if( table == NULL )
935
0
  {
936
0
    libcerror_error_set(
937
0
     error,
938
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
939
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
940
0
     "%s: invalid values table.",
941
0
     function );
942
943
0
    return( -1 );
944
0
  }
945
54
  internal_table = (libfvalue_internal_table_t *) table;
946
947
54
  if( utf8_string == NULL )
948
0
  {
949
0
    libcerror_error_set(
950
0
     error,
951
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
952
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
953
0
     "%s: invalid UTF-8 string.",
954
0
     function );
955
956
0
    return( -1 );
957
0
  }
958
54
  if( ( utf8_string_size == 0 )
959
54
   || ( utf8_string_size > (size_t) SSIZE_MAX ) )
960
1
  {
961
1
    libcerror_error_set(
962
1
     error,
963
1
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
964
1
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
965
1
     "%s: invalid UTF-8 string size value out of bounds.",
966
1
     function );
967
968
1
    return( -1 );
969
1
  }
970
53
  if( table_name == NULL )
971
0
  {
972
0
    libcerror_error_set(
973
0
     error,
974
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
975
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
976
0
     "%s: invalid table name.",
977
0
     function );
978
979
0
    return( -1 );
980
0
  }
981
53
  if( table_name_length > (size_t) SSIZE_MAX )
982
0
  {
983
0
    libcerror_error_set(
984
0
     error,
985
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
986
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
987
0
     "%s: invalid table name size value out of bounds.",
988
0
     function );
989
990
0
    return( -1 );
991
0
  }
992
#ifdef TODO
993
  if( libcdata_array_empty(
994
       internal_table->values,
995
       (int (*)(intptr_t **, libcerror_error_t **)) &libfvalue_value_free,
996
       error ) != 1 )
997
  {
998
    libcerror_error_set(
999
     error,
1000
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1001
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
1002
     "%s: unable to empty values array.",
1003
     function );
1004
1005
    return( -1 );
1006
  }
1007
#endif
1008
  /* TODO check for "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; */
1009
1010
  /* Note that below numeric values for the characters are used to prevent
1011
   * platform specific values being assigned
1012
   */
1013
17.0k
  while( string_index < utf8_string_size )
1014
17.0k
  {
1015
    /* Look for the start of the XML tag: '<'
1016
     */
1017
17.0k
    if( utf8_string[ string_index++ ] != 0x3c )
1018
15.1k
    {
1019
15.1k
      continue;
1020
15.1k
    }
1021
1.89k
    if( string_index >= utf8_string_size )
1022
2
    {
1023
2
      break;
1024
2
    }
1025
    /* Determine if the XML tag is an open or close tag: '/'
1026
     */
1027
1.88k
    if( utf8_string[ string_index ] != 0x2f )
1028
1.56k
    {
1029
1.56k
      xml_tag_type = LIBFVALUE_XML_TAG_TYPE_OPEN;
1030
1.56k
    }
1031
319
    else
1032
319
    {
1033
319
      xml_tag_type = LIBFVALUE_XML_TAG_TYPE_CLOSE;
1034
1035
319
      string_index++;
1036
1037
319
      if( string_index >= utf8_string_size )
1038
1
      {
1039
1
        break;
1040
1
      }
1041
319
    }
1042
1.88k
    xml_tag_name        = &( utf8_string[ string_index ] );
1043
1.88k
    xml_tag_name_length = 0;
1044
1045
7.75k
    while( string_index < utf8_string_size )
1046
7.75k
    {
1047
      /* The XML tag name should only consists of: [A-Za-z0-9_]
1048
       */
1049
7.75k
      if( ( ( utf8_string[ string_index ] >= 0x41 )
1050
7.75k
        &&  ( utf8_string[ string_index ] <= 0x5a ) )
1051
7.75k
       || ( ( utf8_string[ string_index ] >= 0x61 )
1052
6.35k
        &&  ( utf8_string[ string_index ] <= 0x7a ) )
1053
7.75k
       || ( ( utf8_string[ string_index ] >= 0x30 )
1054
4.26k
        &&  ( utf8_string[ string_index ] <= 0x39 ) )
1055
7.75k
       ||   ( utf8_string[ string_index ] == 0x5f ) )
1056
5.87k
      {
1057
5.87k
        xml_tag_name_length++;
1058
5.87k
      }
1059
1.88k
      else
1060
1.88k
      {
1061
1.88k
        break;
1062
1.88k
      }
1063
5.87k
      string_index++;
1064
5.87k
    }
1065
1.88k
    if( string_index >= utf8_string_size )
1066
7
    {
1067
7
      break;
1068
7
    }
1069
    /* TODO add support for XML tag attributes but ignore them for now
1070
     */
1071
12.6k
    while( string_index < utf8_string_size )
1072
12.6k
    {
1073
      /* Look for the end of the XML tag: '>'
1074
       */
1075
12.6k
      if( utf8_string[ string_index ] == 0x3e )
1076
1.85k
      {
1077
1.85k
        break;
1078
1.85k
      }
1079
10.7k
      string_index++;
1080
10.7k
    }
1081
1.88k
    if( string_index >= utf8_string_size )
1082
29
    {
1083
29
      break;
1084
29
    }
1085
    /* Look for the end of the XML tag: '>'
1086
     */
1087
1.85k
    if( utf8_string[ string_index++ ] != 0x3e )
1088
0
    {
1089
0
      continue;
1090
0
    }
1091
1.85k
    if( string_index >= utf8_string_size )
1092
1
    {
1093
1
      break;
1094
1
    }
1095
1.85k
    if( ( xml_tag_name == NULL )
1096
1.85k
     || ( xml_tag_name_length == 0 ) )
1097
784
    {
1098
784
      continue;
1099
784
    }
1100
1.06k
    if( xml_table_name == NULL )
1101
1.06k
    {
1102
1.06k
      if( ( xml_tag_type == LIBFVALUE_XML_TAG_TYPE_OPEN )
1103
1.06k
       && ( xml_tag_name_length == table_name_length )
1104
1.06k
       && ( narrow_string_compare(
1105
79
             table_name,
1106
79
             xml_tag_name,
1107
79
             xml_tag_name_length ) == 0 ) )
1108
0
      {
1109
0
        xml_table_name        = xml_tag_name;
1110
0
        xml_table_name_length = xml_tag_name_length;
1111
0
      }
1112
1.06k
    }
1113
0
    else if( value_identifier == NULL )
1114
0
    {
1115
0
      if( ( xml_tag_type == LIBFVALUE_XML_TAG_TYPE_CLOSE )
1116
0
       && ( xml_tag_name_length == xml_table_name_length )
1117
0
       && ( narrow_string_compare(
1118
0
             xml_table_name,
1119
0
             xml_tag_name,
1120
0
             xml_tag_name_length ) == 0 ) )
1121
0
      {
1122
0
        xml_table_name = NULL;
1123
0
        result         = 1;
1124
1125
0
        break;
1126
0
      }
1127
0
      else if( xml_tag_type == LIBFVALUE_XML_TAG_TYPE_OPEN )
1128
0
      {
1129
0
        value_identifier_length = xml_tag_name_length;
1130
1131
0
        value_identifier = (uint8_t *) memory_allocate(
1132
0
                                        sizeof( uint8_t ) * ( value_identifier_length + 1 ) );
1133
1134
0
        if( value_identifier == NULL )
1135
0
        {
1136
0
          libcerror_error_set(
1137
0
           error,
1138
0
           LIBCERROR_ERROR_DOMAIN_MEMORY,
1139
0
           LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
1140
0
           "%s: unable to create value identifier.",
1141
0
           function );
1142
1143
0
          goto on_error;
1144
0
        }
1145
0
        if( memory_copy(
1146
0
             value_identifier,
1147
0
             xml_tag_name,
1148
0
             value_identifier_length ) == NULL )
1149
0
        {
1150
0
          libcerror_error_set(
1151
0
           error,
1152
0
           LIBCERROR_ERROR_DOMAIN_MEMORY,
1153
0
           LIBCERROR_MEMORY_ERROR_SET_FAILED,
1154
0
           "%s: unable to clear values table.",
1155
0
           function );
1156
1157
0
          goto on_error;
1158
0
        }
1159
0
        value_identifier[ value_identifier_length ] = 0;
1160
1161
0
        xml_tag_data = &( utf8_string[ string_index ] );
1162
0
      }
1163
0
    }
1164
0
    else
1165
0
    {
1166
0
      if( ( xml_tag_type == LIBFVALUE_XML_TAG_TYPE_CLOSE )
1167
0
       && ( xml_tag_name_length == value_identifier_length )
1168
0
       && ( narrow_string_compare(
1169
0
             value_identifier,
1170
0
             xml_tag_name,
1171
0
             xml_tag_name_length ) == 0 ) )
1172
0
      {
1173
0
        result = libfvalue_table_get_index_by_identifier(
1174
0
                  table,
1175
0
                  value_identifier,
1176
0
                  value_identifier_length + 1,
1177
0
                  &value_index,
1178
0
                  0,
1179
0
                  error );
1180
1181
0
        if( result == -1 )
1182
0
        {
1183
0
          libcerror_error_set(
1184
0
           error,
1185
0
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
1186
0
           LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1187
0
           "%s: unable to find index for: %s.",
1188
0
           function,
1189
0
           (char *) value_identifier );
1190
1191
0
          goto on_error;
1192
0
        }
1193
0
        else if( result == 0 )
1194
0
        {
1195
0
          if( libfvalue_value_type_initialize(
1196
0
               &value,
1197
0
               LIBFVALUE_VALUE_TYPE_STRING_UTF8,
1198
0
               error ) != 1 )
1199
0
          {
1200
0
            libcerror_error_set(
1201
0
             error,
1202
0
             LIBCERROR_ERROR_DOMAIN_RUNTIME,
1203
0
             LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1204
0
             "%s: unable to create value: %s.",
1205
0
             function,
1206
0
             (char *) value_identifier );
1207
1208
0
            goto on_error;
1209
0
          }
1210
0
          if( libfvalue_value_set_identifier(
1211
0
               value,
1212
0
               value_identifier,
1213
0
               value_identifier_length + 1,
1214
0
               LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED,
1215
0
               error ) != 1 )
1216
0
          {
1217
0
            libcerror_error_set(
1218
0
             error,
1219
0
             LIBCERROR_ERROR_DOMAIN_RUNTIME,
1220
0
             LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1221
0
             "%s: unable to set identifier in value: %s.",
1222
0
             function,
1223
0
             (char *) value_identifier );
1224
1225
0
            libfvalue_value_free(
1226
0
             &value,
1227
0
             NULL );
1228
1229
0
            goto on_error;
1230
0
          }
1231
0
          if( libcdata_array_insert_entry(
1232
0
               internal_table->values,
1233
0
               &value_index,
1234
0
               (intptr_t *) value,
1235
0
               &libfvalue_compare_identifier,
1236
0
               LIBCDATA_INSERT_FLAG_UNIQUE_ENTRIES,
1237
0
               error ) != 1 )
1238
0
          {
1239
0
            libcerror_error_set(
1240
0
             error,
1241
0
             LIBCERROR_ERROR_DOMAIN_RUNTIME,
1242
0
             LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
1243
0
             "%s: unable to insert value: %s in values array.",
1244
0
             function,
1245
0
             (char *) value_identifier );
1246
1247
0
            libfvalue_value_free(
1248
0
             &value,
1249
0
             NULL );
1250
1251
0
            goto on_error;
1252
0
          }
1253
0
        }
1254
0
        else
1255
0
        {
1256
0
          if( libcdata_array_get_entry_by_index(
1257
0
               internal_table->values,
1258
0
               value_index,
1259
0
               (intptr_t **) &value,
1260
0
               error ) != 1 )
1261
0
          {
1262
0
            libcerror_error_set(
1263
0
             error,
1264
0
             LIBCERROR_ERROR_DOMAIN_RUNTIME,
1265
0
             LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1266
0
             "%s: unable to retrieve entry: %d from values array.",
1267
0
             function,
1268
0
             value_index );
1269
1270
0
            goto on_error;
1271
0
          }
1272
0
        }
1273
        /* Note that the XML tag name of the closing tag is preceded by
1274
         * 2 characters '</' which are not part of the data
1275
         */
1276
0
        value_data_length = (size_t) ( xml_tag_name - ( xml_tag_data + 2 ) );
1277
1278
0
        value_data = (uint8_t *) memory_allocate(
1279
0
                                  sizeof( uint8_t ) * ( value_data_length + 1 ) );
1280
1281
0
        if( value_data == NULL )
1282
0
        {
1283
0
          libcerror_error_set(
1284
0
           error,
1285
0
           LIBCERROR_ERROR_DOMAIN_MEMORY,
1286
0
           LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
1287
0
           "%s: unable to create value data.",
1288
0
           function );
1289
1290
0
          goto on_error;
1291
0
        }
1292
0
        if( memory_copy(
1293
0
             value_data,
1294
0
             xml_tag_data,
1295
0
             value_data_length ) == NULL )
1296
0
        {
1297
0
          libcerror_error_set(
1298
0
           error,
1299
0
           LIBCERROR_ERROR_DOMAIN_MEMORY,
1300
0
           LIBCERROR_MEMORY_ERROR_SET_FAILED,
1301
0
           "%s: unable to clear values table.",
1302
0
           function );
1303
1304
0
          goto on_error;
1305
0
        }
1306
0
        value_data[ value_data_length ] = 0;
1307
1308
0
        if( libfvalue_value_set_data(
1309
0
             value,
1310
0
             (uint8_t *) value_data,
1311
0
             value_data_length + 1,
1312
0
             LIBFVALUE_CODEPAGE_UTF8,
1313
0
             LIBFVALUE_VALUE_DATA_FLAG_MANAGED | LIBFVALUE_VALUE_DATA_FLAG_CLONE_BY_REFERENCE,
1314
0
             error ) != 1 )
1315
0
        {
1316
0
          libcerror_error_set(
1317
0
           error,
1318
0
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
1319
0
           LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1320
0
           "%s: unable to set value: %s data.",
1321
0
           function,
1322
0
           (char *) value_identifier );
1323
1324
0
          goto on_error;
1325
0
        }
1326
        /* value_data is now managed by the value
1327
         */
1328
0
        memory_free(
1329
0
         value_identifier );
1330
1331
0
        value_identifier = NULL;
1332
0
        value_data       = NULL;
1333
0
        value            = NULL;
1334
0
      }
1335
0
    }
1336
1.06k
  }
1337
53
  if( value_identifier != NULL )
1338
0
  {
1339
0
    memory_free(
1340
0
     value_identifier );
1341
0
  }
1342
53
  return( result );
1343
1344
0
on_error:
1345
0
  if( value_data != NULL )
1346
0
  {
1347
0
    memory_free(
1348
0
     value_data );
1349
0
  }
1350
0
  if( value_identifier != NULL )
1351
0
  {
1352
0
    memory_free(
1353
0
     value_identifier );
1354
0
  }
1355
0
  return( -1 );
1356
53
}
1357