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

Comparing Convert-BER-XS/XS.xs (file contents):
Revision 1.21 by root, Sat Apr 20 17:23:21 2019 UTC vs.
Revision 1.24 by root, Sun Apr 21 01:58:15 2019 UTC

260 if (expect_false (c == 0x80)) 260 if (expect_false (c == 0x80))
261 error ("illegal BER padding (X.690 8.1.2.4.2, 8.19.2)"); 261 error ("illegal BER padding (X.690 8.1.2.4.2, 8.19.2)");
262 262
263 for (;;) 263 for (;;)
264 { 264 {
265 if (expect_false (res >> UVSIZE * 8 - 7))
266 error ("BER variable integer overflow");
267
265 res = (res << 7) | (c & 0x7f); 268 res = (res << 7) | (c & 0x7f);
266 269
267 if (!(c & 0x80)) 270 if (!(c & 0x80))
268 return res; 271 return res;
269 272
326 329
327 int negative = data [0] & 0x80; 330 int negative = data [0] & 0x80;
328 331
329 UV val = negative ? -1 : 0; // copy signbit to all bits 332 UV val = negative ? -1 : 0; // copy signbit to all bits
330 333
334 if (len > UVSIZE + (!negative && !*data))
335 error ("INTEGER overflow");
336
331 do 337 do
332 val = (val << 8) | *data++; 338 val = (val << 8) | *data++;
333 while (--len); 339 while (--len);
334 340
335 // the cast to IV relies on implementation-defined behaviour (two's complement cast) 341 // the cast to IV relies on implementation-defined behaviour (two's complement cast)
389 } 395 }
390 396
391 U8 *end = cur + len; 397 U8 *end = cur + len;
392 UV w = get_w (); 398 UV w = get_w ();
393 399
394 static char oid[MAX_OID_STRLEN]; // static, becaueds too large for stack 400 static char oid[MAX_OID_STRLEN]; // static, because too large for stack
395 char *app = oid; 401 char *app = oid;
396 402
397 if (relative) 403 if (relative)
398 app = write_uv (app, w); 404 app = write_uv (app, w);
399 else if (w < 2 * 40) 405 else if (w < 2 * 40)
1081 1087
1082 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 1088 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
1083 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 1089 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
1084} 1090}
1085 1091
1086SV * 1092void
1087ber_decode (SV *ber, SV *profile = &PL_sv_undef) 1093ber_decode (SV *ber, SV *profile = &PL_sv_undef)
1094 ALIAS:
1095 ber_decode_prefix = 1
1088 CODE: 1096 PPCODE:
1089{ 1097{
1090 cur_profile = SvPROFILE (profile); 1098 cur_profile = SvPROFILE (profile);
1091 STRLEN len; 1099 STRLEN len;
1092 buf = (U8 *)SvPVbyte (ber, len); 1100 buf = (U8 *)SvPVbyte (ber, len);
1093 cur = buf; 1101 cur = buf;
1094 end = buf + len; 1102 end = buf + len;
1095 1103
1096 RETVAL = decode_ber (); 1104 SV *tuple = decode_ber ();
1105
1106 EXTEND (SP, 2);
1107 PUSHs (sv_2mortal (tuple));
1108
1109 if (ix)
1110 PUSHs (sv_2mortal (newSViv (cur - buf)));
1111 else if (cur != end)
1112 error ("trailing garbage after BER data");
1097} 1113}
1098 OUTPUT: RETVAL
1099 1114
1100void 1115void
1101ber_is (SV *tuple, SV *klass = &PL_sv_undef, SV *tag = &PL_sv_undef, SV *flags = &PL_sv_undef, SV *data = &PL_sv_undef) 1116ber_is (SV *tuple, SV *klass = &PL_sv_undef, SV *tag = &PL_sv_undef, SV *flags = &PL_sv_undef, SV *data = &PL_sv_undef)
1102 PPCODE: 1117 PPCODE:
1103{ 1118{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines