--- rxvt-unicode/src/rxvtperl.xs 2006/01/07 21:22:02 1.38 +++ rxvt-unicode/src/rxvtperl.xs 2006/01/09 02:06:43 1.47 @@ -38,6 +38,12 @@ #include "perlxsi.c" +#if defined(HAVE_SCROLLBARS) || defined(MENUBAR) +# define GRAB_CURSOR THIS->leftptr_cursor +#else +# define GRAB_CURSOR None +#endif + #undef LINENO #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) #undef ROW @@ -45,6 +51,22 @@ ///////////////////////////////////////////////////////////////////////////// +static SV * +taint (SV *sv) +{ + SvTAINT (sv); + return sv; +} + +static SV * +taint_if (SV *sv, SV *src) +{ + if (SvTAINTED (src)) + SvTAINT (sv); + + return sv; +} + static wchar_t * sv2wcs (SV *sv) { @@ -392,13 +414,14 @@ { char *argv[] = { "", + "-T", "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", }; perl = perl_alloc (); perl_construct (perl); - if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) + if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) || perl_run (perl)) { rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); @@ -410,6 +433,17 @@ } } +static void +ungrab (rxvt_term *THIS) +{ + if (THIS->perl.grabtime) + { + XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); + XUngrabPointer (THIS->display->display, THIS->perl.grabtime); + THIS->perl.grabtime = 0; + } +} + bool rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) { @@ -469,7 +503,7 @@ break; case DT_STR: - XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); + XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); break; case DT_STR_LEN: @@ -477,7 +511,7 @@ char *str = va_arg (ap, char *); int len = va_arg (ap, int); - XPUSHs (sv_2mortal (newSVpvn (str, len))); + XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); } break; @@ -486,7 +520,7 @@ wchar_t *wstr = va_arg (ap, wchar_t *); int wlen = va_arg (ap, int); - XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); + XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); } break; @@ -561,7 +595,10 @@ LEAVE; if (SvTRUE (ERRSV)) - rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); + { + rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); + ungrab (term); // better lose the grab than the session + } if (htype == HOOK_DESTROY) { @@ -586,15 +623,22 @@ BOOT: { - HV *stash = gv_stashpv ("urxvt", 1); -# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); + sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); AV *hookname = get_av ("urxvt::HOOKNAME", 1); # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); # include "hookinc.h" # undef def - + HV *option = get_hv ("urxvt::OPTION", 1); +# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); +# define nodef(name) +# include "optinc.h" +# undef nodef +# undef def + + HV *stash = gv_stashpv ("urxvt", 1); +# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); export_const_iv (DEFAULT_RSTYLE); export_const_iv (OVERLAY_RSTYLE); export_const_iv (RS_Bold); @@ -618,8 +662,6 @@ export_const_iv (Button4Mask); export_const_iv (Button5Mask); export_const_iv (AnyModifier); - - sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); } SV * @@ -667,6 +709,21 @@ CODE: rxvt_fatal ("%s", msg); +SV * +untaint (SV *sv) + CODE: + RETVAL = newSVsv (sv); + SvTAINTED_off (RETVAL); + OUTPUT: + RETVAL + +bool +safe () + CODE: + RETVAL = !rxvt_tainted (); + OUTPUT: + RETVAL + NV NOW () CODE: @@ -732,7 +789,7 @@ CODE: XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, - GrabModeSync, GrabModeSync, None, None); + GrabModeSync, GrabModeSync, None, GRAB_CURSOR); bool rxvt_term::grab (U32 eventtime, int sync = 0) @@ -744,7 +801,7 @@ if (!XGrabPointer (THIS->display->display, THIS->vt, 0, ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, - mode, mode, None, None, eventtime)) + mode, mode, None, GRAB_CURSOR, eventtime)) if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) THIS->perl.grabtime = eventtime; else @@ -756,27 +813,25 @@ RETVAL void -rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) +rxvt_term::allow_events_async () CODE: - XAllowEvents (THIS->display->display, AsyncBoth, eventtime); + XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); void -rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) +rxvt_term::allow_events_sync () CODE: - XAllowEvents (THIS->display->display, SyncBoth, eventtime); + XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); void -rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) +rxvt_term::allow_events_replay () CODE: - XAllowEvents (THIS->display->display, ReplayPointer, eventtime); - XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); + XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); + XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); void -rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) +rxvt_term::ungrab () CODE: - THIS->perl.grabtime = 0; - XUngrabKeyboard (THIS->display->display, eventtime); - XUngrabPointer (THIS->display->display, eventtime); + ungrab (THIS); int rxvt_term::strwidth (SV *str) @@ -805,7 +860,7 @@ free (wstr); - RETVAL = newSVpv (mbstr, 0); + RETVAL = taint_if (newSVpv (mbstr, 0), str); free (mbstr); } OUTPUT: @@ -822,7 +877,7 @@ wchar_t *wstr = rxvt_mbstowcs (data, len); rxvt_pop_locale (); - RETVAL = wcs2sv (wstr); + RETVAL = taint_if (wcs2sv (wstr), octets); free (wstr); } OUTPUT: @@ -939,7 +994,7 @@ for (int col = 0; col < THIS->ncol; col++) wstr [col] = l.t [col]; - XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); + XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); delete [] wstr; } @@ -1070,7 +1125,7 @@ rxvt_pop_locale (); - RETVAL = wcs2sv (rstr, r - rstr); + RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); delete [] rstr; } @@ -1106,7 +1161,7 @@ else *r++ = *s; - RETVAL = wcs2sv (rstr, r - rstr); + RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); delete [] rstr; } @@ -1138,7 +1193,7 @@ croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); if (GIMME_V != G_VOID) - XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); + XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); if (newval) { @@ -1153,8 +1208,44 @@ } } +bool +rxvt_term::option (U32 optval, int set = -1) + CODE: +{ + RETVAL = THIS->options & optval; + + if (set >= 0) + { + if (set) + THIS->options |= optval; + else + THIS->options &= ~optval; + + switch (optval) + { + case Opt_skipBuiltinGlyphs: + THIS->set_fonts (); + THIS->scr_remap_chars (); + THIS->scr_touch (true); + THIS->want_refresh = 1; + break; + + case Opt_cursorUnderline: + THIS->want_refresh = 1; + break; + +# case Opt_scrollBar_floating: +# case Opt_scrollBar_right: +# THIS->resize_all_windows (THIS->width, THIS->height, 1); +# break; + } + } +} + OUTPUT: + RETVAL + void -rxvt_term::cur (...) +rxvt_term::screen_cur (...) PROTOTYPE: $;$$ ALIAS: screen_cur = 0 @@ -1193,7 +1284,9 @@ PPCODE: { if (GIMME_V != G_VOID) - XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); + XPUSHs (THIS->selection.text + ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) + : &PL_sv_undef); if (newtext) {