… | |
… | |
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); |
… | |
… | |
518 | case DT_LONG: |
501 | case DT_LONG: |
519 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
502 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
520 | break; |
503 | break; |
521 | |
504 | |
522 | case DT_STR: |
505 | case DT_STR: |
523 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
506 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
524 | break; |
507 | break; |
525 | |
508 | |
526 | case DT_STR_LEN: |
509 | case DT_STR_LEN: |
527 | { |
510 | { |
528 | char *str = va_arg (ap, char *); |
511 | char *str = va_arg (ap, char *); |
529 | int len = va_arg (ap, int); |
512 | int len = va_arg (ap, int); |
530 | |
513 | |
531 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
514 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
532 | } |
515 | } |
533 | break; |
516 | break; |
534 | |
517 | |
535 | case DT_WCS_LEN: |
518 | case DT_WCS_LEN: |
536 | { |
519 | { |
537 | wchar_t *wstr = va_arg (ap, wchar_t *); |
520 | wchar_t *wstr = va_arg (ap, wchar_t *); |
538 | int wlen = va_arg (ap, int); |
521 | int wlen = va_arg (ap, int); |
539 | |
522 | |
540 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
523 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
541 | } |
524 | } |
542 | break; |
525 | break; |
543 | |
526 | |
544 | case DT_XEVENT: |
527 | case DT_XEVENT: |
545 | { |
528 | { |
… | |
… | |
782 | void |
765 | void |
783 | fatal (const char *msg) |
766 | fatal (const char *msg) |
784 | CODE: |
767 | CODE: |
785 | rxvt_fatal ("%s", msg); |
768 | rxvt_fatal ("%s", msg); |
786 | |
769 | |
787 | SV * |
|
|
788 | untaint (SV *sv) |
|
|
789 | CODE: |
|
|
790 | RETVAL = newSVsv (sv); |
|
|
791 | SvTAINTED_off (RETVAL); |
|
|
792 | OUTPUT: |
|
|
793 | RETVAL |
|
|
794 | |
|
|
795 | void |
770 | void |
796 | _exit (int status) |
771 | _exit (int status) |
797 | |
|
|
798 | bool |
|
|
799 | safe () |
|
|
800 | CODE: |
|
|
801 | RETVAL = !rxvt_tainted (); |
|
|
802 | OUTPUT: |
|
|
803 | RETVAL |
|
|
804 | |
772 | |
805 | NV |
773 | NV |
806 | NOW () |
774 | NOW () |
807 | CODE: |
775 | CODE: |
808 | RETVAL = NOW; |
776 | RETVAL = NOW; |
… | |
… | |
1074 | char *mbstr = rxvt_wcstombs (wstr); |
1042 | char *mbstr = rxvt_wcstombs (wstr); |
1075 | rxvt_pop_locale (); |
1043 | rxvt_pop_locale (); |
1076 | |
1044 | |
1077 | free (wstr); |
1045 | free (wstr); |
1078 | |
1046 | |
1079 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
1047 | RETVAL = newSVpv (mbstr, 0); |
1080 | free (mbstr); |
1048 | free (mbstr); |
1081 | } |
1049 | } |
1082 | OUTPUT: |
1050 | OUTPUT: |
1083 | RETVAL |
1051 | RETVAL |
1084 | |
1052 | |
… | |
… | |
1091 | |
1059 | |
1092 | rxvt_push_locale (THIS->locale); |
1060 | rxvt_push_locale (THIS->locale); |
1093 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1061 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1094 | rxvt_pop_locale (); |
1062 | rxvt_pop_locale (); |
1095 | |
1063 | |
1096 | RETVAL = taint_if (wcs2sv (wstr), octets); |
1064 | RETVAL = wcs2sv (wstr); |
1097 | free (wstr); |
1065 | free (wstr); |
1098 | } |
1066 | } |
1099 | OUTPUT: |
1067 | OUTPUT: |
1100 | RETVAL |
1068 | RETVAL |
1101 | |
1069 | |
… | |
… | |
1253 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1221 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1254 | |
1222 | |
1255 | for (int col = 0; col < THIS->ncol; col++) |
1223 | for (int col = 0; col < THIS->ncol; col++) |
1256 | wstr [col] = l.t [col]; |
1224 | wstr [col] = l.t [col]; |
1257 | |
1225 | |
1258 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
1226 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
1259 | |
1227 | |
1260 | delete [] wstr; |
1228 | delete [] wstr; |
1261 | } |
1229 | } |
1262 | |
1230 | |
1263 | if (new_text) |
1231 | if (new_text) |
… | |
… | |
1384 | else |
1352 | else |
1385 | *r++ = *s; |
1353 | *r++ = *s; |
1386 | |
1354 | |
1387 | rxvt_pop_locale (); |
1355 | rxvt_pop_locale (); |
1388 | |
1356 | |
1389 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1357 | RETVAL = wcs2sv (rstr, r - rstr); |
1390 | |
1358 | |
1391 | delete [] rstr; |
1359 | delete [] rstr; |
1392 | } |
1360 | } |
1393 | OUTPUT: |
1361 | OUTPUT: |
1394 | RETVAL |
1362 | RETVAL |
… | |
… | |
1420 | else if (IS_COMPOSE (*s)) |
1388 | else if (IS_COMPOSE (*s)) |
1421 | r += rxvt_composite.expand (*s, r); |
1389 | r += rxvt_composite.expand (*s, r); |
1422 | else |
1390 | else |
1423 | *r++ = *s; |
1391 | *r++ = *s; |
1424 | |
1392 | |
1425 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1393 | RETVAL = wcs2sv (rstr, r - rstr); |
1426 | |
1394 | |
1427 | delete [] rstr; |
1395 | delete [] rstr; |
1428 | } |
1396 | } |
1429 | OUTPUT: |
1397 | OUTPUT: |
1430 | RETVAL |
1398 | RETVAL |
… | |
… | |
1452 | |
1420 | |
1453 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1421 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1454 | 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); |
1455 | |
1423 | |
1456 | if (GIMME_V != G_VOID) |
1424 | if (GIMME_V != G_VOID) |
1457 | 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); |
1458 | |
1426 | |
1459 | if (newval) |
1427 | if (newval) |
1460 | { |
1428 | { |
1461 | if (SvOK (newval)) |
1429 | if (SvOK (newval)) |
1462 | { |
1430 | { |
… | |
… | |
1469 | } |
1437 | } |
1470 | } |
1438 | } |
1471 | |
1439 | |
1472 | const char * |
1440 | const char * |
1473 | rxvt_term::x_resource (const char *name) |
1441 | rxvt_term::x_resource (const char *name) |
1474 | CLEANUP: |
|
|
1475 | SvTAINTED_on (ST (0)); |
|
|
1476 | |
1442 | |
1477 | bool |
1443 | bool |
1478 | rxvt_term::option (U32 optval, int set = -1) |
1444 | rxvt_term::option (U32 optval, int set = -1) |
1479 | CODE: |
1445 | CODE: |
1480 | { |
1446 | { |
… | |
… | |
1574 | rxvt_term::selection (SV *newtext = 0) |
1540 | rxvt_term::selection (SV *newtext = 0) |
1575 | PPCODE: |
1541 | PPCODE: |
1576 | { |
1542 | { |
1577 | if (GIMME_V != G_VOID) |
1543 | if (GIMME_V != G_VOID) |
1578 | XPUSHs (THIS->selection.text |
1544 | XPUSHs (THIS->selection.text |
1579 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
1545 | ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) |
1580 | : &PL_sv_undef); |
1546 | : &PL_sv_undef); |
1581 | |
1547 | |
1582 | if (newtext) |
1548 | if (newtext) |
1583 | { |
1549 | { |
1584 | free (THIS->selection.text); |
1550 | free (THIS->selection.text); |