зеркало из https://github.com/github/ruby.git
* signal.c (trap): remove sigexit(); handle "EXIT" via sig_exec().
[ruby-dev:26440] * io.c (rb_io_inspect): replace sprintf() with "%s" format all over the place by snprintf() to avoid integer overflow. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8800 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
1fb55b9d77
Коммит
2031602787
|
@ -1,3 +1,11 @@
|
|||
Tue Jul 19 17:16:34 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* signal.c (trap): remove sigexit(); handle "EXIT" via sig_exec().
|
||||
[ruby-dev:26440]
|
||||
|
||||
* io.c (rb_io_inspect): replace sprintf() with "%s" format all
|
||||
over the place by snprintf() to avoid integer overflow.
|
||||
|
||||
Tue Jul 19 14:10:50 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||
|
||||
* ext/tk/tcltklib.c: rbtk_eventloop_depth is used as int.
|
||||
|
|
5
dln.c
5
dln.c
|
@ -962,8 +962,9 @@ load_lib(lib)
|
|||
dln_errno = DLN_EBADLIB;
|
||||
|
||||
if (lib[0] == '-' && lib[1] == 'l') {
|
||||
char *p = alloca(strlen(lib) + 4);
|
||||
sprintf(p, "lib%s.a", lib+2);
|
||||
long len = strlen(lib) + 4;
|
||||
char *p = alloca(len);
|
||||
snprintf(p, len, "lib%s.a", lib+2);
|
||||
lib = p;
|
||||
}
|
||||
|
||||
|
|
5
error.c
5
error.c
|
@ -956,9 +956,10 @@ syserr_initialize(argc, argv, self)
|
|||
else err = "unknown error";
|
||||
if (!NIL_P(mesg)) {
|
||||
VALUE str = mesg;
|
||||
size_t len = strlen(err)+RSTRING(str)->len+3;
|
||||
StringValue(str);
|
||||
mesg = rb_str_new(0, strlen(err)+RSTRING(str)->len+3);
|
||||
sprintf(RSTRING(mesg)->ptr, "%s - %.*s", err,
|
||||
mesg = rb_str_new(0, len);
|
||||
snprintf(RSTRING(mesg)->ptr, len, "%s - %.*s", err,
|
||||
(int)RSTRING(str)->len, RSTRING(str)->ptr);
|
||||
rb_str_resize(mesg, strlen(RSTRING(mesg)->ptr));
|
||||
}
|
||||
|
|
17
eval.c
17
eval.c
|
@ -669,6 +669,7 @@ rb_attr(klass, id, read, write, ex)
|
|||
char *buf;
|
||||
ID attriv;
|
||||
int noex;
|
||||
size_t len;
|
||||
|
||||
if (!ex) noex = NOEX_PUBLIC;
|
||||
else {
|
||||
|
@ -693,8 +694,9 @@ rb_attr(klass, id, read, write, ex)
|
|||
if (!name) {
|
||||
rb_raise(rb_eArgError, "argument needs to be symbol or string");
|
||||
}
|
||||
buf = ALLOCA_N(char,strlen(name)+2);
|
||||
sprintf(buf, "@%s", name);
|
||||
len = strlen(name)+2;
|
||||
buf = ALLOCA_N(char,len);
|
||||
snprintf(buf, len, "@%s", name);
|
||||
attriv = rb_intern(buf);
|
||||
if (read) {
|
||||
rb_add_method(klass, id, NEW_IVAR(attriv), noex);
|
||||
|
@ -8672,12 +8674,14 @@ proc_to_s(self)
|
|||
if ((node = data->frame.node) || (node = data->body)) {
|
||||
len += strlen(node->nd_file) + 2 + (SIZEOF_LONG*CHAR_BIT-NODE_LSHIFT)/3;
|
||||
str = rb_str_new(0, len);
|
||||
sprintf(RSTRING(str)->ptr, "#<%s:0x%.*lx@%s:%d>", cname, w, (VALUE)data->body,
|
||||
snprintf(RSTRING(str)->ptr, len,
|
||||
"#<%s:0x%.*lx@%s:%d>", cname, w, (VALUE)data->body,
|
||||
node->nd_file, nd_line(node));
|
||||
}
|
||||
else {
|
||||
str = rb_str_new(0, len);
|
||||
sprintf(RSTRING(str)->ptr, "#<%s:0x%.*lx>", cname, w, (VALUE)data->body);
|
||||
snprintf(RSTRING(str)->ptr, len,
|
||||
"#<%s:0x%.*lx>", cname, w, (VALUE)data->body);
|
||||
}
|
||||
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
|
||||
if (OBJ_TAINTED(self)) OBJ_TAINT(str);
|
||||
|
@ -12757,9 +12761,10 @@ rb_thread_inspect(thread)
|
|||
rb_thread_t th = rb_thread_check(thread);
|
||||
const char *status = thread_status_name(th->status);
|
||||
VALUE str;
|
||||
size_t len = strlen(cname)+7+16+9+1;
|
||||
|
||||
str = rb_str_new(0, strlen(cname)+7+16+9+1); /* 7:tags 16:addr 9:status 1:nul */
|
||||
sprintf(RSTRING(str)->ptr, "#<%s:0x%lx %s>", cname, thread, status);
|
||||
str = rb_str_new(0, len); /* 7:tags 16:addr 9:status 1:nul */
|
||||
snprintf(RSTRING(str)->ptr, len, "#<%s:0x%lx %s>", cname, thread, status);
|
||||
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
|
||||
OBJ_INFECT(str, thread);
|
||||
|
||||
|
|
7
hash.c
7
hash.c
|
@ -1809,7 +1809,7 @@ ruby_setenv(name, value)
|
|||
else
|
||||
unsetenv(name);
|
||||
#else /* WIN32 */
|
||||
|
||||
size_t len;
|
||||
int i=envix(name); /* where does it go? */
|
||||
|
||||
if (environ == origenviron) { /* need we copy environment? */
|
||||
|
@ -1842,9 +1842,10 @@ ruby_setenv(name, value)
|
|||
REALLOC_N(environ, char*, i+2); /* just expand it a bit */
|
||||
environ[i+1] = 0; /* make sure it's null terminated */
|
||||
}
|
||||
environ[i] = ALLOC_N(char, strlen(name) + strlen(value) + 2);
|
||||
len = strlen(name) + strlen(value) + 2;
|
||||
environ[i] = ALLOC_N(char, len);
|
||||
#ifndef MSDOS
|
||||
sprintf(environ[i],"%s=%s",name,value); /* all that work just for this */
|
||||
snprintf(environ[i],len,"%s=%s",name,value); /* all that work just for this */
|
||||
#else
|
||||
/* MS-DOS requires environment variable names to be in uppercase */
|
||||
/* [Tom Dinger, 27 August 1990: Well, it doesn't _require_ it, but
|
||||
|
|
2
io.c
2
io.c
|
@ -1098,7 +1098,7 @@ rb_io_inspect(obj)
|
|||
len += 9;
|
||||
}
|
||||
buf = ALLOCA_N(char, len);
|
||||
sprintf(buf, "#<%s:%s%s>", cname, fptr->path, st);
|
||||
snprintf(buf, len, "#<%s:%s%s>", cname, fptr->path, st);
|
||||
return rb_str_new2(buf);
|
||||
}
|
||||
|
||||
|
|
12
object.c
12
object.c
|
@ -298,10 +298,12 @@ rb_any_to_s(obj)
|
|||
VALUE obj;
|
||||
{
|
||||
char *cname = rb_obj_classname(obj);
|
||||
size_t len;
|
||||
VALUE str;
|
||||
|
||||
str = rb_str_new(0, strlen(cname)+6+16+1); /* 6:tags 16:addr 1:nul */
|
||||
sprintf(RSTRING(str)->ptr, "#<%s:0x%lx>", cname, obj);
|
||||
len = strlen(cname)+6+16+1;
|
||||
str = rb_str_new(0, len); /* 6:tags 16:addr 1:nul */
|
||||
snprintf(RSTRING(str)->ptr, len, "#<%s:0x%lx>", cname, obj);
|
||||
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
|
||||
if (OBJ_TAINTED(obj)) OBJ_TAINT(str);
|
||||
|
||||
|
@ -383,11 +385,13 @@ rb_obj_inspect(obj)
|
|||
&& ROBJECT(obj)->iv_tbl
|
||||
&& ROBJECT(obj)->iv_tbl->num_entries > 0) {
|
||||
VALUE str;
|
||||
size_t len;
|
||||
char *c;
|
||||
|
||||
c = rb_obj_classname(obj);
|
||||
str = rb_str_new(0, strlen(c)+10+16+1); /* 10:tags 16:addr 1:nul */
|
||||
sprintf(RSTRING(str)->ptr, "-<%s:0x%lx", c, obj);
|
||||
len = strlen(c)+10+16+1;
|
||||
str = rb_str_new(0, len); /* 10:tags 16:addr 1:nul */
|
||||
snprintf(RSTRING(str)->ptr, len, "-<%s:0x%lx", c, obj);
|
||||
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
|
||||
return rb_exec_recursive(inspect_obj, obj, str);
|
||||
}
|
||||
|
|
28
signal.c
28
signal.c
|
@ -424,6 +424,9 @@ signal_exec(sig)
|
|||
break;
|
||||
}
|
||||
}
|
||||
else if (trap_list[sig].cmd == Qundef) {
|
||||
rb_thread_signal_exit();
|
||||
}
|
||||
else {
|
||||
rb_thread_trap_eval(trap_list[sig].cmd, sig, trap_list[sig].safe);
|
||||
}
|
||||
|
@ -581,29 +584,6 @@ static sigset_t trap_last_mask;
|
|||
static int trap_last_mask;
|
||||
# endif
|
||||
|
||||
static RETSIGTYPE sigexit _((int));
|
||||
static RETSIGTYPE
|
||||
sigexit(sig)
|
||||
int sig;
|
||||
{
|
||||
#if defined(HAVE_NATIVETHREAD) && defined(HAVE_NATIVETHREAD_KILL)
|
||||
if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
|
||||
sigsend_to_ruby_thread(sig);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (trap_list[sig].cmd == 0 && ATOMIC_TEST(rb_trap_immediate)) {
|
||||
IN_MAIN_CONTEXT(signal_exec, sig);
|
||||
ATOMIC_SET(rb_trap_immediate, 1);
|
||||
}
|
||||
else {
|
||||
ATOMIC_INC(rb_trap_pending);
|
||||
ATOMIC_INC(trap_pending_list[sig]);
|
||||
}
|
||||
rb_thread_signal_exit();
|
||||
}
|
||||
|
||||
static VALUE
|
||||
trap(arg)
|
||||
struct trap_arg *arg;
|
||||
|
@ -643,7 +623,7 @@ trap(arg)
|
|||
break;
|
||||
case 4:
|
||||
if (strncmp(RSTRING(command)->ptr, "EXIT", 4) == 0) {
|
||||
func = sigexit;
|
||||
arg->cmd = Qundef;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
5
struct.c
5
struct.c
|
@ -477,9 +477,10 @@ inspect_struct(s, dummy, recur)
|
|||
|
||||
if (recur) {
|
||||
char *cname = rb_class2name(rb_obj_class(s));
|
||||
VALUE str = rb_str_new(0, strlen(cname) + 15);
|
||||
size_t len = strlen(cname) + 15;
|
||||
VALUE str = rb_str_new(0, len);
|
||||
|
||||
sprintf(RSTRING(str)->ptr, "#<struct %s:...>", cname);
|
||||
snprintf(RSTRING(str)->ptr, len, "#<struct %s:...>", cname);
|
||||
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
|
||||
return str;
|
||||
}
|
||||
|
|
|
@ -196,6 +196,7 @@ rb_class_path(klass)
|
|||
}
|
||||
else {
|
||||
char *s = "Class";
|
||||
size_t len;
|
||||
|
||||
if (TYPE(klass) == T_MODULE) {
|
||||
if (rb_obj_class(klass) == rb_cModule) {
|
||||
|
@ -205,8 +206,9 @@ rb_class_path(klass)
|
|||
s = rb_class2name(RBASIC(klass)->klass);
|
||||
}
|
||||
}
|
||||
path = rb_str_new(0, 2 + strlen(s) + 3 + 2 * SIZEOF_LONG + 1);
|
||||
sprintf(RSTRING(path)->ptr, "#<%s:0x%lx>", s, klass);
|
||||
len = 2 + strlen(s) + 3 + 2 * SIZEOF_LONG + 1;
|
||||
path = rb_str_new(0, len);
|
||||
snprintf(RSTRING(path)->ptr, len, "#<%s:0x%lx>", s, klass);
|
||||
RSTRING(path)->len = strlen(RSTRING(path)->ptr);
|
||||
rb_ivar_set(klass, tmp_classpath, path);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче