ruby-changes:47956
From: nobu <ko1@a...>
Date: Sat, 30 Sep 2017 17:35:28 +0900 (JST)
Subject: [ruby-changes:47956] nobu:r60071 (trunk): ext: check if null byte is contained
nobu 2017-09-30 17:35:23 +0900 (Sat, 30 Sep 2017) New Revision: 60071 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60071 Log: ext: check if null byte is contained [ruby-dev:50267] [Bug #13953] Modified files: trunk/ext/bigdecimal/bigdecimal.c trunk/ext/etc/etc.c trunk/ext/gdbm/gdbm.c trunk/ext/nkf/nkf.c trunk/ext/psych/psych_emitter.c trunk/ext/readline/readline.c trunk/ext/syslog/syslog.c trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 60070) +++ parse.y (revision 60071) @@ -11324,7 +11324,7 @@ ripper_initialize(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/parse.y#L11324 OBJ_FREEZE(fname); } else { - StringValue(fname); + StringValueCStr(fname); fname = rb_str_new_frozen(fname); } parser_initialize(parser); Index: ext/syslog/syslog.c =================================================================== --- ext/syslog/syslog.c (revision 60070) +++ ext/syslog/syslog.c (revision 60071) @@ -150,6 +150,7 @@ static VALUE mSyslog_close(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/syslog/syslog.c#L150 static VALUE mSyslog_open(int argc, VALUE *argv, VALUE self) { VALUE ident, opt, fac; + const char *ident_ptr; if (syslog_opened) { rb_raise(rb_eRuntimeError, "syslog already open"); @@ -160,8 +161,9 @@ static VALUE mSyslog_open(int argc, VALU https://github.com/ruby/ruby/blob/trunk/ext/syslog/syslog.c#L161 if (NIL_P(ident)) { ident = rb_gv_get("$0"); } - SafeStringValue(ident); - syslog_ident = strdup(RSTRING_PTR(ident)); + ident_ptr = StringValueCStr(ident); + rb_check_safe_obj(ident); + syslog_ident = strdup(ident_ptr); if (NIL_P(opt)) { syslog_options = LOG_PID | LOG_CONS; Index: ext/bigdecimal/bigdecimal.c =================================================================== --- ext/bigdecimal/bigdecimal.c (revision 60070) +++ ext/bigdecimal/bigdecimal.c (revision 60071) @@ -289,8 +289,9 @@ again: https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L289 #ifdef ENABLE_NUMERIC_STRING case T_STRING: - SafeStringValue(v); - return VpCreateRbObject(strlen(RSTRING_PTR(v)) + VpBaseFig() + 1, + StringValueCStr(v); + rb_check_safe_obj(v); + return VpCreateRbObject(RSTRING_LEN(v) + VpBaseFig() + 1, RSTRING_PTR(v)); #endif /* ENABLE_NUMERIC_STRING */ @@ -430,8 +431,8 @@ BigDecimal_load(VALUE self, VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L431 unsigned char ch; unsigned long m=0; - SafeStringValue(str); - pch = (unsigned char *)RSTRING_PTR(str); + pch = (unsigned char *)StringValueCStr(str); + rb_check_safe_obj(str); /* First get max prec */ while((*pch) != (unsigned char)'\0' && (ch = *pch++) != (unsigned char)':') { if(!ISDIGIT(ch)) { @@ -2037,8 +2038,8 @@ BigDecimal_to_s(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2038 if (rb_scan_args(argc, argv, "01", &f) == 1) { if (RB_TYPE_P(f, T_STRING)) { - SafeStringValue(f); - psz = RSTRING_PTR(f); + psz = StringValueCStr(f); + rb_check_safe_obj(f); if (*psz == ' ') { fPlus = 1; psz++; Index: ext/psych/psych_emitter.c =================================================================== --- ext/psych/psych_emitter.c (revision 60070) +++ ext/psych/psych_emitter.c (revision 60071) @@ -192,8 +192,8 @@ static VALUE start_document(VALUE self, https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L192 name = rb_str_export_to_enc(name, encoding); value = rb_str_export_to_enc(value, encoding); - tail->handle = (yaml_char_t *)RSTRING_PTR(name); - tail->prefix = (yaml_char_t *)RSTRING_PTR(value); + tail->handle = (yaml_char_t *)StringValueCStr(name); + tail->prefix = (yaml_char_t *)StringValueCStr(value); tail++; } Index: ext/etc/etc.c =================================================================== --- ext/etc/etc.c (revision 60070) +++ ext/etc/etc.c (revision 60071) @@ -215,9 +215,10 @@ etc_getpwnam(VALUE obj, VALUE nam) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L215 { #ifdef HAVE_GETPWENT struct passwd *pwd; + const char *p = StringValueCStr(nam); - SafeStringValue(nam); - pwd = getpwnam(RSTRING_PTR(nam)); + rb_check_safe_obj(nam); + pwd = getpwnam(p); if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %"PRIsVALUE, nam); return setup_passwd(pwd); #else @@ -458,9 +459,10 @@ etc_getgrnam(VALUE obj, VALUE nam) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L459 { #ifdef HAVE_GETGRENT struct group *grp; + const char *p = StringValueCStr(nam); - SafeStringValue(nam); - grp = getgrnam(RSTRING_PTR(nam)); + rb_check_safe_obj(nam); + grp = getgrnam(p); if (grp == 0) rb_raise(rb_eArgError, "can't find group for %"PRIsVALUE, nam); return setup_group(grp); #else Index: ext/readline/readline.c =================================================================== --- ext/readline/readline.c (revision 60070) +++ ext/readline/readline.c (revision 60071) @@ -92,7 +92,8 @@ static char **readline_attempted_complet https://github.com/ruby/ruby/blob/trunk/ext/readline/readline.c#L92 int start, int end); #define OutputStringValue(str) do {\ - SafeStringValue(str);\ + StringValueCStr(str);\ + rb_check_safe_obj(str);\ (str) = rb_str_conv_enc((str), rb_enc_get(str), rb_locale_encoding());\ } while (0)\ Index: ext/gdbm/gdbm.c =================================================================== --- ext/gdbm/gdbm.c (revision 60070) +++ ext/gdbm/gdbm.c (revision 60071) @@ -228,7 +228,7 @@ fgdbm_initialize(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/gdbm/gdbm.c#L228 if (!NIL_P(vflags)) flags = NUM2INT(vflags); - SafeStringValue(file); + FilePathValue(file); #ifdef GDBM_CLOEXEC /* GDBM_CLOEXEC is available since gdbm 1.10. */ Index: ext/nkf/nkf.c =================================================================== --- ext/nkf/nkf.c (revision 60070) +++ ext/nkf/nkf.c (revision 60071) @@ -137,8 +137,7 @@ rb_nkf_convert(VALUE obj, VALUE opt, VAL https://github.com/ruby/ruby/blob/trunk/ext/nkf/nkf.c#L137 { VALUE tmp; reinit(); - StringValue(opt); - nkf_split_options(RSTRING_PTR(opt)); + nkf_split_options(StringValueCStr(opt)); if (!output_encoding) rb_raise(rb_eArgError, "no output encoding given"); switch (nkf_enc_to_index(output_encoding)) { @@ -153,8 +152,7 @@ rb_nkf_convert(VALUE obj, VALUE opt, VAL https://github.com/ruby/ruby/blob/trunk/ext/nkf/nkf.c#L152 incsize = INCSIZE; input_ctr = 0; - StringValue(src); - input = (unsigned char *)RSTRING_PTR(src); + input = (unsigned char *)StringValuePtr(src); i_len = RSTRING_LENINT(src); tmp = rb_str_new(0, i_len*3 + 10); @@ -195,8 +193,7 @@ rb_nkf_guess(VALUE obj, VALUE src) https://github.com/ruby/ruby/blob/trunk/ext/nkf/nkf.c#L193 reinit(); input_ctr = 0; - StringValue(src); - input = (unsigned char *)RSTRING_PTR(src); + input = (unsigned char *)StringValuePtr(src); i_len = RSTRING_LENINT(src); guess_f = TRUE; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/