… | |
… | |
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", |
407 | "-e" |
424 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
408 | "BEGIN {" |
|
|
409 | " urxvt->bootstrap;" |
|
|
410 | " unshift @INC, '" LIBDIR "';" |
|
|
411 | "}" |
|
|
412 | "" |
|
|
413 | "use urxvt;" |
425 | }; |
414 | }; |
426 | |
415 | |
427 | perl = perl_alloc (); |
416 | perl = perl_alloc (); |
428 | perl_construct (perl); |
417 | perl_construct (perl); |
429 | |
418 | |
430 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
419 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
431 | || perl_run (perl)) |
420 | || perl_run (perl)) |
432 | { |
421 | { |
433 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
422 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
434 | |
423 | |
435 | perl_destruct (perl); |
424 | perl_destruct (perl); |
… | |
… | |
440 | swap (perl_environ, environ); |
429 | swap (perl_environ, environ); |
441 | |
430 | |
442 | rxvt_pop_locale (); |
431 | rxvt_pop_locale (); |
443 | } |
432 | } |
444 | |
433 | |
|
|
434 | if (perl) |
|
|
435 | { |
445 | // runs outside of perls ENV |
436 | // runs outside of perls ENV |
446 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
437 | 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); |
438 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
|
|
439 | } |
448 | } |
440 | } |
449 | |
441 | |
450 | static void |
442 | static void |
451 | ungrab (rxvt_term *THIS) |
443 | ungrab (rxvt_term *THIS) |
452 | { |
444 | { |
… | |
… | |
515 | case DT_LONG: |
507 | case DT_LONG: |
516 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
508 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
517 | break; |
509 | break; |
518 | |
510 | |
519 | case DT_STR: |
511 | case DT_STR: |
520 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
512 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
521 | break; |
513 | break; |
522 | |
514 | |
523 | case DT_STR_LEN: |
515 | case DT_STR_LEN: |
524 | { |
516 | { |
525 | char *str = va_arg (ap, char *); |
517 | char *str = va_arg (ap, char *); |
526 | int len = va_arg (ap, int); |
518 | int len = va_arg (ap, int); |
527 | |
519 | |
528 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
520 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
529 | } |
521 | } |
530 | break; |
522 | break; |
531 | |
523 | |
532 | case DT_WCS_LEN: |
524 | case DT_WCS_LEN: |
533 | { |
525 | { |
534 | wchar_t *wstr = va_arg (ap, wchar_t *); |
526 | wchar_t *wstr = va_arg (ap, wchar_t *); |
535 | int wlen = va_arg (ap, int); |
527 | int wlen = va_arg (ap, int); |
536 | |
528 | |
537 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
529 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
538 | } |
530 | } |
539 | break; |
531 | break; |
540 | |
532 | |
541 | case DT_XEVENT: |
533 | case DT_XEVENT: |
542 | { |
534 | { |
… | |
… | |
779 | void |
771 | void |
780 | fatal (const char *msg) |
772 | fatal (const char *msg) |
781 | CODE: |
773 | CODE: |
782 | rxvt_fatal ("%s", msg); |
774 | rxvt_fatal ("%s", msg); |
783 | |
775 | |
784 | SV * |
|
|
785 | untaint (SV *sv) |
|
|
786 | CODE: |
|
|
787 | RETVAL = newSVsv (sv); |
|
|
788 | SvTAINTED_off (RETVAL); |
|
|
789 | OUTPUT: |
|
|
790 | RETVAL |
|
|
791 | |
|
|
792 | void |
776 | void |
793 | _exit (int status) |
777 | _exit (int status) |
794 | |
|
|
795 | bool |
|
|
796 | safe () |
|
|
797 | CODE: |
|
|
798 | RETVAL = !rxvt_tainted (); |
|
|
799 | OUTPUT: |
|
|
800 | RETVAL |
|
|
801 | |
778 | |
802 | NV |
779 | NV |
803 | NOW () |
780 | NOW () |
804 | CODE: |
781 | CODE: |
805 | RETVAL = NOW; |
782 | RETVAL = NOW; |
… | |
… | |
1071 | char *mbstr = rxvt_wcstombs (wstr); |
1048 | char *mbstr = rxvt_wcstombs (wstr); |
1072 | rxvt_pop_locale (); |
1049 | rxvt_pop_locale (); |
1073 | |
1050 | |
1074 | free (wstr); |
1051 | free (wstr); |
1075 | |
1052 | |
1076 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
1053 | RETVAL = newSVpv (mbstr, 0); |
1077 | free (mbstr); |
1054 | free (mbstr); |
1078 | } |
1055 | } |
1079 | OUTPUT: |
1056 | OUTPUT: |
1080 | RETVAL |
1057 | RETVAL |
1081 | |
1058 | |
… | |
… | |
1088 | |
1065 | |
1089 | rxvt_push_locale (THIS->locale); |
1066 | rxvt_push_locale (THIS->locale); |
1090 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1067 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1091 | rxvt_pop_locale (); |
1068 | rxvt_pop_locale (); |
1092 | |
1069 | |
1093 | RETVAL = taint_if (wcs2sv (wstr), octets); |
1070 | RETVAL = wcs2sv (wstr); |
1094 | free (wstr); |
1071 | free (wstr); |
1095 | } |
1072 | } |
1096 | OUTPUT: |
1073 | OUTPUT: |
1097 | RETVAL |
1074 | RETVAL |
1098 | |
1075 | |
… | |
… | |
1250 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1227 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1251 | |
1228 | |
1252 | for (int col = 0; col < THIS->ncol; col++) |
1229 | for (int col = 0; col < THIS->ncol; col++) |
1253 | wstr [col] = l.t [col]; |
1230 | wstr [col] = l.t [col]; |
1254 | |
1231 | |
1255 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
1232 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
1256 | |
1233 | |
1257 | delete [] wstr; |
1234 | delete [] wstr; |
1258 | } |
1235 | } |
1259 | |
1236 | |
1260 | if (new_text) |
1237 | if (new_text) |
… | |
… | |
1381 | else |
1358 | else |
1382 | *r++ = *s; |
1359 | *r++ = *s; |
1383 | |
1360 | |
1384 | rxvt_pop_locale (); |
1361 | rxvt_pop_locale (); |
1385 | |
1362 | |
1386 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1363 | RETVAL = wcs2sv (rstr, r - rstr); |
1387 | |
1364 | |
1388 | delete [] rstr; |
1365 | delete [] rstr; |
1389 | } |
1366 | } |
1390 | OUTPUT: |
1367 | OUTPUT: |
1391 | RETVAL |
1368 | RETVAL |
… | |
… | |
1417 | else if (IS_COMPOSE (*s)) |
1394 | else if (IS_COMPOSE (*s)) |
1418 | r += rxvt_composite.expand (*s, r); |
1395 | r += rxvt_composite.expand (*s, r); |
1419 | else |
1396 | else |
1420 | *r++ = *s; |
1397 | *r++ = *s; |
1421 | |
1398 | |
1422 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1399 | RETVAL = wcs2sv (rstr, r - rstr); |
1423 | |
1400 | |
1424 | delete [] rstr; |
1401 | delete [] rstr; |
1425 | } |
1402 | } |
1426 | OUTPUT: |
1403 | OUTPUT: |
1427 | RETVAL |
1404 | RETVAL |
… | |
… | |
1449 | |
1426 | |
1450 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1427 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1451 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1428 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1452 | |
1429 | |
1453 | if (GIMME_V != G_VOID) |
1430 | if (GIMME_V != G_VOID) |
1454 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1431 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1455 | |
1432 | |
1456 | if (newval) |
1433 | if (newval) |
1457 | { |
1434 | { |
1458 | if (SvOK (newval)) |
1435 | if (SvOK (newval)) |
1459 | { |
1436 | { |
… | |
… | |
1466 | } |
1443 | } |
1467 | } |
1444 | } |
1468 | |
1445 | |
1469 | const char * |
1446 | const char * |
1470 | rxvt_term::x_resource (const char *name) |
1447 | rxvt_term::x_resource (const char *name) |
1471 | CLEANUP: |
|
|
1472 | SvTAINTED_on (ST (0)); |
|
|
1473 | |
1448 | |
1474 | bool |
1449 | bool |
1475 | rxvt_term::option (U32 optval, int set = -1) |
1450 | rxvt_term::option (U32 optval, int set = -1) |
1476 | CODE: |
1451 | CODE: |
1477 | { |
1452 | { |
… | |
… | |
1571 | rxvt_term::selection (SV *newtext = 0) |
1546 | rxvt_term::selection (SV *newtext = 0) |
1572 | PPCODE: |
1547 | PPCODE: |
1573 | { |
1548 | { |
1574 | if (GIMME_V != G_VOID) |
1549 | if (GIMME_V != G_VOID) |
1575 | XPUSHs (THIS->selection.text |
1550 | XPUSHs (THIS->selection.text |
1576 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
1551 | ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) |
1577 | : &PL_sv_undef); |
1552 | : &PL_sv_undef); |
1578 | |
1553 | |
1579 | if (newtext) |
1554 | if (newtext) |
1580 | { |
1555 | { |
1581 | free (THIS->selection.text); |
1556 | free (THIS->selection.text); |