Project

General

Profile

Bug #11386 ยป 0001-string.c-keep-taintedness.patch

nobu (Nobuyoshi Nakada), 07/22/2015 11:23 PM

View differences:

string.c
209 209
}
210 210

  
211 211
static int fstring_cmp(VALUE a, VALUE b);
212
static st_index_t fstring_hash(VALUE str);
212 213

  
213 214
/* in case we restart MVM development, this needs to be per-VM */
214 215
static st_table* frozen_strings;
......
222 223

  
223 224
static const struct st_hash_type fstring_hash_type = {
224 225
    fstring_cmp,
225
    rb_str_hash,
226
    fstring_hash,
226 227
};
227 228

  
228 229
static int
......
245 246
    }
246 247
    else {
247 248
	if (STR_SHARED_P(str)) { /* str should not be shared */
249
	    const int taint = RBASIC(str)->flags & FL_TAINT;
248 250
	    str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), STR_ENC_GET(str));
249
	    OBJ_FREEZE(str);
251
	    RBASIC(str)->flags |= FL_FREEZE | taint;
250 252
	}
251 253
	else {
252 254
	    str = rb_str_new_frozen(str);
......
327 329
static int
328 330
fstring_cmp(VALUE a, VALUE b)
329 331
{
330
    int cmp = rb_str_hash_cmp(a, b);
332
    int cmp;
333

  
334
    cmp = FL_TEST_RAW(b, FL_TAINT) - FL_TEST_RAW(a, FL_TAINT);
335
    if (cmp != 0) {
336
	return cmp;
337
    }
338
    cmp = rb_str_hash_cmp(a, b);
331 339
    if (cmp != 0) {
332 340
	return cmp;
333 341
    }
334 342
    return ENCODING_GET(b) - ENCODING_GET(a);
335 343
}
336 344

  
345
static st_index_t
346
fstring_hash(VALUE str)
347
{
348
    int e = ENCODING_GET(str);
349
    if (e && rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT) {
350
	e = 0;
351
    }
352
    e ^= FL_TEST_RAW(str, FL_TAINT);
353
    return rb_memhash((const void *)RSTRING_PTR(str), RSTRING_LEN(str)) ^ e;
354
}
355

  
337 356
static inline int
338 357
single_byte_optimizable(VALUE str)
339 358
{