Coverage Report

Created: 2026-04-04 07:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libphdi/libphdi/libphdi_xml_parser.c
Line
Count
Source
1
/* original parser id follows */
2
/* yysccsid[] = "@(#)yaccpar  1.9 (Berkeley) 02/21/93" */
3
/* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */
4
5
#define YYBYACC 1
6
#define YYMAJOR 1
7
#define YYMINOR 9
8
#define YYPATCH 20140715
9
10
496k
#define YYEMPTY        (-1)
11
#define yyclearin      (yychar = YYEMPTY)
12
#define yyerrok        (yyerrflag = 0)
13
#define YYRECOVERING() (yyerrflag != 0)
14
9
#define YYENOMEM       (-2)
15
133
#define YYEOF          0
16
17
#ifndef yyparse
18
#define yyparse    libphdi_xml_scanner_parse
19
#endif /* yyparse */
20
21
#ifndef yylex
22
496k
#define yylex      libphdi_xml_scanner_lex
23
#endif /* yylex */
24
25
#ifndef yyerror
26
544
#define yyerror    libphdi_xml_scanner_error
27
#endif /* yyerror */
28
29
#ifndef yychar
30
3.72M
#define yychar     libphdi_xml_scanner_char
31
#endif /* yychar */
32
33
#ifndef yyval
34
2.00M
#define yyval      libphdi_xml_scanner_val
35
#endif /* yyval */
36
37
#ifndef yylval
38
495k
#define yylval     libphdi_xml_scanner_lval
39
#endif /* yylval */
40
41
#ifndef yydebug
42
#define yydebug    libphdi_xml_scanner_debug
43
#endif /* yydebug */
44
45
#ifndef yynerrs
46
1.39k
#define yynerrs    libphdi_xml_scanner_nerrs
47
#endif /* yynerrs */
48
49
#ifndef yyerrflag
50
498k
#define yyerrflag  libphdi_xml_scanner_errflag
51
#endif /* yyerrflag */
52
53
#ifndef yylhs
54
880k
#define yylhs      libphdi_xml_scanner_lhs
55
#endif /* yylhs */
56
57
#ifndef yylen
58
880k
#define yylen      libphdi_xml_scanner_len
59
#endif /* yylen */
60
61
#ifndef yydefred
62
1.37M
#define yydefred   libphdi_xml_scanner_defred
63
#endif /* yydefred */
64
65
#ifndef yydgoto
66
597k
#define yydgoto    libphdi_xml_scanner_dgoto
67
#endif /* yydgoto */
68
69
#ifndef yysindex
70
946k
#define yysindex   libphdi_xml_scanner_sindex
71
#endif /* yysindex */
72
73
#ifndef yyrindex
74
248k
#define yyrindex   libphdi_xml_scanner_rindex
75
#endif /* yyrindex */
76
77
#ifndef yygindex
78
880k
#define yygindex   libphdi_xml_scanner_gindex
79
#endif /* yygindex */
80
81
#ifndef yytable
82
1.52M
#define yytable    libphdi_xml_scanner_table
83
#endif /* yytable */
84
85
#ifndef yycheck
86
1.27M
#define yycheck    libphdi_xml_scanner_check
87
#endif /* yycheck */
88
89
#ifndef yyname
90
#define yyname     libphdi_xml_scanner_name
91
#endif /* yyname */
92
93
#ifndef yyrule
94
#define yyrule     libphdi_xml_scanner_rule
95
#endif /* yyrule */
96
#define YYPREFIX "libphdi_xml_scanner_"
97
98
#define YYPURE 0
99
100
/*
101
 * XML parser functions
102
 *
103
 * Copyright (C) 2015-2025, Joachim Metz <joachim.metz@gmail.com>
104
 *
105
 * Refer to AUTHORS for acknowledgements.
106
 *
107
 * This program is free software: you can redistribute it and/or modify
108
 * it under the terms of the GNU Lesser General Public License as published by
109
 * the Free Software Foundation, either version 3 of the License, or
110
 * (at your option) any later version.
111
 *
112
 * This program is distributed in the hope that it will be useful,
113
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
114
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
115
 * GNU General Public License for more details.
116
 *
117
 * You should have received a copy of the GNU Lesser General Public License
118
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
119
 */
