~ubuntu-branches/ubuntu/intrepid/ruby1.9/intrepid-updates

« back to all changes in this revision

Viewing changes to signal.c

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2005-09-21 13:16:19 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050921131619-qhlm5e5pz3bvsh2g
Tags: 1.9.0+20050921-1
* akira yamada <akira@debian.org>
- new upstream snapshot. (2005-09-21)
    - [security] JVN#62914675 CVE-2005-2337
        - preserve safe level in the environment where a method is defined.
        - prohibit calling tainted method (>2) when $SAFE == 0.
- removed debian/patches/802_workaround_for_send.dpatch:
    - the patch is in upstream.
- debian/control: build-depends on libreadline5-dev.  (closes: #326333)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
  signal.c -
4
4
 
5
 
  $Author: matz $
6
 
  $Date: 2005/06/12 16:56:05 $
 
5
  $Author: ocean $
 
6
  $Date: 2005/09/14 08:30:16 $
7
7
  created at: Tue Dec 20 10:13:44 JST 1994
8
8
 
9
9
  Copyright (C) 1993-2003 Yukihiro Matsumoto
169
169
};
170
170
 
171
171
static int
172
 
signm2signo(nm)
173
 
    char *nm;
 
172
signm2signo(char *nm)
174
173
{
175
174
    struct signals *sigs;
176
175
 
181
180
}
182
181
 
183
182
static char*
184
 
signo2signm(no)
185
 
    int no;
 
183
signo2signm(int no)
186
184
{
187
185
    struct signals *sigs;
188
186
 
193
191
}
194
192
 
195
193
const char *
196
 
ruby_signal_name(no)
197
 
    int no;
 
194
ruby_signal_name(int no)
198
195
{
199
196
    return signo2signm(no);
200
197
}
224
221
 */
225
222
 
226
223
VALUE
227
 
rb_f_kill(argc, argv)
228
 
    int argc;
229
 
    VALUE *argv;
 
224
rb_f_kill(int argc, VALUE *argv)
230
225
{
231
226
    int negative = 0;
232
227
    int sig;
310
305
int rb_prohibit_interrupt = 1;
311
306
 
312
307
void
313
 
rb_gc_mark_trap_list()
 
308
rb_gc_mark_trap_list(void)
314
309
{
315
310
#ifndef MACOS_UNUSE_SIGNAL
316
311
    int i;
326
321
#define sighandler_t sh_t
327
322
#endif
328
323
 
329
 
typedef RETSIGTYPE (*sighandler_t)_((int));
 
324
typedef RETSIGTYPE (*sighandler_t)(int);
330
325
 
331
326
#ifdef POSIX_SIGNAL
332
327
static sighandler_t
382
377
#define ruby_signal(sig,handler) (rb_trap_accept_nativethreads[sig] = 0, signal((sig),(handler)))
383
378
#ifdef HAVE_NATIVETHREAD
384
379
static sighandler_t
385
 
ruby_nativethread_signal(signum, handler)
386
 
    int signum;
387
 
    sighandler_t handler;
 
380
ruby_nativethread_signal(int signum, sighandler_t handler)
388
381
{
389
382
    sighandler_t old;
390
383
 
395
388
#endif
396
389
#endif
397
390
 
398
 
static void signal_exec _((int sig));
399
391
static void
400
 
signal_exec(sig)
401
 
    int sig;
 
392
signal_exec(int sig)
402
393
{
403
394
    if (trap_list[sig].cmd == 0) {
404
395
        switch (sig) {
424
415
            break;
425
416
        }
426
417
    }
 
418
    else if (trap_list[sig].cmd == Qundef) {
 
419
        rb_thread_signal_exit();
 
420
    }
427
421
    else {
428
422
        rb_thread_trap_eval(trap_list[sig].cmd, sig, trap_list[sig].safe);
429
423
    }
430
424
}
431
425
 
432
426
static void
433
 
sigsend_to_ruby_thread(sig)
434
 
    int sig;
 
427
sigsend_to_ruby_thread(int sig)
435
428
{
436
429
#ifdef HAVE_NATIVETHREAD_KILL
437
430
# ifdef HAVE_SIGPROCMASK
452
445
#endif
453
446
}
454
447
 
455
 
static RETSIGTYPE sighandler _((int));
 
448
static RETSIGTYPE sighandler(int);
456
449
static RETSIGTYPE
457
 
sighandler(sig)
458
 
    int sig;
 
450
sighandler(int sig)
459
451
{
460
452
#ifdef _WIN32
461
453
#define IN_MAIN_CONTEXT(f, a) (rb_w32_main_context(a, f) ? (void)0 : f(a))
492
484
}
493
485
 
494
486
#ifdef SIGBUS
495
 
static RETSIGTYPE sigbus _((int));
496
487
static RETSIGTYPE
497
 
sigbus(sig)
498
 
    int sig;
 
488
sigbus(int sig)
499
489
{
500
490
#if defined(HAVE_NATIVETHREAD) && defined(HAVE_NATIVETHREAD_KILL)
501
491
    if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
509
499
#endif
510
500
 
511
501
#ifdef SIGSEGV
512
 
static RETSIGTYPE sigsegv _((int));
513
502
static RETSIGTYPE
514
 
sigsegv(sig)
515
 
    int sig;
 
503
sigsegv(int sig)
516
504
{
517
505
#if defined(HAVE_NATIVETHREAD) && defined(HAVE_NATIVETHREAD_KILL)
518
506
    if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
526
514
#endif
527
515
 
528
516
#ifdef SIGPIPE
529
 
static RETSIGTYPE sigpipe _((int));
530
517
static RETSIGTYPE
531
 
sigpipe(sig)
532
 
    int sig;
 
518
sigpipe(int sig)
533
519
{
534
520
    /* do nothing */
535
521
}
536
522
#endif
537
523
 
538
524
void
539
 
rb_trap_exit()
 
525
rb_trap_exit(void)
540
526
{
541
527
#ifndef MACOS_UNUSE_SIGNAL
542
528
    if (trap_list[0].cmd) {
549
535
}
550
536
 
551
537
void
552
 
rb_trap_exec()
 
538
rb_trap_exec(void)
553
539
{
554
540
#ifndef MACOS_UNUSE_SIGNAL
555
541
    int i;
581
567
static int trap_last_mask;
582
568
# endif
583
569
 
584
 
static RETSIGTYPE sigexit _((int));
585
 
static RETSIGTYPE
586
 
sigexit(sig)
587
 
    int sig;
588
 
{
589
 
#if defined(HAVE_NATIVETHREAD) && defined(HAVE_NATIVETHREAD_KILL)
590
 
    if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
591
 
        sigsend_to_ruby_thread(sig);
592
 
        return;
593
 
    }
594
 
#endif
595
 
 
596
 
    rb_thread_signal_exit();
597
 
}
598
 
 
599
570
static VALUE
600
 
trap(arg)
601
 
    struct trap_arg *arg;
 
571
trap(struct trap_arg *arg)
602
572
{
603
573
    sighandler_t func, oldfunc;
604
 
    VALUE command, oldcmd;
 
574
    VALUE command, tmp, oldcmd;
605
575
    int sig = -1;
606
576
    char *s;
607
577
 
608
578
    func = sighandler;
609
 
    command = arg->cmd;
610
 
    if (NIL_P(command)) {
 
579
    if (NIL_P(arg->cmd)) {
611
580
        func = SIG_IGN;
612
581
    }
613
 
    else if (TYPE(command) == T_STRING) {
614
 
        SafeStringValue(command);       /* taint check */
615
 
        if (RSTRING(command)->len == 0) {
616
 
            func = SIG_IGN;
617
 
        }
618
 
        else if (RSTRING(command)->len == 7) {
619
 
            if (strncmp(RSTRING(command)->ptr, "SIG_IGN", 7) == 0) {
620
 
                func = SIG_IGN;
621
 
            }
622
 
            else if (strncmp(RSTRING(command)->ptr, "SIG_DFL", 7) == 0) {
623
 
                func = SIG_DFL;
624
 
            }
625
 
            else if (strncmp(RSTRING(command)->ptr, "DEFAULT", 7) == 0) {
626
 
                func = SIG_DFL;
627
 
            }
628
 
        }
629
 
        else if (RSTRING(command)->len == 6) {
630
 
            if (strncmp(RSTRING(command)->ptr, "IGNORE", 6) == 0) {
631
 
                func = SIG_IGN;
632
 
            }
633
 
        }
634
 
        else if (RSTRING(command)->len == 4) {
635
 
            if (strncmp(RSTRING(command)->ptr, "EXIT", 4) == 0) {
636
 
                func = sigexit;
 
582
    else {
 
583
        command = rb_check_string_type(arg->cmd);
 
584
        if (!NIL_P(command)) {
 
585
            SafeStringValue(command);   /* taint check */
 
586
            switch (RSTRING(command)->len) {
 
587
              case 0:
 
588
                func = SIG_IGN;
 
589
                break;
 
590
              case 7:
 
591
                if (strncmp(RSTRING(command)->ptr, "SIG_IGN", 7) == 0) {
 
592
                    func = SIG_IGN;
 
593
                }
 
594
                else if (strncmp(RSTRING(command)->ptr, "SIG_DFL", 7) == 0) {
 
595
                    func = SIG_DFL;
 
596
                }
 
597
                else if (strncmp(RSTRING(command)->ptr, "DEFAULT", 7) == 0) {
 
598
                    func = SIG_DFL;
 
599
                }
 
600
                break;
 
601
              case 6:
 
602
                if (strncmp(RSTRING(command)->ptr, "IGNORE", 6) == 0) {
 
603
                    func = SIG_IGN;
 
604
                }
 
605
                break;
 
606
              case 4:
 
607
                if (strncmp(RSTRING(command)->ptr, "EXIT", 4) == 0) {
 
608
                    arg->cmd = Qundef;
 
609
                }
 
610
                break;
637
611
            }
638
612
        }
639
613
    }
640
614
    if (func == SIG_IGN || func == SIG_DFL) {
641
615
        command = 0;
642
616
    }
 
617
    else {
 
618
        command = arg->cmd;
 
619
    }
643
620
 
644
621
    switch (TYPE(arg->sig)) {
645
622
      case T_FIXNUM:
745
722
#endif
746
723
 
747
724
void
748
 
rb_trap_restore_mask()
 
725
rb_trap_restore_mask(void)
749
726
{
750
727
#ifndef _WIN32
751
728
# ifdef HAVE_SIGPROCMASK
785
762
 *     Terminating: 27460
786
763
 */
787
764
static VALUE
788
 
sig_trap(argc, argv)
789
 
    int argc;
790
 
    VALUE *argv;
 
765
sig_trap(int argc, VALUE *argv)
791
766
{
792
767
    struct trap_arg arg;
793
768
 
832
807
 * Signal.list   #=> {"ABRT"=>6, "ALRM"=>14, "BUS"=>7, "CHLD"=>17, "CLD"=>17, "CONT"=>18, "FPE"=>8, "HUP"=>1, "ILL"=>4, "INT"=>2, "IO"=>29, "IOT"=>6, "KILL"=>9, "PIPE"=>13, "POLL"=>29, "PROF"=>27, "PWR"=>30, "QUIT"=>3, "SEGV"=>11, "STOP"=>19, "SYS"=>31, "TERM"=>15, "TRAP"=>5, "TSTP"=>20, "TTIN"=>21, "TTOU"=>22, "URG"=>23, "USR1"=>10, "USR2"=>12, "VTALRM"=>26, "WINCH"=>28, "XCPU"=>24, "XFSZ"=>25}
833
808
 */
834
809
static VALUE
835
 
sig_list()
 
810
sig_list(void)
836
811
{
837
812
    VALUE h = rb_hash_new();
838
813
    struct signals *sigs;
844
819
}
845
820
 
846
821
static void
847
 
install_sighandler(signum, handler)
848
 
    int signum;
849
 
    sighandler_t handler;
 
822
install_sighandler(int signum, sighandler_t handler)
850
823
{
851
824
    sighandler_t old;
852
825
 
858
831
 
859
832
#ifdef HAVE_NATIVETHREAD
860
833
static void
861
 
install_nativethread_sighandler(signum, handler)
862
 
    int signum;
863
 
    sighandler_t handler;
 
834
install_nativethread_sighandler(int signum, sighandler_t handler)
864
835
{
865
836
    sighandler_t old;
866
837
    int old_st;
878
849
#endif
879
850
 
880
851
static void
881
 
init_sigchld(sig)
882
 
    int sig;
 
852
init_sigchld(int sig)
883
853
{
884
854
    sighandler_t oldfunc;
885
855
#ifndef _WIN32
957
927
 * systems; in particular signal delivery may not always be reliable.
958
928
 */
959
929
void
960
 
Init_signal()
 
930
Init_signal(void)
961
931
{
962
932
#ifndef MACOS_UNUSE_SIGNAL
963
933
    VALUE mSignal = rb_define_module("Signal");