1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

ext: check if null byte is contained

[ruby-dev:50267] [Bug #13953]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-09-30 08:35:23 +00:00
parent d00c9d7e06
commit 1852b4a866
8 changed files with 26 additions and 23 deletions

View file

@ -289,8 +289,9 @@ again:
#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)
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, VALUE self)
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++;

View file

@ -215,9 +215,10 @@ etc_getpwnam(VALUE obj, VALUE nam)
{
#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)
{
#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

View file

@ -228,7 +228,7 @@ fgdbm_initialize(int argc, VALUE *argv, VALUE obj)
if (!NIL_P(vflags))
flags = NUM2INT(vflags);
SafeStringValue(file);
FilePathValue(file);
#ifdef GDBM_CLOEXEC
/* GDBM_CLOEXEC is available since gdbm 1.10. */

View file

@ -137,8 +137,7 @@ rb_nkf_convert(VALUE obj, VALUE opt, VALUE src)
{
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, VALUE src)
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)
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;

View file

@ -192,8 +192,8 @@ static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
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++;
}

View file

@ -92,7 +92,8 @@ static char **readline_attempted_completion_function(const char *text,
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)\

View file

@ -150,6 +150,7 @@ static VALUE mSyslog_close(VALUE self)
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, VALUE *argv, VALUE self)
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;

View file

@ -11324,7 +11324,7 @@ ripper_initialize(int argc, VALUE *argv, VALUE self)
OBJ_FREEZE(fname);
}
else {
StringValue(fname);
StringValueCStr(fname);
fname = rb_str_new_frozen(fname);
}
parser_initialize(parser);