summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-19 01:42:57 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-19 01:42:57 (GMT)
commitadfeb95c87b31e17c7e1d78d65f9b548f26ccfed (patch)
treed261c2356960ef416223edd1225cc4f6d615a5ff /hash.c
parent5c0df05b92de528a397d29fd9ca5dca534b4c930 (diff)
hash.c: check env vars encoding
* hash.c (get_env_cstr): environment variables must be ASCII compatible, as dummy encodings and wide char encodings are unsupproted now. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50344 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/hash.c b/hash.c
index 122abb3..bd099ce 100644
--- a/hash.c
+++ b/hash.c
@@ -2699,9 +2699,24 @@ env_str_new2(const char *ptr)
return env_str_new(ptr, strlen(ptr));
}
+static void *
+get_env_cstr(VALUE str, const char *name)
+{
+ char *var;
+ rb_encoding *enc = rb_enc_get(str);
+ if (!rb_enc_asciicompat(enc)) {
+ rb_raise(rb_eArgError, "bad environment variable %s: ASCII incompatible encoding: %s",
+ name, rb_enc_name(enc));
+ }
+ var = RSTRING_PTR(str);
+ if (memchr(var, '\0', RSTRING_LEN(str))) {
+ rb_raise(rb_eArgError, "bad environment variable %s: contains null byte", name);
+ }
+ return var;
+}
+
#define get_env_ptr(var, val) \
- (memchr((var = RSTRING_PTR(val)), '\0', RSTRING_LEN(val)) ? \
- rb_raise(rb_eArgError, "bad environment variable " #var) : (void)0)
+ (var = get_env_cstr(val, #var))
static inline const char *
env_name(volatile VALUE *s)