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 #ifdef ENABLE_NUMERIC_STRING
case T_STRING: case T_STRING:
SafeStringValue(v); StringValueCStr(v);
return VpCreateRbObject(strlen(RSTRING_PTR(v)) + VpBaseFig() + 1, rb_check_safe_obj(v);
return VpCreateRbObject(RSTRING_LEN(v) + VpBaseFig() + 1,
RSTRING_PTR(v)); RSTRING_PTR(v));
#endif /* ENABLE_NUMERIC_STRING */ #endif /* ENABLE_NUMERIC_STRING */
@ -430,8 +431,8 @@ BigDecimal_load(VALUE self, VALUE str)
unsigned char ch; unsigned char ch;
unsigned long m=0; unsigned long m=0;
SafeStringValue(str); pch = (unsigned char *)StringValueCStr(str);
pch = (unsigned char *)RSTRING_PTR(str); rb_check_safe_obj(str);
/* First get max prec */ /* First get max prec */
while((*pch) != (unsigned char)'\0' && (ch = *pch++) != (unsigned char)':') { while((*pch) != (unsigned char)'\0' && (ch = *pch++) != (unsigned char)':') {
if(!ISDIGIT(ch)) { 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_scan_args(argc, argv, "01", &f) == 1) {
if (RB_TYPE_P(f, T_STRING)) { if (RB_TYPE_P(f, T_STRING)) {
SafeStringValue(f); psz = StringValueCStr(f);
psz = RSTRING_PTR(f); rb_check_safe_obj(f);
if (*psz == ' ') { if (*psz == ' ') {
fPlus = 1; fPlus = 1;
psz++; psz++;

View file

@ -215,9 +215,10 @@ etc_getpwnam(VALUE obj, VALUE nam)
{ {
#ifdef HAVE_GETPWENT #ifdef HAVE_GETPWENT
struct passwd *pwd; struct passwd *pwd;
const char *p = StringValueCStr(nam);
SafeStringValue(nam); rb_check_safe_obj(nam);
pwd = getpwnam(RSTRING_PTR(nam)); pwd = getpwnam(p);
if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %"PRIsVALUE, nam); if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %"PRIsVALUE, nam);
return setup_passwd(pwd); return setup_passwd(pwd);
#else #else
@ -458,9 +459,10 @@ etc_getgrnam(VALUE obj, VALUE nam)
{ {
#ifdef HAVE_GETGRENT #ifdef HAVE_GETGRENT
struct group *grp; struct group *grp;
const char *p = StringValueCStr(nam);
SafeStringValue(nam); rb_check_safe_obj(nam);
grp = getgrnam(RSTRING_PTR(nam)); grp = getgrnam(p);
if (grp == 0) rb_raise(rb_eArgError, "can't find group for %"PRIsVALUE, nam); if (grp == 0) rb_raise(rb_eArgError, "can't find group for %"PRIsVALUE, nam);
return setup_group(grp); return setup_group(grp);
#else #else

View file

@ -228,7 +228,7 @@ fgdbm_initialize(int argc, VALUE *argv, VALUE obj)
if (!NIL_P(vflags)) if (!NIL_P(vflags))
flags = NUM2INT(vflags); flags = NUM2INT(vflags);
SafeStringValue(file); FilePathValue(file);
#ifdef GDBM_CLOEXEC #ifdef GDBM_CLOEXEC
/* GDBM_CLOEXEC is available since gdbm 1.10. */ /* 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; VALUE tmp;
reinit(); reinit();
StringValue(opt); nkf_split_options(StringValueCStr(opt));
nkf_split_options(RSTRING_PTR(opt));
if (!output_encoding) rb_raise(rb_eArgError, "no output encoding given"); if (!output_encoding) rb_raise(rb_eArgError, "no output encoding given");
switch (nkf_enc_to_index(output_encoding)) { switch (nkf_enc_to_index(output_encoding)) {
@ -153,8 +152,7 @@ rb_nkf_convert(VALUE obj, VALUE opt, VALUE src)
incsize = INCSIZE; incsize = INCSIZE;
input_ctr = 0; input_ctr = 0;
StringValue(src); input = (unsigned char *)StringValuePtr(src);
input = (unsigned char *)RSTRING_PTR(src);
i_len = RSTRING_LENINT(src); i_len = RSTRING_LENINT(src);
tmp = rb_str_new(0, i_len*3 + 10); tmp = rb_str_new(0, i_len*3 + 10);
@ -195,8 +193,7 @@ rb_nkf_guess(VALUE obj, VALUE src)
reinit(); reinit();
input_ctr = 0; input_ctr = 0;
StringValue(src); input = (unsigned char *)StringValuePtr(src);
input = (unsigned char *)RSTRING_PTR(src);
i_len = RSTRING_LENINT(src); i_len = RSTRING_LENINT(src);
guess_f = TRUE; 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); name = rb_str_export_to_enc(name, encoding);
value = rb_str_export_to_enc(value, encoding); value = rb_str_export_to_enc(value, encoding);
tail->handle = (yaml_char_t *)RSTRING_PTR(name); tail->handle = (yaml_char_t *)StringValueCStr(name);
tail->prefix = (yaml_char_t *)RSTRING_PTR(value); tail->prefix = (yaml_char_t *)StringValueCStr(value);
tail++; tail++;
} }

View file

@ -92,7 +92,8 @@ static char **readline_attempted_completion_function(const char *text,
int start, int end); int start, int end);
#define OutputStringValue(str) do {\ #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());\ (str) = rb_str_conv_enc((str), rb_enc_get(str), rb_locale_encoding());\
} while (0)\ } while (0)\

View file

@ -150,6 +150,7 @@ static VALUE mSyslog_close(VALUE self)
static VALUE mSyslog_open(int argc, VALUE *argv, VALUE self) static VALUE mSyslog_open(int argc, VALUE *argv, VALUE self)
{ {
VALUE ident, opt, fac; VALUE ident, opt, fac;
const char *ident_ptr;
if (syslog_opened) { if (syslog_opened) {
rb_raise(rb_eRuntimeError, "syslog already open"); 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)) { if (NIL_P(ident)) {
ident = rb_gv_get("$0"); ident = rb_gv_get("$0");
} }
SafeStringValue(ident); ident_ptr = StringValueCStr(ident);
syslog_ident = strdup(RSTRING_PTR(ident)); rb_check_safe_obj(ident);
syslog_ident = strdup(ident_ptr);
if (NIL_P(opt)) { if (NIL_P(opt)) {
syslog_options = LOG_PID | LOG_CONS; syslog_options = LOG_PID | LOG_CONS;

View file

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