From db26a9b105f0e2b4850c45554c1e77aa35973ef4 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 16 Jan 2008 06:26:33 +0000 Subject: * load.c (rb_feature_p): get rid of unlimited alloca. * object.c (rb_cstr_to_dbl): ditto. * io.c (mode_enc): fixed uninitialized variable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 14 +++++++++++++- io.c | 7 ++++--- load.c | 6 +++++- object.c | 12 +++++++----- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 47fa70bbb2..ab82c1a94c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,21 @@ -Wed Jan 16 14:55:15 2008 Nobuyoshi Nakada +Wed Jan 16 15:26:31 2008 Nobuyoshi Nakada + + * load.c (rb_feature_p): get rid of unlimited alloca. + + * object.c (rb_cstr_to_dbl): ditto. + + * io.c (mode_enc): fixed uninitialized variable. * file.c (sys_fail2): get rid of unlimited alloca. * io.c (mode_enc, pipe_open, rb_io_s_popen): ditto. + * load.c (rb_feature_p): ditto. + + * object.c (rb_cstr_to_dbl): ditto. + + * io.c (mode_enc): fixed uninitialized variable. + Wed Jan 16 12:51:30 2008 Nobuyoshi Nakada * include/ruby/intern.h (rb_str_tmp_new, rb_str_shared_replace): diff --git a/io.c b/io.c index 75c1fa3025..f1ce12e865 100644 --- a/io.c +++ b/io.c @@ -3192,14 +3192,15 @@ mode_enc(rb_io_t *fptr, const char *estr) enc2name = ALLOCA_N(char, n+1); memcpy(enc2name, estr, n); enc2name[n] = '\0'; + estr = enc2name; idx2 = rb_enc_find_index(enc2name); } if (idx2 < 0) { - rb_warn("Unsupported encoding %s ignored", enc2name); + rb_warn("Unsupported encoding %.*s ignored", n, estr); } else if (idx2 == idx) { - rb_warn("Ignoring internal encoding %s: it is identical to external encoding %s", - enc2name, p1); + rb_warn("Ignoring internal encoding %.*s: it is identical to external encoding %s", + n, estr, p1); } else { fptr->enc2 = rb_enc_from_index(idx2); diff --git a/load.c b/load.c index 541e6c81bc..1d10589611 100644 --- a/load.c +++ b/load.c @@ -166,18 +166,22 @@ rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const c return !IS_RBEXT(ext) ? 's' : 'r'; } else { + VALUE bufstr; char *buf; if (ext && *ext) return 0; - buf = ALLOCA_N(char, len + DLEXT_MAXLEN + 1); + bufstr = rb_str_tmp_new(len + DLEXT_MAXLEN); + buf = RSTRING_PTR(bufstr); MEMCPY(buf, feature, char, len); for (i = 0; (e = loadable_ext[i]) != 0; i++) { strncpy(buf + len, e, DLEXT_MAXLEN + 1); if (st_get_key(loading_tbl, (st_data_t)buf, &data)) { + rb_str_resize(bufstr, 0); if (fn) *fn = (const char*)data; return i ? 's' : 'r'; } } + rb_str_resize(bufstr, 0); } } return 0; diff --git a/object.c b/object.c index ae0cdd98b7..ddf02b298b 100644 --- a/object.c +++ b/object.c @@ -19,6 +19,7 @@ #include #include #include +#include VALUE rb_cBasicObject; VALUE rb_mKernel; @@ -2048,15 +2049,16 @@ rb_cstr_to_dbl(const char *p, int badcheck) return d; } if (*end) { - char *buf = ALLOCA_N(char, strlen(p)+1); + char buf[DBL_DIG * 4 + 10]; char *n = buf; + char *e = buf + sizeof(buf) - 1; - while (p < end) *n++ = *p++; - while (*p) { + while (p < end && n < e) *n++ = *p++; + while (n < e && *p) { if (*p == '_') { /* remove underscores between digits */ - if (n == buf || !ISDIGIT(n[-1])) goto bad; - while (*++p == '_'); + if (n == buf || !ISDIGIT(n[-1])) goto bad; + while (*++p == '_'); if (!ISDIGIT(*p)) { if (badcheck) goto bad; break; -- cgit v1.2.3