summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-04 16:10:14 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-04 16:10:14 +0000
commitb3799b93c20c00865c1bd5885890291c0874f029 (patch)
tree6d7845695df7a66f7fd4dce02816de17d94c70d5
parent36f3e5ec8529d798088e4d104d31efc616da4014 (diff)
signal.c: packed signals
* signal.c (signals): pack signal names instead of references. * signal.c (signm2signo): also reject too long signal name. [ruby-core:87767] [Bug #14893] reapply r63841 and r63842, which are unrelated to r63758 but had been wrongly reverted by r63852. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--signal.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/signal.c b/signal.c
index c781c38c62c..d2231fe5ca4 100644
--- a/signal.c
+++ b/signal.c
@@ -66,8 +66,11 @@ ruby_atomic_compare_and_swap(rb_atomic_t *ptr, rb_atomic_t cmp,
# define NSIG (_SIGMAX + 1) /* For QNX */
#endif
+#define FOREACH_SIGNAL(sig, offset) \
+ for (sig = siglist + (offset); sig < siglist + numberof(siglist); ++sig)
+enum { LONGEST_SIGNAME = 7 }; /* MIGRATE and RETRACT */
static const struct signals {
- const char *signm;
+ char signm[LONGEST_SIGNAME + 1];
int signo;
} siglist [] = {
{"EXIT", 0},
@@ -202,7 +205,6 @@ static const struct signals {
#ifdef SIGINFO
{"INFO", SIGINFO},
#endif
- {NULL, 0}
};
static const char signame_prefix[3] = "SIG";
@@ -214,7 +216,7 @@ signm2signo(VALUE *sig_ptr, int negative, int exit, int *prefix_ptr)
const struct signals *sigs;
VALUE vsig = *sig_ptr;
const char *nm;
- long len;
+ long len, nmlen;
int prefix = 0;
if (RB_SYMBOL_P(vsig)) {
@@ -268,9 +270,12 @@ signm2signo(VALUE *sig_ptr, int negative, int exit, int *prefix_ptr)
}
if (prefix_ptr) *prefix_ptr = prefix;
- for (sigs = siglist + !exit; sigs->signm; sigs++) {
- if (memcmp(sigs->signm, nm + prefix, len - prefix) == 0 &&
- sigs->signm[len - prefix] == '\0') {
+ nmlen = len - prefix;
+ nm += prefix;
+ if (nmlen > LONGEST_SIGNAME) goto unsupported;
+ FOREACH_SIGNAL(sigs, !exit) {
+ if (memcmp(sigs->signm, nm, nmlen) == 0 &&
+ sigs->signm[nmlen] == '\0') {
return negative ? -sigs->signo : sigs->signo;
}
}
@@ -282,9 +287,10 @@ signo2signm(int no)
{
const struct signals *sigs;
- for (sigs = siglist; sigs->signm; sigs++)
+ FOREACH_SIGNAL(sigs, 0) {
if (sigs->signo == no)
return sigs->signm;
+ }
return 0;
}
@@ -1384,7 +1390,7 @@ sig_list(void)
VALUE h = rb_hash_new();
const struct signals *sigs;
- for (sigs = siglist; sigs->signm; sigs++) {
+ FOREACH_SIGNAL(sigs, 0) {
rb_hash_aset(h, rb_fstring_cstr(sigs->signm), INT2FIX(sigs->signo));
}
return h;