120
121
#include <common.h>
122
#include <memory.h>
123
#include <narrow_string.h>
124
#include <types.h>
125
126
#if defined( HAVE_STDLIB_H ) || defined( WINAPI )
127
#include <stdlib.h>
128
#endif
129
130
#include "libphdi_disk_descriptor_xml_file.h"
131
#include "libphdi_libcerror.h"
132
#include "libphdi_libcnotify.h"
133
#include "libphdi_types.h"
134
#include "libphdi_xml_tag.h"
135
136
#define YYMALLOC  libphdi_xml_scanner_alloc
137
#define YYREALLOC libphdi_xml_scanner_realloc
138
#define YYFREE    libphdi_xml_scanner_free
139
140
496k
#define YYLEX_PARAM NULL
141
#define YYPARSE_PARAM parser_state
142
143
#if defined( HAVE_DEBUG_OUTPUT )
144
#define libphdi_xml_parser_rule_print( string ) \
145
  if( libcnotify_verbose != 0 ) libcnotify_printf( "libphdi_xml_parser: rule: %s\n", string )
146
#else
147
#define libphdi_xml_parser_rule_print( string )
148
#endif
149
150
#ifdef YYSTYPE
151
#undef  YYSTYPE_IS_DECLARED
152
#define YYSTYPE_IS_DECLARED 1
153
#endif
154
#ifndef YYSTYPE_IS_DECLARED
155
#define YYSTYPE_IS_DECLARED 1
156
typedef union
157
{
158
        /* The numeric value
159
         */
160
        uint32_t numeric_value;
161
162
        /* The string value
163
         */
164
  struct xml_plist_string_value
165
  {
166
    /* The string data
167
     */
168
          const char *data;
169
170
    /* The string length
171
     */
172
    size_t length;
173
174
  } string_value;
175
} YYSTYPE;
176
#endif /* !YYSTYPE_IS_DECLARED */
177
178
typedef struct libphdi_xml_parser_state libphdi_xml_parser_state_t;
179
180
struct libphdi_xml_parser_state
181
{
182
  /* The disk descriptor XML file
183
   */
184
  libphdi_disk_descriptor_xml_file_t *disk_descriptor_xml_file;
185
186
  /* The error
187
   */
188
  libcerror_error_t **error;
189
190
  /* The root XML tag
191
   */
192
  libphdi_xml_tag_t *root_tag;
193
194
  /* The current XML tag
195
   */
196
  libphdi_xml_tag_t *current_tag;
197
198
  /* The parent XML tag
199
   */
200
  libphdi_xml_tag_t *parent_tag;
201
};
202
203
typedef size_t yy_size_t;
204
typedef struct yy_buffer_state* YY_BUFFER_STATE;
205
206
extern \
207
int libphdi_xml_scanner_suppress_error;
208
209
extern \
210
int libphdi_xml_scanner_lex_destroy(
211
     void );
212
213
extern \
214
void *libphdi_xml_scanner_alloc(
215
       yy_size_t size );
216
217
extern \
218
void *libphdi_xml_scanner_realloc(
219
       void *buffer,
220
       yy_size_t size );
221
222
extern \
223
void *libphdi_xml_scanner_free(
224
       void *buffer );
225
226
extern \
227
int libphdi_xml_scanner_lex(
228
     void *user_data );
229
230
extern \
231
void libphdi_xml_scanner_error(
232
      void *parser_state,
233
      const char *error_string );
234
235
extern \
236
YY_BUFFER_STATE libphdi_xml_scanner__scan_buffer(
237
                 char *buffer,
238
                 yy_size_t buffer_size );
239
240
extern \
241
void libphdi_xml_scanner__delete_buffer(
242
      YY_BUFFER_STATE buffer_state );
243
244
extern \
245
size_t libphdi_xml_scanner_buffer_offset;
246
247
static char *libphdi_xml_parser_function = "libphdi_xml_parser";
248
249
int libphdi_xml_parser_parse_buffer(
250
     libphdi_disk_descriptor_xml_file_t *disk_descriptor_xml_file,
251
     uint8_t *buffer,
252
     size_t buffer_size,
253
     libcerror_error_t **error );
254
255
256
/* compatibility with bison */
257
#ifdef YYPARSE_PARAM
258
/* compatibility with FreeBSD */
259
# ifdef YYPARSE_PARAM_TYPE
260
#  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
261
# else
262
#  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
263
# endif
264
#else
265
# define YYPARSE_DECL() yyparse(void * parser_state)
266
#endif
267
268
/* Parameters sent to lex. */
269
#ifdef YYLEX_PARAM
270
# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
271
496k
# define YYLEX yylex(YYLEX_PARAM)
272
#else
273
# define YYLEX_DECL() yylex((void *)  NULL)
274
# define YYLEX yylex(NULL)
275
#endif
276
277
/* Parameters sent to yyerror. */
278
#ifndef YYERROR_DECL
279
#define YYERROR_DECL() yyerror(void * parser_state, const char *s)
280
#endif
281
#ifndef YYERROR_CALL
282
544
#define YYERROR_CALL(msg) yyerror(parser_state, msg)
283
#endif
284
285
extern int YYPARSE_DECL();
286
287
#define XML_ATTRIBUTE_ASSIGN 257
288
#define XML_COMMENT 258
289
#define XML_DOCTYPE 259
290
#define XML_PROLOGUE 260
291
#define XML_TAG_END 261
292
#define XML_TAG_END_SINGLE 262
293
#define XML_UNDEFINED 263
294
#define XML_ATTRIBUTE_NAME 264
295
#define XML_ATTRIBUTE_VALUE 265
296
#define XML_TAG_CLOSE 266
297
#define XML_TAG_CONTENT 267
298
#define XML_TAG_OPEN_START 268
299
204k
#define YYERRCODE 256
300
typedef short YYINT;
301
static const YYINT libphdi_xml_scanner_lhs[] = {         -1,
302
    0,    1,    1,    2,    2,    4,    4,    6,    6,    6,
303
    9,    3,    8,    5,    7,   10,   10,   11,
304
};
305
static const YYINT libphdi_xml_scanner_len[] = {          2,
306
    5,    0,    1,    0,    1,    0,    2,    3,    3,    1,
307
    1,    3,    3,    1,    1,    0,    2,    3,
308
};
309
static const YYINT libphdi_xml_scanner_defred[] = {       0,
310
    3,    0,    0,    5,    0,   11,    0,    0,    0,    0,
311
    0,   10,    0,    0,    0,    0,   15,    0,    0,   14,
312
    1,    7,    0,    0,   12,   17,    8,    9,   13,   18,
313
};
314
static const YYINT libphdi_xml_scanner_dgoto[] = {        2,
315
    3,    5,    9,   10,   21,   11,   19,   12,   13,   15,
316
   16,
317
};
318
static const YYINT libphdi_xml_scanner_sindex[] = {    -258,
319
    0,    0, -243,    0, -260,    0, -260, -247, -261, -248,
320
 -260,    0, -247, -238, -241, -247,    0, -248, -248,    0,
321
    0,    0, -251, -244,    0,    0,    0,    0,    0,    0,
322
};
323
static const YYINT libphdi_xml_scanner_rindex[] = {    -259,
324
    0,    0, -246,    0,    0,    0, -242, -236, -242,    0,
325
 -242,    0, -249,    0,    0, -249,    0,    0,    0,    0,
326
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
327
};
328
static const YYINT libphdi_xml_scanner_gindex[] = {       0,
329
    0,    0,   18,   -6,   -4,    0,    0,    0,   21,  -12,
330
    0,
331
};
332
3.74M
#define YYTABLESIZE 26
333
static const YYINT libphdi_xml_scanner_table[] = {        2,
334
   23,    1,   18,   26,   22,   17,    6,    6,    2,   25,
335
   29,   16,   16,   27,   28,    4,   14,   20,   24,   25,
336
   30,    4,    7,    6,   16,    8,
337
};
338
static const YYINT libphdi_xml_scanner_check[] = {      259,
339
   13,  260,    9,   16,   11,  267,  268,  268,  268,  261,
340
  262,  261,  262,   18,   19,  259,  264,  266,  257,  261,
341
  265,  268,    5,  266,  261,    5,
342
};
343
266
#define YYFINAL 2
344
#ifndef YYDEBUG
345
#define YYDEBUG 0
346
#endif
347
#define YYMAXTOKEN 268
348
#define YYUNDFTOKEN 282
349
#define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
350
#if YYDEBUG
351
static const char *const libphdi_xml_scanner_name[] = {
352
353
"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
354
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
355
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
356
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
357
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
358
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
359
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"XML_ATTRIBUTE_ASSIGN",
360
"XML_COMMENT","XML_DOCTYPE","XML_PROLOGUE","XML_TAG_END","XML_TAG_END_SINGLE",
361
"XML_UNDEFINED","XML_ATTRIBUTE_NAME","XML_ATTRIBUTE_VALUE","XML_TAG_CLOSE",
362
"XML_TAG_CONTENT","XML_TAG_OPEN_START",0,0,0,0,0,0,0,0,0,0,0,0,0,
363
"illegal-symbol",
364
};
365
static const char *const libphdi_xml_scanner_rule[] = {
366
"$accept : xml_plist_main",
367
"xml_plist_main : xml_prologue xml_doctype xml_tag_open xml_tags xml_tag_close",
368
"xml_prologue :",
369
"xml_prologue : XML_PROLOGUE",
370
"xml_doctype :",
371
"xml_doctype : XML_DOCTYPE",
372
"xml_tags :",
373
"xml_tags : xml_tag xml_tags",
374
"xml_tag : xml_tag_open xml_tags xml_tag_close",
375
"xml_tag : xml_tag_open xml_tag_content xml_tag_close",
376
"xml_tag : xml_tag_single",
377
"xml_tag_open_start : XML_TAG_OPEN_START",
378
"xml_tag_open : xml_tag_open_start xml_attributes XML_TAG_END",
379
"xml_tag_single : xml_tag_open_start xml_attributes XML_TAG_END_SINGLE",
380
"xml_tag_close : XML_TAG_CLOSE",
381
"xml_tag_content : XML_TAG_CONTENT",
382
"xml_attributes :",
383
"xml_attributes : xml_attribute xml_attributes",
384
"xml_attribute : XML_ATTRIBUTE_NAME XML_ATTRIBUTE_ASSIGN XML_ATTRIBUTE_VALUE",
385
386
};
387
#endif
388
389
int      yydebug;
390
int      yynerrs;
391
392
int      yyerrflag;
393
int      yychar;
394
YYSTYPE  yyval;
395
YYSTYPE  yylval;
396
397
/* define the initial stack-sizes */
398
#ifdef YYSTACKSIZE
399
#undef YYMAXDEPTH
400
#define YYMAXDEPTH  YYSTACKSIZE
401
#else
402
#ifdef YYMAXDEPTH
403
#define YYSTACKSIZE YYMAXDEPTH
404
#else
405
#define YYSTACKSIZE 10000
406
14
#define YYMAXDEPTH  10000
407
#endif
408
#endif
409
410
1
#define YYINITSTACKSIZE 200
411
412
typedef struct {
413
    unsigned stacksize;
414
    YYINT    *s_base;
415
    YYINT    *s_mark;
416
    YYINT    *s_last;
417
    YYSTYPE  *l_base;
418
    YYSTYPE  *l_mark;
419
} YYSTACKDATA;
420
/* variables for the parser stack */
421
static YYSTACKDATA yystack;
422
423
int libphdi_xml_parser_parse_buffer(
424
     libphdi_disk_descriptor_xml_file_t *disk_descriptor_xml_file,
425
     uint8_t *buffer,
426
     size_t buffer_size,
427
     libcerror_error_t **error )
