Project

General

Profile

Bug #199 » 1.8.6p111_sedov_and_lai_backport.patch

Anonymous, 06/25/2008 10:04 AM

View differences:

array.c
static ID id_cmp;
#define ARY_DEFAULT_SIZE 16
#define ARY_MAX_SIZE (LONG_MAX / sizeof(VALUE))
void
rb_mem_clear(mem, size)
......
if (len < 0) {
rb_raise(rb_eArgError, "negative array size (or size too big)");
}
if (len > 0 && len * sizeof(VALUE) <= len) {
if (len > ARY_MAX_SIZE) {
rb_raise(rb_eArgError, "array size too big");
}
if (len == 0) len++;
......
if (len < 0) {
rb_raise(rb_eArgError, "negative array size");
}
if (len > 0 && len * (long)sizeof(VALUE) <= len) {
if (len > ARY_MAX_SIZE) {
rb_raise(rb_eArgError, "array size too big");
}
if (len > RARRAY(ary)->aux.capa) {
......
}
}
if (idx >= ARY_MAX_SIZE) {
rb_raise(rb_eIndexError, "index %ld too big", idx);
}
rb_ary_modify(ary);
if (idx >= RARRAY(ary)->aux.capa) {
long new_capa = RARRAY(ary)->aux.capa / 2;
......
if (new_capa < ARY_DEFAULT_SIZE) {
new_capa = ARY_DEFAULT_SIZE;
}
if (new_capa >= ARY_MAX_SIZE - idx) {
new_capa = (ARY_MAX_SIZE - idx) / 2;
}
new_capa += idx;
if (new_capa * (long)sizeof(VALUE) <= new_capa) {
rb_raise(rb_eArgError, "index too big");
......
rb_ary_modify(ary);
if (beg >= RARRAY(ary)->len) {
if (beg > ARY_MAX_SIZE - rlen) {
rb_raise(rb_eIndexError, "index %ld too big", beg);
}
len = beg + rlen;
if (len >= RARRAY(ary)->aux.capa) {
REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
......
if (len < 0) {
rb_raise(rb_eArgError, "negative argument");
}
if (LONG_MAX/len < RARRAY(ary)->len) {
if (ARY_MAX_SIZE/len < RARRAY(ary)->len) {
rb_raise(rb_eArgError, "argument too big");
}
len *= RARRAY(ary)->len;
bignum.c
#define BIGLO(x) ((BDIGIT)((x) & (BIGRAD-1)))
#define BDIGMAX ((BDIGIT)-1)
#define BIGZEROP(x) (RBIGNUM(x)->len == 0 || (RBIGNUM(x)->len == 1 && BDIGITS(x)[0] == 0))
#define BIGZEROP(x) (RBIGNUM(x)->len == 0 || \
(BDIGITS(x)[0] == 0 && \
(RBIGNUM(x)->len == 1 || bigzero_p(x))))
static int bigzero_p(VALUE);
static int
bigzero_p(x)
VALUE x;
{
long i;
for (i = 0; i < RBIGNUM(x)->len; ++i) {
if (BDIGITS(x)[i]) return 0;
}
return 1;
}
static VALUE
bignew_1(klass, len, sign)
......
}
if (*str == '0') { /* squeeze preceeding 0s */
while (*++str == '0');
if (!*str) --str;
if (!(c = *str) || ISSPACE(c)) --str;
}
c = *str;
c = conv_digit(c);
......
if (BIGZEROP(x)) {
return rb_str_new2("0");
}
if (i >= LONG_MAX/SIZEOF_BDIGITS/CHAR_BIT) {
rb_raise(rb_eRangeError, "bignum too big to convert into `string'");
}
j = SIZEOF_BDIGITS*CHAR_BIT*i;
switch (base) {
case 2: break;
......
while (k--) {
s[--j] = ruby_digitmap[num % base];
num /= base;
if (!trim && j < 1) break;
if (!trim && j <= 1) break;
if (trim && i == 0 && num == 0) break;
}
}
eval.c
* MISSING: documentation
*/
#define PROC_TSHIFT (FL_USHIFT+1)
#define PROC_TMASK (FL_USER1|FL_USER2|FL_USER3)
#define PROC_TMAX (PROC_TMASK >> PROC_TSHIFT)
static int proc_get_safe_level(VALUE);
static VALUE
proc_dup(self)
VALUE self;
{
struct BLOCK *orig, *data;
VALUE bind;
int safe = proc_get_safe_level(self);
Data_Get_Struct(self, struct BLOCK, orig);
bind = Data_Make_Struct(rb_obj_class(self),struct BLOCK,blk_mark,blk_free,data);
blk_dup(data, orig);
if (safe > PROC_TMAX) safe = PROC_TMAX;
FL_SET(bind, (safe << PROC_TSHIFT) & PROC_TMASK);
return bind;
}
......
return bind;
}
#define PROC_TSHIFT (FL_USHIFT+1)
#define PROC_TMASK (FL_USER1|FL_USER2|FL_USER3)
#define PROC_TMAX (PROC_TMASK >> PROC_TSHIFT)
#define SAFE_LEVEL_MAX PROC_TMASK
static void
intern.h
void ruby_default_signal _((int));
/* sprintf.c */
VALUE rb_f_sprintf _((int, VALUE*));
VALUE rb_str_format _((int, VALUE*, VALUE));
/* string.c */
VALUE rb_str_new _((const char*, long));
VALUE rb_str_new2 _((const char*));
io.c
#if !defined(MSDOS) && !defined(__human68k__)
static int
io_cntl(fd, cmd, narg, io_p)
int fd, cmd, io_p;
int fd, io_p;
long narg;
unsigned long cmd;
{
int retval;
......
int io_p;
{
#if !defined(MSDOS) && !defined(__human68k__)
int cmd = NUM2ULONG(req);
unsigned long cmd = NUM2ULONG(req);
OpenFile *fptr;
long len = 0;
long narg = 0;
lib/webrick/httpservlet/filehandler.rb
end
end
end
prevent_directory_traversal(req, res)
super(req, res)
end
......
private
def prevent_directory_traversal(req, res)
# Preventing directory traversal on DOSISH platforms;
# Backslashes (0x5c) in path_info are not interpreted as special
# character in URI notation. So the value of path_info should be
# normalize before accessing to the filesystem.
if File::ALT_SEPARATOR
# File.expand_path removes the trailing path separator.
# Adding a character is a workaround to save it.
# File.expand_path("/aaa/") #=> "/aaa"
# File.expand_path("/aaa/" + "x") #=> "/aaa/x"
expanded = File.expand_path(req.path_info + "x")
expanded[-1, 1] = "" # remove trailing "x"
req.path_info = expanded
end
end
def exec_handler(req, res)
raise HTTPStatus::NotFound, "`#{req.path}' not found" unless @root
if set_filename(req, res)
......
def check_filename(req, res, name)
@options[:NondisclosureName].each{|pattern|
if File.fnmatch("/#{pattern}", name)
if File.fnmatch("/#{pattern}", name, File::FNM_CASEFOLD)
@logger.warn("the request refers nondisclosure name `#{name}'.")
raise HTTPStatus::NotFound, "`#{req.path}' not found."
end
......
def nondisclosure_name?(name)
@options[:NondisclosureName].each{|pattern|
if File.fnmatch(pattern, name)
if File.fnmatch(pattern, name, File::FNM_CASEFOLD)
return true
end
}
sprintf.c
int argc;
VALUE *argv;
{
return rb_str_format(argc - 1, argv + 1, GETNTHARG(0));
}
VALUE
rb_str_format(argc, argv, fmt)
int argc;
VALUE *argv;
VALUE fmt;
{
const char *p, *end;
char *buf;
int blen, bsiz;
......
rb_raise(rb_eArgError, "flag after precision"); \
}
fmt = GETNTHARG(0);
++argc;
--argv;
if (OBJ_TAINTED(fmt)) tainted = 1;
StringValue(fmt);
fmt = rb_str_new4(fmt);
string.c
*/
static VALUE
rb_str_format(str, arg)
rb_str_format_m(str, arg)
VALUE str, arg;
{
VALUE *argv;
VALUE tmp = rb_check_array_type(arg);
if (TYPE(arg) == T_ARRAY) {
argv = ALLOCA_N(VALUE, RARRAY(arg)->len + 1);
argv[0] = str;
MEMCPY(argv+1, RARRAY(arg)->ptr, VALUE, RARRAY(arg)->len);
return rb_f_sprintf(RARRAY(arg)->len+1, argv);
if (!NIL_P(tmp)) {
return rb_str_format(RARRAY_LEN(tmp), RARRAY_PTR(tmp), str);
}
argv = ALLOCA_N(VALUE, 2);
argv[0] = str;
argv[1] = arg;
return rb_f_sprintf(2, argv);
return rb_str_format(1, &arg, str);
}
static int
......
return str;
}
VALUE
rb_str_buf_cat(str, ptr, len)
static VALUE
str_buf_cat(str, ptr, len)
VALUE str;
const char *ptr;
long len;
{
long capa, total;
if (len == 0) return str;
if (len < 0) {
rb_raise(rb_eArgError, "negative string size (or size too big)");
}
rb_str_modify(str);
if (FL_TEST(str, STR_ASSOC)) {
FL_UNSET(str, STR_ASSOC);
......
else {
capa = RSTRING(str)->aux.capa;
}
if (RSTRING(str)->len >= LONG_MAX - len) {
rb_raise(rb_eArgError, "string sizes too big");
}
total = RSTRING(str)->len+len;
if (capa <= total) {
while (total > capa) {
if (capa + 1 >= LONG_MAX / 2) {
capa = total;
break;
}
capa = (capa + 1) * 2;
}
RESIZE_CAPA(str, capa);
......
}
VALUE
rb_str_buf_cat(str, ptr, len)
VALUE str;
const char *ptr;
long len;
{
if (len == 0) return str;
if (len < 0) {
rb_raise(rb_eArgError, "negative string size (or size too big)");
}
return str_buf_cat(str, ptr, len);
}
VALUE
rb_str_buf_cat2(str, ptr)
VALUE str;
const char *ptr;
......
}
if (FL_TEST(str, STR_ASSOC)) {
rb_str_modify(str);
REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len+len);
REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len+len+1);
memcpy(RSTRING(str)->ptr + RSTRING(str)->len, ptr, len);
RSTRING(str)->len += len;
RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; /* sentinel */
......
rb_str_buf_append(str, str2)
VALUE str, str2;
{
long capa, len;
rb_str_modify(str);
if (FL_TEST(str, STR_ASSOC)) {
FL_UNSET(str, STR_ASSOC);
capa = RSTRING(str)->aux.capa = RSTRING(str)->len;
}
else {
capa = RSTRING(str)->aux.capa;
}
len = RSTRING(str)->len+RSTRING(str2)->len;
if (capa <= len) {
while (len > capa) {
capa = (capa + 1) * 2;
}
RESIZE_CAPA(str, capa);
}
memcpy(RSTRING(str)->ptr + RSTRING(str)->len,
RSTRING(str2)->ptr, RSTRING(str2)->len);
RSTRING(str)->len += RSTRING(str2)->len;
RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; /* sentinel */
str_buf_cat(str, RSTRING(str2)->ptr, RSTRING(str2)->len);
OBJ_INFECT(str, str2);
return str;
}
......
rb_define_method(rb_cString, "casecmp", rb_str_casecmp, 1);
rb_define_method(rb_cString, "+", rb_str_plus, 1);
rb_define_method(rb_cString, "*", rb_str_times, 1);
rb_define_method(rb_cString, "%", rb_str_format, 1);
rb_define_method(rb_cString, "%", rb_str_format_m, 1);
rb_define_method(rb_cString, "[]", rb_str_aref_m, -1);
rb_define_method(rb_cString, "[]=", rb_str_aset_m, -1);
rb_define_method(rb_cString, "insert", rb_str_insert, 2);
(2-2/5)