Lines 1-6
Link Here
|
1 |
--- src/common.c.orig 2011-04-06 19:35:39 UTC |
1 |
--- src/common.c.orig 2011-04-06 19:35:39 UTC |
2 |
+++ src/common.c |
2 |
+++ src/common.c |
3 |
@@ -1229,7 +1229,7 @@ bdb_s_new(int argc, VALUE *argv, VALUE o |
3 |
@@ -1080,9 +1080,11 @@ bdb_close(int argc, VALUE *argv, VALUE obj) |
|
|
4 |
bdb_DB *dbst; |
5 |
int flags = 0; |
6 |
|
7 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 4 |
8 |
if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4) { |
9 |
rb_raise(rb_eSecurityError, "Insecure: can't close the database"); |
10 |
} |
11 |
+#endif |
12 |
Data_Get_Struct(obj, bdb_DB, dbst); |
13 |
if (dbst->dbp != NULL) { |
14 |
if (rb_scan_args(argc, argv, "01", &opt)) { |
15 |
@@ -1229,7 +1231,7 @@ bdb_s_new(int argc, VALUE *argv, VALUE obj) |
4 |
if (argc && TYPE(argv[argc - 1]) == T_HASH) { |
16 |
if (argc && TYPE(argv[argc - 1]) == T_HASH) { |
5 |
VALUE v, f = argv[argc - 1]; |
17 |
VALUE v, f = argv[argc - 1]; |
6 |
|
18 |
|
Lines 9-15
Link Here
|
9 |
if (!rb_obj_is_kind_of(v, bdb_cTxn)) { |
21 |
if (!rb_obj_is_kind_of(v, bdb_cTxn)) { |
10 |
rb_raise(bdb_eFatal, "argument of txn must be a transaction"); |
22 |
rb_raise(bdb_eFatal, "argument of txn must be a transaction"); |
11 |
} |
23 |
} |
12 |
@@ -1241,7 +1241,7 @@ bdb_s_new(int argc, VALUE *argv, VALUE o |
24 |
@@ -1241,7 +1243,7 @@ bdb_s_new(int argc, VALUE *argv, VALUE obj) |
13 |
dbst->options |= envst->options & BDB_NO_THREAD; |
25 |
dbst->options |= envst->options & BDB_NO_THREAD; |
14 |
dbst->marshal = txnst->marshal; |
26 |
dbst->marshal = txnst->marshal; |
15 |
} |
27 |
} |
Lines 18-24
Link Here
|
18 |
if (!rb_obj_is_kind_of(v, bdb_cEnv)) { |
30 |
if (!rb_obj_is_kind_of(v, bdb_cEnv)) { |
19 |
rb_raise(bdb_eFatal, "argument of env must be an environnement"); |
31 |
rb_raise(bdb_eFatal, "argument of env must be an environnement"); |
20 |
} |
32 |
} |
21 |
@@ -1254,11 +1254,11 @@ bdb_s_new(int argc, VALUE *argv, VALUE o |
33 |
@@ -1254,11 +1256,11 @@ bdb_s_new(int argc, VALUE *argv, VALUE obj) |
22 |
#if HAVE_CONST_DB_ENCRYPT |
34 |
#if HAVE_CONST_DB_ENCRYPT |
23 |
if (envst && (envst->options & BDB_ENV_ENCRYPT)) { |
35 |
if (envst && (envst->options & BDB_ENV_ENCRYPT)) { |
24 |
VALUE tmp = rb_str_new2("set_flags"); |
36 |
VALUE tmp = rb_str_new2("set_flags"); |
Lines 32-39
Link Here
|
32 |
rb_hash_aset(f, tmp, INT2NUM(NUM2INT(v) | DB_ENCRYPT)); |
44 |
rb_hash_aset(f, tmp, INT2NUM(NUM2INT(v) | DB_ENCRYPT)); |
33 |
} |
45 |
} |
34 |
else { |
46 |
else { |
35 |
@@ -1570,10 +1570,10 @@ bdb_init(int argc, VALUE *argv, VALUE ob |
47 |
@@ -1431,15 +1433,19 @@ bdb_init(int argc, VALUE *argv, VALUE obj) |
|
|
48 |
dbst->options |= BDB_FEEDBACK; |
49 |
} |
36 |
#endif |
50 |
#endif |
|
|
51 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 2 |
52 |
if (flags & DB_TRUNCATE) { |
53 |
rb_secure(2); |
54 |
} |
55 |
+#endif |
56 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 4 |
57 |
if (flags & DB_CREATE) { |
58 |
rb_secure(4); |
59 |
} |
60 |
if (rb_safe_level() >= 4) { |
61 |
flags |= DB_RDONLY; |
62 |
} |
63 |
+#endif |
64 |
#if HAVE_CONST_DB_DUPSORT |
65 |
if (dbst->options & BDB_DUP_COMPARE) { |
66 |
#if HAVE_TYPE_DB_INFO |
67 |
@@ -1570,10 +1576,10 @@ bdb_init(int argc, VALUE *argv, VALUE obj) |
68 |
#endif |
37 |
switch(dbst->type) { |
69 |
switch(dbst->type) { |
38 |
case DB_BTREE: |
70 |
case DB_BTREE: |
39 |
- RBASIC(obj)->klass = bdb_cBtree; |
71 |
- RBASIC(obj)->klass = bdb_cBtree; |
Lines 45-51
Link Here
|
45 |
break; |
77 |
break; |
46 |
case DB_RECNO: |
78 |
case DB_RECNO: |
47 |
{ |
79 |
{ |
48 |
@@ -1581,17 +1581,17 @@ bdb_init(int argc, VALUE *argv, VALUE ob |
80 |
@@ -1581,17 +1587,17 @@ bdb_init(int argc, VALUE *argv, VALUE obj) |
49 |
|
81 |
|
50 |
rb_warning("It's hard to distinguish Recnum with Recno for all versions of Berkeley DB"); |
82 |
rb_warning("It's hard to distinguish Recnum with Recno for all versions of Berkeley DB"); |
51 |
if ((count = bdb_is_recnum(dbst->dbp)) != -1) { |
83 |
if ((count = bdb_is_recnum(dbst->dbp)) != -1) { |
Lines 66-72
Link Here
|
66 |
break; |
98 |
break; |
67 |
#endif |
99 |
#endif |
68 |
default: |
100 |
default: |
69 |
@@ -1635,29 +1635,29 @@ bdb_s_alloc(obj) |
101 |
@@ -1635,29 +1641,29 @@ bdb_s_alloc(obj) |
70 |
dbst->options = BDB_NOT_OPEN; |
102 |
dbst->options = BDB_NOT_OPEN; |
71 |
cl = obj; |
103 |
cl = obj; |
72 |
while (cl) { |
104 |
while (cl) { |
Lines 102-109
Link Here
|
102 |
dbst->type = DB_UNKNOWN; |
134 |
dbst->type = DB_UNKNOWN; |
103 |
break; |
135 |
break; |
104 |
} |
136 |
} |
105 |
@@ -3004,8 +3004,8 @@ bdb_each_kvc(argc, argv, obj, sens, repl |
137 |
@@ -1802,7 +1808,9 @@ bdb_append_internal(argc, argv, obj, flag, retval) |
|
|
138 |
VALUE *a, ary = Qnil; |
139 |
volatile VALUE res = Qnil; |
106 |
|
140 |
|
|
|
141 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 4 |
142 |
rb_secure(4); |
143 |
+#endif |
144 |
if (argc < 1) |
145 |
return obj; |
146 |
INIT_TXN(txnid, obj, dbst); |
147 |
@@ -1885,7 +1893,9 @@ bdb_put(int argc, VALUE *argv, VALUE obj) |
148 |
int ret, flags; |
149 |
db_recno_t recno; |
150 |
|
151 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 4 |
152 |
rb_secure(4); |
153 |
+#endif |
154 |
INIT_TXN(txnid, obj, dbst); |
155 |
flags = 0; |
156 |
a = b = c = Qnil; |
157 |
@@ -2374,7 +2384,9 @@ bdb_consume(obj) |
158 |
int ret; |
159 |
db_recno_t recno; |
160 |
|
161 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 4 |
162 |
rb_secure(4); |
163 |
+#endif |
164 |
INIT_TXN(txnid, obj, dbst); |
165 |
MEMZERO(&key, DBT, 1); |
166 |
MEMZERO(&data, DBT, 1); |
167 |
@@ -2551,7 +2563,9 @@ bdb_del(obj, a) |
168 |
db_recno_t recno; |
169 |
volatile VALUE b = Qnil; |
170 |
|
171 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 4 |
172 |
rb_secure(4); |
173 |
+#endif |
174 |
INIT_TXN(txnid, obj, dbst); |
175 |
#if HAVE_CONST_DB_AUTO_COMMIT |
176 |
if (txnid == NULL && (dbst->options & BDB_AUTO_COMMIT)) { |
177 |
@@ -3004,8 +3018,8 @@ bdb_each_kvc(argc, argv, obj, sens, replace, type) |
178 |
|
107 |
if (argc && TYPE(argv[argc - 1]) == T_HASH) { |
179 |
if (argc && TYPE(argv[argc - 1]) == T_HASH) { |
108 |
VALUE g, f = argv[argc - 1]; |
180 |
VALUE g, f = argv[argc - 1]; |
109 |
- if ((g = rb_hash_aref(f, rb_intern("flags"))) != RHASH(f)->ifnone || |
181 |
- if ((g = rb_hash_aref(f, rb_intern("flags"))) != RHASH(f)->ifnone || |
Lines 113-119
Link Here
|
113 |
flags = NUM2INT(g); |
185 |
flags = NUM2INT(g); |
114 |
} |
186 |
} |
115 |
argc--; |
187 |
argc--; |
116 |
@@ -3323,8 +3323,8 @@ bdb_clear(int argc, VALUE *argv, VALUE o |
188 |
@@ -3053,9 +3067,11 @@ bdb_each_kvc(argc, argv, obj, sens, replace, type) |
|
|
189 |
} |
190 |
#endif |
191 |
type &= ~BDB_ST_ONE; |
192 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 4 |
193 |
if ((type & ~BDB_ST_PREFIX) == BDB_ST_DELETE) { |
194 |
rb_secure(4); |
195 |
} |
196 |
+#endif |
197 |
INIT_TXN(txnid, obj, dbst); |
198 |
#if HAVE_DB_CURSOR_4 |
199 |
bdb_test_error(dbst->dbp->cursor(dbst->dbp, txnid, &dbcp, flags)); |
200 |
@@ -3309,7 +3325,9 @@ bdb_clear(int argc, VALUE *argv, VALUE obj) |
201 |
#endif |
202 |
int flags = 0; |
203 |
|
204 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 4 |
205 |
rb_secure(4); |
206 |
+#endif |
207 |
#if HAVE_ST_DB_TRUNCATE |
208 |
INIT_TXN(txnid, obj, dbst); |
209 |
#if HAVE_CONST_DB_AUTO_COMMIT |
210 |
@@ -3323,8 +3341,8 @@ bdb_clear(int argc, VALUE *argv, VALUE obj) |
117 |
flags = 0; |
211 |
flags = 0; |
118 |
if (argc && TYPE(argv[argc - 1]) == T_HASH) { |
212 |
if (argc && TYPE(argv[argc - 1]) == T_HASH) { |
119 |
VALUE g, f = argv[argc - 1]; |
213 |
VALUE g, f = argv[argc - 1]; |
Lines 124-130
Link Here
|
124 |
flags = NUM2INT(g); |
218 |
flags = NUM2INT(g); |
125 |
} |
219 |
} |
126 |
argc--; |
220 |
argc--; |
127 |
@@ -3348,8 +3348,8 @@ bdb_replace(int argc, VALUE *argv, VALUE |
221 |
@@ -3348,8 +3366,8 @@ bdb_replace(int argc, VALUE *argv, VALUE obj) |
128 |
flags = 0; |
222 |
flags = 0; |
129 |
if (TYPE(argv[argc - 1]) == T_HASH) { |
223 |
if (TYPE(argv[argc - 1]) == T_HASH) { |
130 |
VALUE f = argv[argc - 1]; |
224 |
VALUE f = argv[argc - 1]; |
Lines 135-137
Link Here
|
135 |
flags = NUM2INT(g); |
229 |
flags = NUM2INT(g); |
136 |
} |
230 |
} |
137 |
argc--; |
231 |
argc--; |
|
|
232 |
@@ -3557,8 +3575,10 @@ bdb_sync(obj) |
233 |
{ |
234 |
bdb_DB *dbst; |
235 |
|
236 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 4 |
237 |
if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4) |
238 |
rb_raise(rb_eSecurityError, "Insecure: can't sync the database"); |
239 |
+#endif |
240 |
GetDB(obj, dbst); |
241 |
bdb_test_error(dbst->dbp->sync(dbst->dbp, 0)); |
242 |
return Qtrue; |
243 |
@@ -3884,7 +3904,9 @@ bdb_s_upgrade(int argc, VALUE *argv, VALUE obj) |
244 |
int flags; |
245 |
VALUE val; |
246 |
|
247 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 4 |
248 |
rb_secure(4); |
249 |
+#endif |
250 |
flags = 0; |
251 |
if (rb_scan_args(argc, argv, "11", &a, &b) == 2) { |
252 |
flags = NUM2INT(b); |
253 |
@@ -3908,7 +3930,9 @@ bdb_s_remove(int argc, VALUE *argv, VALUE obj) |
254 |
VALUE a, b, c; |
255 |
char *name, *subname; |
256 |
|
257 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 2 |
258 |
rb_secure(2); |
259 |
+#endif |
260 |
c = bdb_i_create(obj); |
261 |
GetDB(c, dbst); |
262 |
name = subname = NULL; |
263 |
@@ -3936,7 +3960,9 @@ bdb_s_rename(int argc, VALUE *argv, VALUE obj) |
264 |
VALUE a, b, c; |
265 |
char *name, *subname, *newname; |
266 |
|
267 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 2 |
268 |
rb_secure(2); |
269 |
+#endif |
270 |
c = bdb_i_create(obj); |
271 |
GetDB(c, dbst); |
272 |
name = subname = NULL; |
273 |
@@ -4222,7 +4248,9 @@ bdb_verify(int argc, VALUE *argv, VALUE obj) |
274 |
#endif |
275 |
FILE *io = NULL; |
276 |
|
277 |
+#if defined(RUBY_SAFE_LEVEL_MAX) && RUBY_SAFE_LEVEL_MAX >= 4 |
278 |
rb_secure(4); |
279 |
+#endif |
280 |
file = database = NULL; |
281 |
switch(rb_scan_args(argc, argv, "02", &iov, &flagv)) { |
282 |
case 2: |