From 29dfda0011e7ecaf88611679dcf0a3b9dd3f84da Mon Sep 17 00:00:00 2001 From: cremno Date: Tue, 2 Sep 2014 19:09:17 +0200 Subject: [PATCH] check Ruby strings for embedded null bytes The RGSS doesn't do it. But doing it shouldn't be a problem, as it's the correct way. If a game is broken by this commit (unlikely), then the game needs to be fixed as silent truncation is highly unlikely to be wanted. --- binding-mri/binding-util.cpp | 2 +- binding-mri/bitmap-binding.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/binding-mri/binding-util.cpp b/binding-mri/binding-util.cpp index 6312406..5843ad3 100644 --- a/binding-mri/binding-util.cpp +++ b/binding-mri/binding-util.cpp @@ -189,7 +189,7 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...) if (!RB_TYPE_P(tmp, RUBY_T_STRING)) rb_raise(rb_eTypeError, "Argument %d: Expected string", argI); - *s = RSTRING_PTR(tmp); + *s = StringValueCStr(tmp); ++argI; break; diff --git a/binding-mri/bitmap-binding.cpp b/binding-mri/bitmap-binding.cpp index b2448d6..5f805e8 100644 --- a/binding-mri/bitmap-binding.cpp +++ b/binding-mri/bitmap-binding.cpp @@ -32,7 +32,7 @@ DEF_TYPE(Bitmap); static const char *objAsStringPtr(VALUE obj) { VALUE str = rb_obj_as_string(obj); - return RSTRING_PTR(str); + return StringValueCStr(str); } void bitmapInitProps(Bitmap *b, VALUE self)