… | |
… | |
54 | |
54 | |
55 | #define ENABLE_PERL_FRILLS 1 |
55 | #define ENABLE_PERL_FRILLS 1 |
56 | |
56 | |
57 | ///////////////////////////////////////////////////////////////////////////// |
57 | ///////////////////////////////////////////////////////////////////////////// |
58 | |
58 | |
59 | static SV * |
|
|
60 | taint (SV *sv) |
|
|
61 | { |
|
|
62 | SvTAINT (sv); |
|
|
63 | return sv; |
|
|
64 | } |
|
|
65 | |
|
|
66 | static SV * |
|
|
67 | taint_if (SV *sv, SV *src) |
|
|
68 | { |
|
|
69 | if (SvTAINTED (src)) |
|
|
70 | SvTAINT (sv); |
|
|
71 | |
|
|
72 | return sv; |
|
|
73 | } |
|
|
74 | |
|
|
75 | static wchar_t * |
59 | static wchar_t * |
76 | sv2wcs (SV *sv) |
60 | sv2wcs (SV *sv) |
77 | { |
61 | { |
78 | STRLEN len; |
62 | STRLEN len; |
79 | char *str = SvPVutf8 (sv, len); |
63 | char *str = SvPVutf8 (sv, len); |
… | |
… | |
418 | perl_environ = rxvt_environ; |
402 | perl_environ = rxvt_environ; |
419 | swap (perl_environ, environ); |
403 | swap (perl_environ, environ); |
420 | |
404 | |
421 | char *argv[] = { |
405 | char *argv[] = { |
422 | "", |
406 | "", |
423 | "-T", |
|
|
424 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
407 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
425 | }; |
408 | }; |
426 | |
409 | |
427 | perl = perl_alloc (); |
410 | perl = perl_alloc (); |
428 | perl_construct (perl); |
411 | perl_construct (perl); |
429 | |
412 | |
430 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
413 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
431 | || perl_run (perl)) |
414 | || perl_run (perl)) |
432 | { |
415 | { |
433 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
416 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
434 | |
417 | |
435 | perl_destruct (perl); |
418 | perl_destruct (perl); |
… | |
… | |
440 | swap (perl_environ, environ); |
423 | swap (perl_environ, environ); |
441 | |
424 | |
442 | rxvt_pop_locale (); |
425 | rxvt_pop_locale (); |
443 | } |
426 | } |
444 | |
427 | |
|
|
428 | if (perl) |
|
|
429 | { |
445 | // runs outside of perls ENV |
430 | // runs outside of perls ENV |
446 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
431 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
447 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
432 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
|
|
433 | } |
448 | } |
434 | } |
449 | |
435 | |
450 | static void |
436 | static void |
451 | ungrab (rxvt_term *THIS) |
437 | ungrab (rxvt_term *THIS) |
452 | { |
438 | { |
… | |
… | |
515 | case DT_LONG: |
501 | case DT_LONG: |
516 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
502 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
517 | break; |
503 | break; |
518 | |
504 | |
519 | case DT_STR: |
505 | case DT_STR: |
520 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
506 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
521 | break; |
507 | break; |
522 | |
508 | |
523 | case DT_STR_LEN: |
509 | case DT_STR_LEN: |
524 | { |
510 | { |
525 | char *str = va_arg (ap, char *); |
511 | char *str = va_arg (ap, char *); |
526 | int len = va_arg (ap, int); |
512 | int len = va_arg (ap, int); |
527 | |
513 | |
528 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
514 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
529 | } |
515 | } |
530 | break; |
516 | break; |
531 | |
517 | |
532 | case DT_WCS_LEN: |
518 | case DT_WCS_LEN: |
533 | { |
519 | { |
534 | wchar_t *wstr = va_arg (ap, wchar_t *); |
520 | wchar_t *wstr = va_arg (ap, wchar_t *); |
535 | int wlen = va_arg (ap, int); |
521 | int wlen = va_arg (ap, int); |
536 | |
522 | |
537 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
523 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
538 | } |
524 | } |
539 | break; |
525 | break; |
540 | |
526 | |
541 | case DT_XEVENT: |
527 | case DT_XEVENT: |
542 | { |
528 | { |
… | |
… | |
779 | void |
765 | void |
780 | fatal (const char *msg) |
766 | fatal (const char *msg) |
781 | CODE: |
767 | CODE: |
782 | rxvt_fatal ("%s", msg); |
768 | rxvt_fatal ("%s", msg); |
783 | |
769 | |
784 | SV * |
|
|
785 | untaint (SV *sv) |
|
|
786 | CODE: |
|
|
787 | RETVAL = newSVsv (sv); |
|
|
788 | SvTAINTED_off (RETVAL); |
|
|
789 | OUTPUT: |
|
|
790 | RETVAL |
|
|
791 | |
|
|
792 | void |
770 | void |
793 | _exit (int status) |
771 | _exit (int status) |
794 | |
|
|
795 | bool |
|
|
796 | safe () |
|
|
797 | CODE: |
|
|
798 | RETVAL = !rxvt_tainted (); |
|
|
799 | OUTPUT: |
|
|
800 | RETVAL |
|
|
801 | |
772 | |
802 | NV |
773 | NV |
803 | NOW () |
774 | NOW () |
804 | CODE: |
775 | CODE: |
805 | RETVAL = NOW; |
776 | RETVAL = NOW; |
… | |
… | |
1071 | char *mbstr = rxvt_wcstombs (wstr); |
1042 | char *mbstr = rxvt_wcstombs (wstr); |
1072 | rxvt_pop_locale (); |
1043 | rxvt_pop_locale (); |
1073 | |
1044 | |
1074 | free (wstr); |
1045 | free (wstr); |
1075 | |
1046 | |
1076 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
1047 | RETVAL = newSVpv (mbstr, 0); |
1077 | free (mbstr); |
1048 | free (mbstr); |
1078 | } |
1049 | } |
1079 | OUTPUT: |
1050 | OUTPUT: |
1080 | RETVAL |
1051 | RETVAL |
1081 | |
1052 | |
… | |
… | |
1088 | |
1059 | |
1089 | rxvt_push_locale (THIS->locale); |
1060 | rxvt_push_locale (THIS->locale); |
1090 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1061 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1091 | rxvt_pop_locale (); |
1062 | rxvt_pop_locale (); |
1092 | |
1063 | |
1093 | RETVAL = taint_if (wcs2sv (wstr), octets); |
1064 | RETVAL = wcs2sv (wstr); |
1094 | free (wstr); |
1065 | free (wstr); |
1095 | } |
1066 | } |
1096 | OUTPUT: |
1067 | OUTPUT: |
1097 | RETVAL |
1068 | RETVAL |
1098 | |
1069 | |
… | |
… | |
1250 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1221 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1251 | |
1222 | |
1252 | for (int col = 0; col < THIS->ncol; col++) |
1223 | for (int col = 0; col < THIS->ncol; col++) |
1253 | wstr [col] = l.t [col]; |
1224 | wstr [col] = l.t [col]; |
1254 | |
1225 | |
1255 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
1226 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
1256 | |
1227 | |
1257 | delete [] wstr; |
1228 | delete [] wstr; |
1258 | } |
1229 | } |
1259 | |
1230 | |
1260 | if (new_text) |
1231 | if (new_text) |
… | |
… | |
1381 | else |
1352 | else |
1382 | *r++ = *s; |
1353 | *r++ = *s; |
1383 | |
1354 | |
1384 | rxvt_pop_locale (); |
1355 | rxvt_pop_locale (); |
1385 | |
1356 | |
1386 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1357 | RETVAL = wcs2sv (rstr, r - rstr); |
1387 | |
1358 | |
1388 | delete [] rstr; |
1359 | delete [] rstr; |
1389 | } |
1360 | } |
1390 | OUTPUT: |
1361 | OUTPUT: |
1391 | RETVAL |
1362 | RETVAL |
… | |
… | |
1417 | else if (IS_COMPOSE (*s)) |
1388 | else if (IS_COMPOSE (*s)) |
1418 | r += rxvt_composite.expand (*s, r); |
1389 | r += rxvt_composite.expand (*s, r); |
1419 | else |
1390 | else |
1420 | *r++ = *s; |
1391 | *r++ = *s; |
1421 | |
1392 | |
1422 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1393 | RETVAL = wcs2sv (rstr, r - rstr); |
1423 | |
1394 | |
1424 | delete [] rstr; |
1395 | delete [] rstr; |
1425 | } |
1396 | } |
1426 | OUTPUT: |
1397 | OUTPUT: |
1427 | RETVAL |
1398 | RETVAL |
… | |
… | |
1449 | |
1420 | |
1450 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1421 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1451 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1422 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1452 | |
1423 | |
1453 | if (GIMME_V != G_VOID) |
1424 | if (GIMME_V != G_VOID) |
1454 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1425 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1455 | |
1426 | |
1456 | if (newval) |
1427 | if (newval) |
1457 | { |
1428 | { |
1458 | if (SvOK (newval)) |
1429 | if (SvOK (newval)) |
1459 | { |
1430 | { |
… | |
… | |
1466 | } |
1437 | } |
1467 | } |
1438 | } |
1468 | |
1439 | |
1469 | const char * |
1440 | const char * |
1470 | rxvt_term::x_resource (const char *name) |
1441 | rxvt_term::x_resource (const char *name) |
1471 | CLEANUP: |
|
|
1472 | SvTAINTED_on (ST (0)); |
|
|
1473 | |
1442 | |
1474 | bool |
1443 | bool |
1475 | rxvt_term::option (U32 optval, int set = -1) |
1444 | rxvt_term::option (U32 optval, int set = -1) |
1476 | CODE: |
1445 | CODE: |
1477 | { |
1446 | { |
… | |
… | |
1571 | rxvt_term::selection (SV *newtext = 0) |
1540 | rxvt_term::selection (SV *newtext = 0) |
1572 | PPCODE: |
1541 | PPCODE: |
1573 | { |
1542 | { |
1574 | if (GIMME_V != G_VOID) |
1543 | if (GIMME_V != G_VOID) |
1575 | XPUSHs (THIS->selection.text |
1544 | XPUSHs (THIS->selection.text |
1576 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
1545 | ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) |
1577 | : &PL_sv_undef); |
1546 | : &PL_sv_undef); |
1578 | |
1547 | |
1579 | if (newtext) |
1548 | if (newtext) |
1580 | { |
1549 | { |
1581 | free (THIS->selection.text); |
1550 | free (THIS->selection.text); |