428
854
{
429
854
  libphdi_xml_parser_state_t parser_state;
430
  
431
854
  YY_BUFFER_STATE buffer_state = NULL;
432
854
  static char *function        = "libphdi_xml_parser_parse_buffer";
433
854
  int result                   = -1;
434
435
854
  buffer_state = libphdi_xml_scanner__scan_buffer(
436
854
                  (char *) buffer,
437
854
                  buffer_size );
438
439
854
  libphdi_xml_scanner_buffer_offset = 0;
440
441
854
  if( buffer_state != NULL )
442
854
  {
443
854
    parser_state.disk_descriptor_xml_file = disk_descriptor_xml_file;
444
854
    parser_state.error                    = error;
445
854
    parser_state.root_tag                 = NULL;
446
854
    parser_state.current_tag              = NULL;
447
854
    parser_state.parent_tag               = NULL;
448
449
854
    if( libphdi_xml_scanner_parse(
450
854
         &parser_state ) == 0 )
451
114
    {
452
114
      if( libphdi_disk_descriptor_xml_file_set_root_tag(
453
114
           disk_descriptor_xml_file,
454
114
           parser_state.root_tag,
455
114
           error ) != 1 )
456
0
      {
457
0
        libcerror_error_set(
458
0
         error,
459
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
460
0
         LIBCERROR_RUNTIME_ERROR_GET_FAILED,
461
0
         "%s: unable to set root tag.",
462
0
         function );
463
464
0
        result = -1;
465
0
      }
466
114
      else
467
114
      {
468
114
        parser_state.root_tag = NULL;
469
470
114
        result = 1;
471
114
      }
472
114
    }
473
854
    libphdi_xml_scanner__delete_buffer(
474
854
     buffer_state );
475
854
  }
476
854
  libphdi_xml_scanner_lex_destroy();
477
478
854
  if( parser_state.root_tag != NULL )
479
576
  {
480
576
    libphdi_xml_tag_free(
481
576
     &( parser_state.root_tag ),
482
576
     NULL );
483
576
  }
484
854
  return( result );
485
854
}
486
487
488
#if YYDEBUG
489
#include <stdio.h>    /* needed for printf */
490
#endif
491
492
#include <stdlib.h> /* needed for malloc, etc */
493
#include <string.h> /* needed for memset */
494
495
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
496
static int yygrowstack(YYSTACKDATA *data)
497
8
{
498
8
    int i;
499
8
    unsigned newsize;
500
8
    YYINT *newss;
501
8
    YYSTYPE *newvs;
502
503
8
    if ((newsize = data->stacksize) == 0)
504
1
        newsize = YYINITSTACKSIZE;
505
7
    else if (newsize >= YYMAXDEPTH)
506
1
        return YYENOMEM;
507
6
    else if ((newsize *= 2) > YYMAXDEPTH)
508
1
        newsize = YYMAXDEPTH;
509
510
7
    i = (int) (data->s_mark - data->s_base);
511
7
    newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
512
7
    if (newss == 0)
513
0
        return YYENOMEM;
514
515
7
    data->s_base = newss;
516
7
    data->s_mark = newss + i;
517
518
7
    newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
519
7
    if (newvs == 0)
520
0
        return YYENOMEM;
521
522
7
    data->l_base = newvs;
523
7
    data->l_mark = newvs + i;
524
525
7
    data->stacksize = newsize;
526
7
    data->s_last = data->s_base + newsize - 1;
527
7
    return 0;
528
7
}
529
530
#if YYPURE || defined(YY_NO_LEAKS)
531
static void yyfreestack(YYSTACKDATA *data)
532
{
533
    free(data->s_base);
534
    free(data->l_base);
535
    memset(data, 0, sizeof(*data));
536
}
537
#else
538
#define yyfreestack(data) /* nothing */
539
#endif
540
541
196
#define YYABORT  goto yyabort
542
#define YYREJECT goto yyabort
543
#define YYACCEPT goto yyaccept
544
#define YYERROR  goto yyerrlab
545
546
int
547
YYPARSE_DECL()
548
854
{
549
854
    int yym, yyn, yystate;
550
#if YYDEBUG
551
    const char *yys;
552
553
    if ((yys = getenv("YYDEBUG")) != 0)
554
    {
555
        yyn = *yys;
556
        if (yyn >= '0' && yyn <= '9')
557
            yydebug = yyn - '0';
558
    }
559
#endif
560
561
854
    yynerrs = 0;
562
854
    yyerrflag = 0;
563
854
    yychar = YYEMPTY;
564
854
    yystate = 0;
565
566
#if YYPURE
567
    memset(&yystack, 0, sizeof(yystack));
568
#endif
569
570
854
    if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
571
854
    yystack.s_mark = yystack.s_base;
572
854
    yystack.l_mark = yystack.l_base;
573
854
    yystate = 0;
574
854
    *yystack.s_mark = 0;
575
576
1.37M
yyloop:
577
1.37M
    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
578
744k
    if (yychar < 0)
579
496k
    {
580
496k
        if ((yychar = YYLEX) < 0) yychar = YYEOF;
581
#if YYDEBUG
582
        if (yydebug)
583
        {
584
            yys = yyname[YYTRANSLATE(yychar)];
585
            printf("%sdebug: state %d, reading %d (%s)\n",
586
                    YYPREFIX, yystate, yychar, yys);
587
        }
588
#endif
589
496k
    }
590
744k
    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
591
743k
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
592
495k
    {
593
#if YYDEBUG
594
        if (yydebug)
595
            printf("%sdebug: state %d, shifting to state %d\n",
596
                    YYPREFIX, yystate, yytable[yyn]);
597
#endif
598
495k
        if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
599
1
        {
600
1
            goto yyoverflow;
601
1
        }
602
495k
        yystate = yytable[yyn];
603
495k
        *++yystack.s_mark = yytable[yyn];
604
495k
        *++yystack.l_mark = yylval;
605
495k
        yychar = YYEMPTY;
606
495k
        if (yyerrflag > 0)  --yyerrflag;
607
495k
        goto yyloop;
608
495k
    }
609
248k
    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
610
248k
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
611
248k
    {
612
248k
        yyn = yytable[yyn];
613
248k
        goto yyreduce;
614
248k
    }
615
543
    if (yyerrflag) goto yyinrecovery;
616
617
543
    YYERROR_CALL("syntax error");
618
619
543
    goto yyerrlab;
620
621
543
yyerrlab:
622
543
    ++yynerrs;
623
624
543
yyinrecovery:
625
543
    if (yyerrflag < 3)
626
543
    {
627
543
        yyerrflag = 3;
628
543
        for (;;)
629
202k
        {
630
202k
            if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
631
1.33k
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
632
0
            {
633
#if YYDEBUG
634
                if (yydebug)
635
                    printf("%sdebug: state %d, error recovery shifting\
636
 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
637
#endif
638
0
                if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
639
0
                {
640
0
                    goto yyoverflow;
641
0
                }
642
0
                yystate = yytable[yyn];
643
0
                *++yystack.s_mark = yytable[yyn];
644
0
                *++yystack.l_mark = yylval;
645
0
                goto yyloop;
646
0
            }
647
202k
            else
648
202k
            {
649
#if YYDEBUG
650
                if (yydebug)
651
                    printf("%sdebug: error recovery discarding state %d\n",
652
                            YYPREFIX, *yystack.s_mark);
653
#endif
654
202k
                if (yystack.s_mark <= yystack.s_base) goto yyabort;
655
202k
                --yystack.s_mark;
656
202k
                --yystack.l_mark;
657
202k
            }
658
202k
        }
659
543
    }
660
0
    else
661
0
    {
662
0
        if (yychar == YYEOF) goto yyabort;
663
#if YYDEBUG
664
        if (yydebug)
665
        {
666
            yys = yyname[YYTRANSLATE(yychar)];
667
            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
668
                    YYPREFIX, yystate, yychar, yys);
669
        }
670
#endif
671
0
        yychar = YYEMPTY;
672
0
        goto yyloop;
673
0
    }
674
675
880k
yyreduce:
676
#if YYDEBUG
677
    if (yydebug)
678
        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
679
                YYPREFIX, yystate, yyn, yyrule[yyn]);
