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.23 by root, Sun Apr 21 01:51:12 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 //printf ("len %d > %d + (!%d && !%d) = %d\n", len, UVSIZE, negative, *data, UVSIZE + (!negative && !*data));//D
336 error ("INTEGER overflow");
337
331 do 338 do
332 val = (val << 8) | *data++; 339 val = (val << 8) | *data++;
333 while (--len); 340 while (--len);
334 341
335 // the cast to IV relies on implementation-defined behaviour (two's complement cast) 342 // the cast to IV relies on implementation-defined behaviour (two's complement cast)
389 } 396 }
390 397
391 U8 *end = cur + len; 398 U8 *end = cur + len;
392 UV w = get_w (); 399 UV w = get_w ();
393 400
394 static char oid[MAX_OID_STRLEN]; // static, becaueds too large for stack 401 static char oid[MAX_OID_STRLEN]; // static, because too large for stack
395 char *app = oid; 402 char *app = oid;
396 403
397 if (relative) 404 if (relative)
398 app = write_uv (app, w); 405 app = write_uv (app, w);
399 else if (w < 2 * 40) 406 else if (w < 2 * 40)
1081 1088
1082 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 1089 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)); 1090 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
1084} 1091}
1085 1092
1086SV * 1093void
1087ber_decode (SV *ber, SV *profile = &PL_sv_undef) 1094ber_decode (SV *ber, SV *profile = &PL_sv_undef)
1095 ALIAS:
1096 ber_decode_prefix = 1
1088 CODE: 1097 PPCODE:
1089{ 1098{
1090 cur_profile = SvPROFILE (profile); 1099 cur_profile = SvPROFILE (profile);
1091 STRLEN len; 1100 STRLEN len;
1092 buf = (U8 *)SvPVbyte (ber, len); 1101 buf = (U8 *)SvPVbyte (ber, len);
1093 cur = buf; 1102 cur = buf;
1094 end = buf + len; 1103 end = buf + len;
1095 1104
1096 RETVAL = decode_ber (); 1105 SV *tuple = decode_ber ();
1106
1107 EXTEND (SP, 2);
1108 PUSHs (sv_2mortal (tuple));
1109
1110 if (ix)
1111 PUSHs (sv_2mortal (newSViv (cur - buf)));
1112 else if (cur != end)
1113 error ("trailing garbage after BER data");
1097} 1114}
1098 OUTPUT: RETVAL
1099 1115
1100void 1116void
1101ber_is (SV *tuple, SV *klass = &PL_sv_undef, SV *tag = &PL_sv_undef, SV *flags = &PL_sv_undef, SV *data = &PL_sv_undef) 1117ber_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: 1118 PPCODE:
1103{ 1119{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines