Skip to content

Commit db8a496

Browse files
author
matz
committed
* process.c (proc_getpgrp): prohibit for $SAFE=2.
[ruby-dev:24899] * process.c (get_pid): ditto. [ruby-dev:24904] * process.c (get_ppid): ditto. * array.c (rb_ary_delete): defer rb_ary_modify() until actual modification. [ruby-dev:24901] * parse.y (newline_node): should not use FL_SET. [ruby-dev:24874] * parse.y (string_content): should not use FL_UNSET. * node.h (NODE_NEWLINE): remove unused bit to utilize flag field in nodes. * string.c (rb_str_splice): move rb_str_modify() after StringValue(), which may alter the receiver. [ruby-dev:24878] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 1fff70f commit db8a496

File tree

5 files changed

+74
-58
lines changed

5 files changed

+74
-58
lines changed

ChangeLog

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
Thu Nov 18 00:21:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
2+
3+
* process.c (proc_getpgrp): prohibit for $SAFE=2.
4+
[ruby-dev:24899]
5+
6+
* process.c (get_pid): ditto. [ruby-dev:24904]
7+
8+
* process.c (get_ppid): ditto.
9+
10+
* array.c (rb_ary_delete): defer rb_ary_modify() until actual
11+
modification. [ruby-dev:24901]
12+
113
Thu Nov 18 10:10:14 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
214

315
* io.c, rubyio.h (rb_io_modenum_flags): exported.
@@ -9,6 +21,15 @@ Wed Nov 17 23:42:40 2004 NAKAMURA, Hiroshi <nakahiro@sarion.co.jp>
921

1022
* test/ruby/test_settracefunc.rb: added. [ruby-dev:24884]
1123

24+
Wed Nov 17 13:56:57 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
25+
26+
* parse.y (newline_node): should not use FL_SET. [ruby-dev:24874]
27+
28+
* parse.y (string_content): should not use FL_UNSET.
29+
30+
* node.h (NODE_NEWLINE): remove unused bit to utilize flag field
31+
in nodes.
32+
1233
Wed Nov 17 13:09:40 2004 NAKAMURA Usaku <usa@ruby-lang.org>
1334

1435
* {bcc32,win32,wince}/Makefile.sub (test): should build ruby.exe
@@ -20,6 +41,11 @@ Wed Nov 17 04:33:01 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
2041

2142
* bignum.c (rb_big2ulong_pack): new function to pack Bignums.
2243

44+
Wed Nov 17 03:42:45 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
45+
46+
* string.c (rb_str_splice): move rb_str_modify() after
47+
StringValue(), which may alter the receiver. [ruby-dev:24878]
48+
2349
Tue Nov 16 23:45:07 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
2450

2551
* numeric.c (flo_divmod): protect float values from GC by

array.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ rb_ary_initialize(argc, argv, ary)
270270
long len;
271271
VALUE size, val;
272272

273-
rb_ary_modify(ary);
274273
if (rb_scan_args(argc, argv, "02", &size, &val) == 0) {
275274
RARRAY(ary)->len = 0;
276275
if (rb_block_given_p()) {
@@ -294,6 +293,7 @@ rb_ary_initialize(argc, argv, ary)
294293
if (len > 0 && len * (long)sizeof(VALUE) <= len) {
295294
rb_raise(rb_eArgError, "array size too big");
296295
}
296+
rb_ary_modify(ary);
297297
if (len > RARRAY(ary)->aux.capa) {
298298
REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
299299
RARRAY(ary)->aux.capa = len;
@@ -352,7 +352,6 @@ rb_ary_store(ary, idx, val)
352352
long idx;
353353
VALUE val;
354354
{
355-
rb_ary_modify(ary);
356355
if (idx < 0) {
357356
idx += RARRAY(ary)->len;
358357
if (idx < 0) {
@@ -361,6 +360,7 @@ rb_ary_store(ary, idx, val)
361360
}
362361
}
363362

363+
rb_ary_modify(ary);
364364
if (idx >= RARRAY(ary)->aux.capa) {
365365
long new_capa = RARRAY(ary)->aux.capa / 2;
366366

@@ -938,7 +938,7 @@ rb_ary_to_ary(obj)
938938
}
939939

940940
static void
941-
rb_ary_update(ary, beg, len, rpl)
941+
rb_ary_splice(ary, beg, len, rpl)
942942
VALUE ary;
943943
long beg, len;
944944
VALUE rpl;
@@ -1045,7 +1045,7 @@ rb_ary_aset(argc, argv, ary)
10451045
if (SYMBOL_P(argv[1])) {
10461046
rb_raise(rb_eTypeError, "Symbol as subarray length");
10471047
}
1048-
rb_ary_update(ary, NUM2LONG(argv[0]), NUM2LONG(argv[1]), argv[2]);
1048+
rb_ary_splice(ary, NUM2LONG(argv[0]), NUM2LONG(argv[1]), argv[2]);
10491049
return argv[2];
10501050
}
10511051
if (argc != 2) {
@@ -1060,7 +1060,7 @@ rb_ary_aset(argc, argv, ary)
10601060
}
10611061
if (rb_range_beg_len(argv[0], &beg, &len, RARRAY(ary)->len, 1)) {
10621062
/* check if idx is Range */
1063-
rb_ary_update(ary, beg, len, argv[1]);
1063+
rb_ary_splice(ary, beg, len, argv[1]);
10641064
return argv[1];
10651065
}
10661066

@@ -1102,7 +1102,7 @@ rb_ary_insert(argc, argv, ary)
11021102
}
11031103

11041104
if (argc == 1) return ary;
1105-
rb_ary_update(ary, pos, 0, rb_ary_new4(argc - 1, argv + 1));
1105+
rb_ary_splice(ary, pos, 0, rb_ary_new4(argc - 1, argv + 1));
11061106
return ary;
11071107
}
11081108

@@ -1849,7 +1849,6 @@ rb_ary_delete(ary, item)
18491849
{
18501850
long i1, i2;
18511851

1852-
rb_ary_modify(ary);
18531852
for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
18541853
VALUE e = RARRAY(ary)->ptr[i1];
18551854

@@ -1866,6 +1865,7 @@ rb_ary_delete(ary, item)
18661865
return Qnil;
18671866
}
18681867

1868+
rb_ary_modify(ary);
18691869
if (RARRAY(ary)->len > i2) {
18701870
RARRAY(ary)->len = i2;
18711871
if (i2 * 2 < RARRAY(ary)->aux.capa &&
@@ -1886,13 +1886,13 @@ rb_ary_delete_at(ary, pos)
18861886
long i, len = RARRAY(ary)->len;
18871887
VALUE del;
18881888

1889-
rb_ary_modify(ary);
18901889
if (pos >= len) return Qnil;
18911890
if (pos < 0) {
18921891
pos += len;
18931892
if (pos < 0) return Qnil;
18941893
}
18951894

1895+
rb_ary_modify(ary);
18961896
del = RARRAY(ary)->ptr[pos];
18971897
for (i = pos + 1; i < len; i++, pos++) {
18981898
RARRAY(ary)->ptr[pos] = RARRAY(ary)->ptr[i];
@@ -1957,7 +1957,6 @@ rb_ary_slice_bang(argc, argv, ary)
19571957
VALUE arg1, arg2;
19581958
long pos, len;
19591959

1960-
rb_ary_modify(ary);
19611960
if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2) {
19621961
pos = NUM2LONG(arg1);
19631962
len = NUM2LONG(arg2);
@@ -1966,7 +1965,7 @@ rb_ary_slice_bang(argc, argv, ary)
19661965
pos = RARRAY(ary)->len + pos;
19671966
}
19681967
arg2 = rb_ary_subseq(ary, pos, len);
1969-
rb_ary_update(ary, pos, len, Qnil); /* Qnil/rb_ary_new2(0) */
1968+
rb_ary_splice(ary, pos, len, Qnil); /* Qnil/rb_ary_new2(0) */
19701969
return arg2;
19711970
}
19721971

@@ -2338,7 +2337,7 @@ rb_ary_concat(x, y)
23382337
{
23392338
y = to_ary(y);
23402339
if (RARRAY(y)->len > 0) {
2341-
rb_ary_update(x, RARRAY(x)->len, 0, y);
2340+
rb_ary_splice(x, RARRAY(x)->len, 0, y);
23422341
}
23432342
return x;
23442343
}
@@ -2754,8 +2753,6 @@ rb_ary_uniq_bang(ary)
27542753
VALUE hash, v, vv;
27552754
long i, j;
27562755

2757-
rb_ary_modify(ary);
2758-
27592756
hash = ary_make_hash(ary, 0);
27602757

27612758
if (RARRAY(ary)->len == RHASH(hash)->tbl->num_entries) {
@@ -2886,7 +2883,7 @@ flatten(ary, idx, ary2, memo)
28862883
rb_raise(rb_eArgError, "tried to flatten recursive array");
28872884
}
28882885
rb_ary_push(memo, id);
2889-
rb_ary_update(ary, idx, 1, ary2);
2886+
rb_ary_splice(ary, idx, 1, ary2);
28902887
while (i < lim) {
28912888
VALUE tmp;
28922889

@@ -2924,7 +2921,6 @@ rb_ary_flatten_bang(ary)
29242921
int mod = 0;
29252922
VALUE memo = Qnil;
29262923

2927-
rb_ary_modify(ary);
29282924
while (i<RARRAY(ary)->len) {
29292925
VALUE ary2 = RARRAY(ary)->ptr[i];
29302926
VALUE tmp;

numeric.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ flo_divmod(x, y)
715715
VALUE x, y;
716716
{
717717
double fy, div, mod;
718+
volatile VALUE a, b;
718719

719720
switch (TYPE(y)) {
720721
case T_FIXNUM:
@@ -730,9 +731,9 @@ flo_divmod(x, y)
730731
return rb_num_coerce_bin(x, y);
731732
}
732733
flodivmod(RFLOAT(x)->value, fy, &div, &mod);
733-
x = rb_float_new(div);
734-
y = rb_float_new(mod);
735-
return rb_assoc_new(x, y);
734+
a = rb_float_new(div);
735+
b = rb_float_new(mod);
736+
return rb_assoc_new(a, b);
736737
}
737738

738739
/*

process.c

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ static VALUE S_Tms;
124124
static VALUE
125125
get_pid()
126126
{
127+
rb_secure(2);
127128
return INT2FIX(getpid());
128129
}
129130

@@ -147,6 +148,7 @@ get_pid()
147148
static VALUE
148149
get_ppid()
149150
{
151+
rb_secure(2);
150152
#ifdef _WIN32
151153
return INT2FIX(0);
152154
#else
@@ -724,6 +726,7 @@ proc_wait(argc, argv)
724726
VALUE vpid, vflags;
725727
int pid, flags, status;
726728

729+
rb_secure(2);
727730
flags = 0;
728731
rb_scan_args(argc, argv, "02", &vpid, &vflags);
729732
if (argc == 0) {
@@ -798,6 +801,7 @@ proc_waitall()
798801
VALUE result;
799802
int pid, status;
800803

804+
rb_secure(2);
801805
result = rb_ary_new();
802806
#ifdef NO_WAITPID
803807
if (pid_tbl) {
@@ -899,6 +903,7 @@ static VALUE
899903
proc_detach(obj, pid)
900904
VALUE pid;
901905
{
906+
rb_secure(2);
902907
return rb_detach_process(NUM2INT(pid));
903908
}
904909

@@ -1590,6 +1595,7 @@ proc_getpgrp()
15901595
{
15911596
int pgrp;
15921597

1598+
rb_secure(2);
15931599
#if defined(HAVE_GETPGRP) && defined(GETPGRP_VOID)
15941600
pgrp = getpgrp();
15951601
if (pgrp < 0) rb_sys_fail(0);
@@ -1617,12 +1623,13 @@ proc_getpgrp()
16171623
static VALUE
16181624
proc_setpgrp()
16191625
{
1626+
rb_secure(2);
16201627
/* check for posix setpgid() first; this matches the posix */
16211628
/* getpgrp() above. It appears that configure will set SETPGRP_VOID */
16221629
/* even though setpgrp(0,0) would be prefered. The posix call avoids */
16231630
/* this confusion. */
16241631
#ifdef HAVE_SETPGID
1625-
if (setpgid(0,0) < 0) rb_sys_fail(0);
1632+
if (setpgid(0,0) < 0) rb_sys_fail(0);
16261633
#elif defined(HAVE_SETPGRP) && defined(SETPGRP_VOID)
16271634
if (setpgrp() < 0) rb_sys_fail(0);
16281635
#else
@@ -1647,8 +1654,10 @@ proc_getpgid(obj, pid)
16471654
VALUE obj, pid;
16481655
{
16491656
#if defined(HAVE_GETPGID) && !defined(__CHECKER__)
1650-
int i = getpgid(NUM2INT(pid));
1657+
int i;
16511658

1659+
rb_secure(2);
1660+
i = getpgid(NUM2INT(pid));
16521661
if (i < 0) rb_sys_fail(0);
16531662
return INT2NUM(i);
16541663
#else
@@ -1756,6 +1765,7 @@ proc_getpriority(obj, which, who)
17561765
#ifdef HAVE_GETPRIORITY
17571766
int prio, iwhich, iwho;
17581767

1768+
rb_secure(2);
17591769
iwhich = NUM2INT(which);
17601770
iwho = NUM2INT(who);
17611771

@@ -2314,6 +2324,7 @@ p_sys_issetugid(obj)
23142324
VALUE obj;
23152325
{
23162326
#if defined HAVE_ISSETUGID
2327+
rb_secure(2);
23172328
if (issetugid()) {
23182329
return Qtrue;
23192330
} else {
@@ -3454,26 +3465,18 @@ Init_process()
34543465
rb_define_module_function(rb_mProcGID, "rid", proc_getgid, 0);
34553466
rb_define_module_function(rb_mProcUID, "eid", proc_geteuid, 0);
34563467
rb_define_module_function(rb_mProcGID, "eid", proc_getegid, 0);
3457-
rb_define_module_function(rb_mProcUID, "change_privilege",
3458-
p_uid_change_privilege, 1);
3459-
rb_define_module_function(rb_mProcGID, "change_privilege",
3460-
p_gid_change_privilege, 1);
3461-
rb_define_module_function(rb_mProcUID, "grant_privilege",
3462-
p_uid_grant_privilege, 1);
3463-
rb_define_module_function(rb_mProcGID, "grant_privilege",
3464-
p_gid_grant_privilege, 1);
3468+
rb_define_module_function(rb_mProcUID, "change_privilege", p_uid_change_privilege, 1);
3469+
rb_define_module_function(rb_mProcGID, "change_privilege", p_gid_change_privilege, 1);
3470+
rb_define_module_function(rb_mProcUID, "grant_privilege", p_uid_grant_privilege, 1);
3471+
rb_define_module_function(rb_mProcGID, "grant_privilege", p_gid_grant_privilege, 1);
34653472
rb_define_alias(rb_mProcUID, "eid=", "grant_privilege");
34663473
rb_define_alias(rb_mProcGID, "eid=", "grant_privilege");
34673474
rb_define_module_function(rb_mProcUID, "re_exchange", p_uid_exchange, 0);
34683475
rb_define_module_function(rb_mProcGID, "re_exchange", p_gid_exchange, 0);
3469-
rb_define_module_function(rb_mProcUID, "re_exchangeable?",
3470-
p_uid_exchangeable, 0);
3471-
rb_define_module_function(rb_mProcGID, "re_exchangeable?",
3472-
p_gid_exchangeable, 0);
3473-
rb_define_module_function(rb_mProcUID, "sid_available?",
3474-
p_uid_have_saved_id, 0);
3475-
rb_define_module_function(rb_mProcGID, "sid_available?",
3476-
p_gid_have_saved_id, 0);
3476+
rb_define_module_function(rb_mProcUID, "re_exchangeable?", p_uid_exchangeable, 0);
3477+
rb_define_module_function(rb_mProcGID, "re_exchangeable?", p_gid_exchangeable, 0);
3478+
rb_define_module_function(rb_mProcUID, "sid_available?", p_uid_have_saved_id, 0);
3479+
rb_define_module_function(rb_mProcGID, "sid_available?", p_gid_have_saved_id, 0);
34773480
rb_define_module_function(rb_mProcUID, "switch", p_uid_switch, 0);
34783481
rb_define_module_function(rb_mProcGID, "switch", p_gid_switch, 0);
34793482

@@ -3493,15 +3496,10 @@ Init_process()
34933496
rb_define_module_function(rb_mProcID_Syscall, "seteuid", p_sys_seteuid, 1);
34943497
rb_define_module_function(rb_mProcID_Syscall, "setegid", p_sys_setegid, 1);
34953498

3496-
rb_define_module_function(rb_mProcID_Syscall, "setreuid",
3497-
p_sys_setreuid, 2);
3498-
rb_define_module_function(rb_mProcID_Syscall, "setregid",
3499-
p_sys_setregid, 2);
3500-
3501-
rb_define_module_function(rb_mProcID_Syscall, "setresuid",
3502-
p_sys_setresuid, 3);
3503-
rb_define_module_function(rb_mProcID_Syscall, "setresgid",
3504-
p_sys_setresgid, 3);
3505-
rb_define_module_function(rb_mProcID_Syscall, "issetugid",
3506-
p_sys_issetugid, 0);
3499+
rb_define_module_function(rb_mProcID_Syscall, "setreuid", p_sys_setreuid, 2);
3500+
rb_define_module_function(rb_mProcID_Syscall, "setregid", p_sys_setregid, 2);
3501+
3502+
rb_define_module_function(rb_mProcID_Syscall, "setresuid", p_sys_setresuid, 3);
3503+
rb_define_module_function(rb_mProcID_Syscall, "setresgid", p_sys_setresgid, 3);
3504+
rb_define_module_function(rb_mProcID_Syscall, "issetugid", p_sys_issetugid, 0);
35073505
}

0 commit comments

Comments
 (0)