… | |
… | |
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); |
… | |
… | |
518 | case DT_LONG: |
507 | case DT_LONG: |
519 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
508 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
520 | break; |
509 | break; |
521 | |
510 | |
522 | case DT_STR: |
511 | case DT_STR: |
523 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
512 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
524 | break; |
513 | break; |
525 | |
514 | |
526 | case DT_STR_LEN: |
515 | case DT_STR_LEN: |
527 | { |
516 | { |
528 | char *str = va_arg (ap, char *); |
517 | char *str = va_arg (ap, char *); |
529 | int len = va_arg (ap, int); |
518 | int len = va_arg (ap, int); |
530 | |
519 | |
531 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
520 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
532 | } |
521 | } |
533 | break; |
522 | break; |
534 | |
523 | |
535 | case DT_WCS_LEN: |
524 | case DT_WCS_LEN: |
536 | { |
525 | { |
537 | wchar_t *wstr = va_arg (ap, wchar_t *); |
526 | wchar_t *wstr = va_arg (ap, wchar_t *); |
538 | int wlen = va_arg (ap, int); |
527 | int wlen = va_arg (ap, int); |
539 | |
528 | |
540 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
529 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
541 | } |
530 | } |
542 | break; |
531 | break; |
543 | |
532 | |
544 | case DT_XEVENT: |
533 | case DT_XEVENT: |
545 | { |
534 | { |
… | |
… | |
782 | void |
771 | void |
783 | fatal (const char *msg) |
772 | fatal (const char *msg) |
784 | CODE: |
773 | CODE: |
785 | rxvt_fatal ("%s", msg); |
774 | rxvt_fatal ("%s", msg); |
786 | |
775 | |
787 | SV * |
|
|
788 | untaint (SV *sv) |
|
|
789 | CODE: |
|
|
790 | RETVAL = newSVsv (sv); |
|
|
791 | SvTAINTED_off (RETVAL); |
|
|
792 | OUTPUT: |
|
|
793 | RETVAL |
|
|
794 | |
|
|
795 | void |
776 | void |
796 | _exit (int status) |
777 | _exit (int status) |
797 | |
|
|
798 | bool |
|
|
799 | safe () |
|
|
800 | CODE: |
|
|
801 | RETVAL = !rxvt_tainted (); |
|
|
802 | OUTPUT: |
|
|
803 | RETVAL |
|
|
804 | |
778 | |
805 | NV |
779 | NV |
806 | NOW () |
780 | NOW () |
807 | CODE: |
781 | CODE: |
808 | RETVAL = NOW; |
782 | RETVAL = NOW; |
… | |
… | |
1074 | char *mbstr = rxvt_wcstombs (wstr); |
1048 | char *mbstr = rxvt_wcstombs (wstr); |
1075 | rxvt_pop_locale (); |
1049 | rxvt_pop_locale (); |
1076 | |
1050 | |
1077 | free (wstr); |
1051 | free (wstr); |
1078 | |
1052 | |
1079 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
1053 | RETVAL = newSVpv (mbstr, 0); |
1080 | free (mbstr); |
1054 | free (mbstr); |
1081 | } |
1055 | } |
1082 | OUTPUT: |
1056 | OUTPUT: |
1083 | RETVAL |
1057 | RETVAL |
1084 | |
1058 | |
… | |
… | |
1091 | |
1065 | |
1092 | rxvt_push_locale (THIS->locale); |
1066 | rxvt_push_locale (THIS->locale); |
1093 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1067 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1094 | rxvt_pop_locale (); |
1068 | rxvt_pop_locale (); |
1095 | |
1069 | |
1096 | RETVAL = taint_if (wcs2sv (wstr), octets); |
1070 | RETVAL = wcs2sv (wstr); |
1097 | free (wstr); |
1071 | free (wstr); |
1098 | } |
1072 | } |
1099 | OUTPUT: |
1073 | OUTPUT: |
1100 | RETVAL |
1074 | RETVAL |
1101 | |
1075 | |
… | |
… | |
1253 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1227 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1254 | |
1228 | |
1255 | for (int col = 0; col < THIS->ncol; col++) |
1229 | for (int col = 0; col < THIS->ncol; col++) |
1256 | wstr [col] = l.t [col]; |
1230 | wstr [col] = l.t [col]; |
1257 | |
1231 | |
1258 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
1232 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
1259 | |
1233 | |
1260 | delete [] wstr; |
1234 | delete [] wstr; |
1261 | } |
1235 | } |
1262 | |
1236 | |
1263 | if (new_text) |
1237 | if (new_text) |
… | |
… | |
1384 | else |
1358 | else |
1385 | *r++ = *s; |
1359 | *r++ = *s; |
1386 | |
1360 | |
1387 | rxvt_pop_locale (); |
1361 | rxvt_pop_locale (); |
1388 | |
1362 | |
1389 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1363 | RETVAL = wcs2sv (rstr, r - rstr); |
1390 | |
1364 | |
1391 | delete [] rstr; |
1365 | delete [] rstr; |
1392 | } |
1366 | } |
1393 | OUTPUT: |
1367 | OUTPUT: |
1394 | RETVAL |
1368 | RETVAL |
… | |
… | |
1420 | else if (IS_COMPOSE (*s)) |
1394 | else if (IS_COMPOSE (*s)) |
1421 | r += rxvt_composite.expand (*s, r); |
1395 | r += rxvt_composite.expand (*s, r); |
1422 | else |
1396 | else |
1423 | *r++ = *s; |
1397 | *r++ = *s; |
1424 | |
1398 | |
1425 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1399 | RETVAL = wcs2sv (rstr, r - rstr); |
1426 | |
1400 | |
1427 | delete [] rstr; |
1401 | delete [] rstr; |
1428 | } |
1402 | } |
1429 | OUTPUT: |
1403 | OUTPUT: |
1430 | RETVAL |
1404 | RETVAL |
… | |
… | |
1452 | |
1426 | |
1453 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1427 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1454 | 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); |
1455 | |
1429 | |
1456 | if (GIMME_V != G_VOID) |
1430 | if (GIMME_V != G_VOID) |
1457 | 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); |
1458 | |
1432 | |
1459 | if (newval) |
1433 | if (newval) |
1460 | { |
1434 | { |
1461 | if (SvOK (newval)) |
1435 | if (SvOK (newval)) |
1462 | { |
1436 | { |
… | |
… | |
1469 | } |
1443 | } |
1470 | } |
1444 | } |
1471 | |
1445 | |
1472 | const char * |
1446 | const char * |
1473 | rxvt_term::x_resource (const char *name) |
1447 | rxvt_term::x_resource (const char *name) |
1474 | CLEANUP: |
|
|
1475 | SvTAINTED_on (ST (0)); |
|
|
1476 | |
1448 | |
1477 | bool |
1449 | bool |
1478 | rxvt_term::option (U32 optval, int set = -1) |
1450 | rxvt_term::option (U32 optval, int set = -1) |
1479 | CODE: |
1451 | CODE: |
1480 | { |
1452 | { |
… | |
… | |
1540 | PUSHs (sv_2mortal (newSViv (rc.col))); |
1512 | PUSHs (sv_2mortal (newSViv (rc.col))); |
1541 | } |
1513 | } |
1542 | |
1514 | |
1543 | if (items == 3) |
1515 | if (items == 3) |
1544 | { |
1516 | { |
|
|
1517 | rc.row = SvIV (ST (1)); |
|
|
1518 | rc.col = SvIV (ST (2)); |
|
|
1519 | |
|
|
1520 | if (ix == 2 && rc.col == 0) |
|
|
1521 | { |
|
|
1522 | rc.row--; |
|
|
1523 | rc.col = THIS->ncol; |
|
|
1524 | } |
|
|
1525 | |
|
|
1526 | clamp_it (rc.col, 0, THIS->ncol); |
1545 | rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1); |
1527 | clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); |
1546 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
|
|
1547 | |
1528 | |
1548 | if (ix) |
1529 | if (ix) |
1549 | THIS->want_refresh = 1; |
1530 | THIS->want_refresh = 1; |
1550 | } |
1531 | } |
1551 | } |
1532 | } |
… | |
… | |
1574 | rxvt_term::selection (SV *newtext = 0) |
1555 | rxvt_term::selection (SV *newtext = 0) |
1575 | PPCODE: |
1556 | PPCODE: |
1576 | { |
1557 | { |
1577 | if (GIMME_V != G_VOID) |
1558 | if (GIMME_V != G_VOID) |
1578 | XPUSHs (THIS->selection.text |
1559 | XPUSHs (THIS->selection.text |
1579 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
1560 | ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) |
1580 | : &PL_sv_undef); |
1561 | : &PL_sv_undef); |
1581 | |
1562 | |
1582 | if (newtext) |
1563 | if (newtext) |
1583 | { |
1564 | { |
1584 | free (THIS->selection.text); |
1565 | free (THIS->selection.text); |