680
#endif
681
880k
    yym = yylen[yyn];
682
880k
    if (yym)
683
632k
        yyval = yystack.l_mark[1-yym];
684
248k
    else
685
248k
        memset(&yyval, 0, sizeof yyval);
686
880k
    switch (yyn)
687
880k
    {
688
245k
case 11:
689
245k
  {
690
245k
    libphdi_xml_parser_rule_print(
691
245k
     "xml_tag_open_start" );
692
693
245k
    if( yystack.l_mark[0].string_value.data == NULL )
694
0
    {
695
0
      libcerror_error_set(
696
0
       ( (libphdi_xml_parser_state_t *) parser_state )->error,
697
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
698
0
       LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
699
0
       "%s: invalid tag name.",
700
0
       libphdi_xml_parser_function );
701
702
0
      YYABORT;
703
0
    }
704
245k
    ( (libphdi_xml_parser_state_t *) parser_state )->current_tag = NULL;
705
706
245k
    if( libphdi_xml_tag_initialize(
707
245k
         &( ( (libphdi_xml_parser_state_t *) parser_state )->current_tag ),
708
245k
         (uint8_t *) yystack.l_mark[0].string_value.data,
709
245k
         yystack.l_mark[0].string_value.length,
710
245k
         ( (libphdi_xml_parser_state_t *) parser_state )->error ) != 1 )
711
0
    {
712
0
      libcerror_error_set(
713
0
       ( (libphdi_xml_parser_state_t *) parser_state )->error,
714
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
715
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
716
0
       "%s: unable to create XML tag.",
717
0
       libphdi_xml_parser_function );
718
719
0
      YYABORT;
720
0
    }
721
245k
    if( ( (libphdi_xml_parser_state_t *) parser_state )->root_tag == NULL )
722
690
    {
723
690
      ( (libphdi_xml_parser_state_t *) parser_state )->root_tag = ( (libphdi_xml_parser_state_t *) parser_state )->current_tag;
724
690
    }
725
245k
    else
726
245k
    {
727
245k
      if( libphdi_xml_tag_append_element(
728
245k
           ( (libphdi_xml_parser_state_t *) parser_state )->parent_tag,
729
245k
           ( (libphdi_xml_parser_state_t *) parser_state )->current_tag,
730
245k
           ( (libphdi_xml_parser_state_t *) parser_state )->error ) != 1 )
731
0
      {
732
0
        libcerror_error_set(
733
0
         ( (libphdi_xml_parser_state_t *) parser_state )->error,
734
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
735
0
         LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
736
0
         "%s: unable to append attribute.",
737
0
         libphdi_xml_parser_function );
738
739
0
        YYABORT;
740
0
      }
741
245k
    }
742
245k
    ( (libphdi_xml_parser_state_t *) parser_state )->parent_tag = ( (libphdi_xml_parser_state_t *) parser_state )->current_tag;
743
245k
  }
744
0
break;
745
102k
case 13:
746
102k
  {
747
102k
    libphdi_xml_parser_rule_print(
748
102k
     "xml_tag_single" );
749
750
102k
    if( ( (libphdi_xml_parser_state_t *) parser_state )->current_tag == NULL )
751
0
    {
752
0
      libcerror_error_set(
753
0
       ( (libphdi_xml_parser_state_t *) parser_state )->error,
754
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
755
0
       LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
756
0
       "%s: invalid current tag.",
757
0
       libphdi_xml_parser_function );
758
759
0
      YYABORT;
760
0
    }
761
102k
    ( (libphdi_xml_parser_state_t *) parser_state )->parent_tag  = ( (libphdi_xml_parser_state_t *) parser_state )->current_tag->parent_tag;
762
102k
    ( (libphdi_xml_parser_state_t *) parser_state )->current_tag = ( (libphdi_xml_parser_state_t *) parser_state )->parent_tag;
763
102k
  }
764
0
break;
765
1.31k
case 14:
766
1.31k
  {
767
1.31k
    libphdi_xml_parser_rule_print(
768
1.31k
     "xml_tag_close" );
769
770
1.31k
    if( yystack.l_mark[0].string_value.data == NULL )
771
0
    {
772
0
      libcerror_error_set(
773
0
       ( (libphdi_xml_parser_state_t *) parser_state )->error,
774
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
775
0
       LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
776
0
       "%s: invalid tag name.",
777
0
       libphdi_xml_parser_function );
778
779
0
      YYABORT;
780
0
    }
781
1.31k
    if( ( (libphdi_xml_parser_state_t *) parser_state )->current_tag == NULL )
782
0
    {
783
0
      libcerror_error_set(
784
0
       ( (libphdi_xml_parser_state_t *) parser_state )->error,
785
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
786
0
       LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
787
0
       "%s: invalid current tag.",
788
0
       libphdi_xml_parser_function );
789
790
0
      YYABORT;
791
0
    }
792
1.31k
    if( ( ( (libphdi_xml_parser_state_t *) parser_state )->current_tag->name_size != ( yystack.l_mark[0].string_value.length + 1 ) )
793
1.29k
     || ( narrow_string_compare(
794
1.29k
           ( (libphdi_xml_parser_state_t *) parser_state )->current_tag->name,
795
1.29k
           yystack.l_mark[0].string_value.data,
796
1.29k
           yystack.l_mark[0].string_value.length ) != 0 ) )
797
182
    {
798
182
      libcerror_error_set(
799
182
       ( (libphdi_xml_parser_state_t *) parser_state )->error,
800
182
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
801
182
       LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
802
182
       "%s: mismatch in tag name (%s != %s).",
803
182
       libphdi_xml_parser_function,
804
182
       ( (libphdi_xml_parser_state_t *) parser_state )->current_tag->name,
805
182
       yystack.l_mark[0].string_value.data );
806
807
182
      YYABORT;
808
182
    }
809
1.13k
    ( (libphdi_xml_parser_state_t *) parser_state )->parent_tag  = ( (libphdi_xml_parser_state_t *) parser_state )->current_tag->parent_tag;
810
1.13k
    ( (libphdi_xml_parser_state_t *) parser_state )->current_tag = ( (libphdi_xml_parser_state_t *) parser_state )->parent_tag;
811
1.13k
  }
812
0
break;
813
415
case 15:
814
415
  {
815
415
    libphdi_xml_parser_rule_print(
816
415
     "xml_tag_content" );
817
818
415
    if( yystack.l_mark[0].string_value.data == NULL )
819
0
    {
820
0
      libcerror_error_set(
821
0
       ( (libphdi_xml_parser_state_t *) parser_state )->error,
822
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
823
0
       LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
824
0
       "%s: invalid attribute value.",
825
0
       libphdi_xml_parser_function );
826
827
0
      YYABORT;
828
0
    }
829
415
    if( libphdi_xml_tag_set_value(
830
415
         ( (libphdi_xml_parser_state_t *) parser_state )->current_tag,
831
415
         (uint8_t *) yystack.l_mark[0].string_value.data,
832
415
         yystack.l_mark[0].string_value.length,
833
415
         ( (libphdi_xml_parser_state_t *) parser_state )->error ) != 1 )
834
0
    {
835
0
      libcerror_error_set(
836
0
       ( (libphdi_xml_parser_state_t *) parser_state )->error,
837
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
838
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
839
0
       "%s: unable to set value.",
840
0
       libphdi_xml_parser_function );
841
842
0
      YYABORT;
843
0
    }
844
415
  }
845
415
break;
846
694
case 18:
847
694
  {
848
694
    libphdi_xml_parser_rule_print(
849
694
     "xml_attribute" );
850
851
694
    if( yystack.l_mark[-2].string_value.data == NULL )
852
0
    {
853
0
      libcerror_error_set(
854
0
       ( (libphdi_xml_parser_state_t *) parser_state )->error,
855
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
856
0
       LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
857
0
       "%s: invalid attribute name.",
858
0
       libphdi_xml_parser_function );
859
860
0
      YYABORT;
861
0
    }
862
694
    if( yystack.l_mark[0].string_value.data == NULL )
863
0
    {
864
0
      libcerror_error_set(
865
0
       ( (libphdi_xml_parser_state_t *) parser_state )->error,
866
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
867
0
       LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
868
0
       "%s: invalid attribute value.",
869
0
       libphdi_xml_parser_function );
870
871
0
      YYABORT;
872
0
    }
873
694
    if( libphdi_xml_tag_append_attribute(
874
694
         ( (libphdi_xml_parser_state_t *) parser_state )->current_tag,
875
694
         (uint8_t *) yystack.l_mark[-2].string_value.data,
876
694
         yystack.l_mark[-2].string_value.length,
877
694
         (uint8_t *) yystack.l_mark[0].string_value.data,
878
694
         yystack.l_mark[0].string_value.length,
879
694
         ( (libphdi_xml_parser_state_t *) parser_state )->error ) != 1 )
880
14
    {
881
14
      libcerror_error_set(
882
14
       ( (libphdi_xml_parser_state_t *) parser_state )->error,
883
14
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
884
14
       LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
885
14
       "%s: unable to append attribute.",
886
14
       libphdi_xml_parser_function );
887
888
14
      YYABORT;
889
14
    }
890
694
  }
891
680
break;
892
880k
    }
