ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/XS.xs
(Generate patch)

Comparing CBOR-XS/XS.xs (file contents):
Revision 1.63 by root, Sat Nov 26 04:50:58 2016 UTC vs.
Revision 1.65 by root, Thu Nov 15 19:52:41 2018 UTC

510 else if ((method = gv_fetchmethod_autoload (stash, "FREEZE", 0)) != 0) 510 else if ((method = gv_fetchmethod_autoload (stash, "FREEZE", 0)) != 0)
511 { 511 {
512 dSP; 512 dSP;
513 513
514 ENTER; SAVETMPS; 514 ENTER; SAVETMPS;
515 SAVESTACK_POS ();
516 PUSHMARK (SP); 515 PUSHMARK (SP);
517 EXTEND (SP, 2); 516 EXTEND (SP, 2);
518 // we re-bless the reference to get overload and other niceties right 517 // we re-bless the reference to get overload and other niceties right
519 PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); 518 PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash));
520 PUSHs (sv_cbor); 519 PUSHs (sv_cbor);
529 528
530 encode_tag (enc, CBOR_TAG_PERL_OBJECT); 529 encode_tag (enc, CBOR_TAG_PERL_OBJECT);
531 encode_uint (enc, MAJOR_ARRAY, count + 1); 530 encode_uint (enc, MAJOR_ARRAY, count + 1);
532 encode_strref (enc, 0, HvNAMEUTF8 (stash), HvNAME (stash), HvNAMELEN (stash)); 531 encode_strref (enc, 0, HvNAMEUTF8 (stash), HvNAME (stash), HvNAMELEN (stash));
533 532
534 while (count) 533 {
534 int i;
535
536 for (i = 0; i < count; ++i)
535 encode_sv (enc, SP[1 - count--]); 537 encode_sv (enc, SP[i + 1 - count]);
538
539 SP -= count;
540 }
536 541
537 PUTBACK; 542 PUTBACK;
538 543
539 FREETMPS; LEAVE; 544 FREETMPS; LEAVE;
540 } 545 }
780 785
781 for (;;) 786 for (;;)
782 { 787 {
783 WANT (1); 788 WANT (1);
784 789
785 if (*dec->cur == (MAJOR_MISC | MINOR_INDEF)) 790 if (*dec->cur == (MAJOR_MISC | MINOR_INDEF) || dec->err)
786 { 791 {
787 ++dec->cur; 792 ++dec->cur;
788 break; 793 break;
789 } 794 }
790 795
898 903
899 for (;;) 904 for (;;)
900 { 905 {
901 WANT (1); 906 WANT (1);
902 907
903 if (*dec->cur == (MAJOR_MISC | MINOR_INDEF)) 908 if (*dec->cur == (MAJOR_MISC | MINOR_INDEF) || dec->err)
904 { 909 {
905 ++dec->cur; 910 ++dec->cur;
906 break; 911 break;
907 } 912 }
908 913
1029 if ((*dec->cur >> MAJOR_SHIFT) != (MAJOR_POS_INT >> MAJOR_SHIFT)) 1034 if ((*dec->cur >> MAJOR_SHIFT) != (MAJOR_POS_INT >> MAJOR_SHIFT))
1030 ERR ("corrupted CBOR data (stringref index not an unsigned integer)"); 1035 ERR ("corrupted CBOR data (stringref index not an unsigned integer)");
1031 1036
1032 UV idx = decode_uint (dec); 1037 UV idx = decode_uint (dec);
1033 1038
1034 if (!dec->stringref || (int)idx > AvFILLp (dec->stringref)) 1039 if (!dec->stringref || idx >= (UV)(1 + AvFILLp (dec->stringref)))
1035 ERR ("corrupted CBOR data (stringref index out of bounds or outside namespace)"); 1040 ERR ("corrupted CBOR data (stringref index out of bounds or outside namespace)");
1036 1041
1037 sv = newSVsv (AvARRAY (dec->stringref)[idx]); 1042 sv = newSVsv (AvARRAY (dec->stringref)[idx]);
1038 } 1043 }
1039 break; 1044 break;
1067 if ((*dec->cur >> MAJOR_SHIFT) != (MAJOR_POS_INT >> MAJOR_SHIFT)) 1072 if ((*dec->cur >> MAJOR_SHIFT) != (MAJOR_POS_INT >> MAJOR_SHIFT))
1068 ERR ("corrupted CBOR data (sharedref index not an unsigned integer)"); 1073 ERR ("corrupted CBOR data (sharedref index not an unsigned integer)");
1069 1074
1070 UV idx = decode_uint (dec); 1075 UV idx = decode_uint (dec);
1071 1076
1072 if (!dec->shareable || (int)idx > AvFILLp (dec->shareable)) 1077 if (!dec->shareable || idx >= (UV)(1 + AvFILLp (dec->shareable)))
1073 ERR ("corrupted CBOR data (sharedref index out of bounds)"); 1078 ERR ("corrupted CBOR data (sharedref index out of bounds)");
1074 1079
1075 sv = SvREFCNT_inc_NN (AvARRAY (dec->shareable)[idx]); 1080 sv = SvREFCNT_inc_NN (AvARRAY (dec->shareable)[idx]);
1076 1081
1077 if (sv == &PL_sv_undef) 1082 if (sv == &PL_sv_undef)
1141 1146
1142 sv = decode_sv (dec); 1147 sv = decode_sv (dec);
1143 1148
1144 dSP; 1149 dSP;
1145 ENTER; SAVETMPS; 1150 ENTER; SAVETMPS;
1146 SAVESTACK_POS ();
1147 PUSHMARK (SP); 1151 PUSHMARK (SP);
1148 EXTEND (SP, 2); 1152 EXTEND (SP, 2);
1149 PUSHs (tag_sv); 1153 PUSHs (tag_sv);
1150 PUSHs (sv); 1154 PUSHs (sv);
1151 1155
1162 1166
1163 if (count) 1167 if (count)
1164 { 1168 {
1165 SvREFCNT_dec_NN (tag_sv); 1169 SvREFCNT_dec_NN (tag_sv);
1166 SvREFCNT_dec_NN (sv); 1170 SvREFCNT_dec_NN (sv);
1167 sv = SvREFCNT_inc_NN (POPs); 1171 sv = SvREFCNT_inc_NN (TOPs);
1172 SP -= count;
1168 } 1173 }
1169 else 1174 else
1170 { 1175 {
1171 AV *av = newAV (); 1176 AV *av = newAV ();
1172 av_push (av, tag_sv); 1177 av_push (av, tag_sv);
1668 cbor_init (&cbor); 1673 cbor_init (&cbor);
1669 PUTBACK; cborstr = decode_cbor (cborstr, &cbor, 0); SPAGAIN; 1674 PUTBACK; cborstr = decode_cbor (cborstr, &cbor, 0); SPAGAIN;
1670 XPUSHs (cborstr); 1675 XPUSHs (cborstr);
1671} 1676}
1672 1677
1678#ifdef __AFL_COMPILER
1679
1680void
1681afl_init ()
1682 CODE:
1683 __AFL_INIT ();
1684
1685int
1686afl_loop (unsigned int count = 10000)
1687 CODE:
1688 RETVAL = __AFL_LOOP (count);
1689 OUTPUT:
1690 RETVAL
1691
1692#endif
1693

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines