@@ -467,23 +467,17 @@ yajl_start_map(void *ctx)
467
467
{
468
468
yajl_ctx_t * s_ctx = (yajl_ctx_t * )ctx ;
469
469
470
- if (unlikely (s_ctx -> stage != PARAMS ))
471
- return 1 ;
472
-
473
470
stack_grow_array (s_ctx );
474
471
475
- bool r = false;
476
- if (unlikely (s_ctx -> size == 0 ))
477
- /**/
478
- r = stack_push (s_ctx , s_ctx -> tp .p , TYPE_MAP | PARAMS );
479
- else
480
- r = stack_push (s_ctx , s_ctx -> tp .p , TYPE_MAP );
481
-
472
+ bool r = stack_push (s_ctx , s_ctx -> tp .p , TYPE_MAP );
482
473
if (unlikely (!r )) {
483
474
say_error (s_ctx , -32603 , "[BUG?] 'stack' overflow" );
484
475
return 0 ;
485
476
}
486
477
478
+ if (unlikely (s_ctx -> stage != PARAMS ))
479
+ return 1 ;
480
+
487
481
if (unlikely (s_ctx -> tp .e < s_ctx -> tp .p + 1 + sizeof (uint32_t )))
488
482
say_overflow_r_2 (s_ctx );
489
483
@@ -498,8 +492,8 @@ yajl_end_map(void *ctx)
498
492
{
499
493
yajl_ctx_t * s_ctx = (yajl_ctx_t * )ctx ;
500
494
501
- if ( s_ctx -> size == 0 ) {
502
-
495
+ stack_item_t * item = stack_pop ( s_ctx );
496
+ if ( item != NULL && s_ctx -> size == 0 ) {
503
497
if (!(s_ctx -> been_stages & PARAMS )) {
504
498
dd ("ADDING EMPTY PARAMS\n" );
505
499
@@ -523,19 +517,21 @@ yajl_end_map(void *ctx)
523
517
if (unlikely (s_ctx -> stage != PARAMS ))
524
518
return 1 ;
525
519
526
- stack_item_t * item = stack_pop (s_ctx );
527
520
if (likely (item != NULL )) {
528
-
529
521
dd ("map close, count %d '}'\n" , (int )item -> count );
530
522
531
- if (unlikely (item -> type & PARAMS )) {
532
- say_wrong_params (s_ctx );
533
- return 0 ;
534
- }
523
+ /*
524
+ * A map instead of an array as "params" value.
525
+ *
526
+ * {<...>, "params": {<...>}}
527
+ */
528
+ if (unlikely (s_ctx -> size == 1 )) {
529
+ say_wrong_params (s_ctx );
530
+ return 0 ;
531
+ }
535
532
536
533
* (item -> ptr ++ ) = 0xdf ;
537
534
* (uint32_t * ) item -> ptr = mp_bswap_u32 (item -> count );
538
-
539
535
} else {
540
536
say_wrong_params (s_ctx );
541
537
return 0 ;
@@ -550,30 +546,36 @@ yajl_start_array(void *ctx)
550
546
{
551
547
yajl_ctx_t * s_ctx = (yajl_ctx_t * )ctx ;
552
548
549
+ /*
550
+ * Don't store a stack item for 'batching' array. This way we
551
+ * unify processing of both cases: when this array is present
552
+ * and when it does not.
553
+ *
554
+ * 1. {"method": <...>, "params": <...>, "id": <...>, <...>}
555
+ * 2. [
556
+ * {"method": <...>, "params": <...>, "id": <...>, <...>},
557
+ * {<...>}
558
+ * ]
559
+ *
560
+ * All other arrays and maps are tracked in the stack.
561
+ */
553
562
if (s_ctx -> stage == INIT ) {
554
563
s_ctx -> batch_mode_on = true;
555
564
return 1 ;
556
565
}
557
566
558
- if (unlikely (s_ctx -> stage != PARAMS ))
559
- return 1 ;
560
-
561
567
dd ("array open '['\n" );
562
-
563
568
stack_grow_array (s_ctx );
564
569
565
- bool push_ok = false, bind_first_argument = false;
566
- if (unlikely (s_ctx -> size == 0 )) {
567
- push_ok = stack_push (s_ctx , s_ctx -> tp .p , TYPE_ARRAY | PARAMS );
568
- bind_first_argument = true;
569
- } else
570
- push_ok = stack_push (s_ctx , s_ctx -> tp .p , TYPE_ARRAY );
571
-
570
+ bool push_ok = stack_push (s_ctx , s_ctx -> tp .p , TYPE_ARRAY );
572
571
if (unlikely (!push_ok )) {
573
572
say_error (s_ctx , -32603 , "[BUG?] 'stack' overflow" );
574
573
return 0 ;
575
574
}
576
575
576
+ if (unlikely (s_ctx -> stage != PARAMS ))
577
+ return 1 ;
578
+
577
579
if (unlikely (s_ctx -> tp .e < (s_ctx -> tp .p + 1 + sizeof (uint32_t ))))
578
580
say_overflow_r_2 (s_ctx );
579
581
@@ -582,7 +584,7 @@ yajl_start_array(void *ctx)
582
584
// Here is bind data
583
585
// e.g. http request
584
586
// [
585
- if (bind_first_argument ) {
587
+ if (s_ctx -> size == 2 ) {
586
588
if (unlikely (!bind_data (s_ctx )))
587
589
say_overflow_r_2 (s_ctx );
588
590
}
@@ -596,16 +598,22 @@ yajl_end_array(void *ctx)
596
598
{
597
599
yajl_ctx_t * s_ctx = (yajl_ctx_t * )ctx ;
598
600
601
+ stack_item_t * item = stack_pop (s_ctx );
602
+
599
603
if (unlikely (s_ctx -> stage != PARAMS ))
600
604
return 1 ;
601
605
602
- stack_item_t * item = stack_pop (s_ctx );
603
606
if (likely (item != NULL )) {
604
-
605
607
dd ("array close, count %d ']'\n" , item -> count );
606
608
607
609
size_t item_count = item -> count ;
608
- if (unlikely (item -> type & PARAMS )) {
610
+
611
+ /*
612
+ * An end of "params" array.
613
+ *
614
+ * {<...>, "params": [<...>]}.
615
+ */
616
+ if (unlikely (s_ctx -> size == 1 )) {
609
617
dd ("PARAMS END\n" );
610
618
s_ctx -> stage = WAIT_NEXT ;
611
619
s_ctx -> been_stages |= PARAMS ;
0 commit comments