893
880k
    yystack.s_mark -= yym;
894
880k
    yystate = *yystack.s_mark;
895
880k
    yystack.l_mark -= yym;
896
880k
    yym = yylhs[yyn];
897
880k
    if (yystate == 0 && yym == 0)
898
133
    {
899
#if YYDEBUG
900
        if (yydebug)
901
            printf("%sdebug: after reduction, shifting from state 0 to\
902
 state %d\n", YYPREFIX, YYFINAL);
903
#endif
904
133
        yystate = YYFINAL;
905
133
        *++yystack.s_mark = YYFINAL;
906
133
        *++yystack.l_mark = yyval;
907
133
        if (yychar < 0)
908
133
        {
909
133
            if ((yychar = YYLEX) < 0) yychar = YYEOF;
910
#if YYDEBUG
911
            if (yydebug)
912
            {
913
                yys = yyname[YYTRANSLATE(yychar)];
914
                printf("%sdebug: state %d, reading %d (%s)\n",
915
                        YYPREFIX, YYFINAL, yychar, yys);
916
            }
917
#endif
918
133
        }
919
133
        if (yychar == YYEOF) goto yyaccept;
920
19
        goto yyloop;
921
133
    }
922
880k
    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
923
671k
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
924
282k
        yystate = yytable[yyn];
925
597k
    else
926
597k
        yystate = yydgoto[yym];
927
#if YYDEBUG
928
    if (yydebug)
929
        printf("%sdebug: after reduction, shifting from state %d \
930
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
931
#endif
932
880k
    if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
933
0
    {
934
0
        goto yyoverflow;
935
0
    }
936
880k
    *++yystack.s_mark = (YYINT) yystate;
937
880k
    *++yystack.l_mark = yyval;
938
880k
    goto yyloop;
939
940
1
yyoverflow:
941
1
    YYERROR_CALL("yacc stack overflow");
942
943
740
yyabort:
944
740
    yyfreestack(&yystack);
945
740
    return (1);
946
947
114
yyaccept:
948
114
    yyfreestack(&yystack);
949
114
    return (0);
950
1
}