diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-09-20 19:06:22 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-11-18 01:00:25 +0200 |
commit | c5c05460ac20abcbc0ed686eb4acf06da7a39a79 (patch) | |
tree | 991109a68f3b1cd2e256a936701d3b2badd3ddac /ext/socket | |
parent | 7b6a8b5b54448235e17ed187d9d73f56893e1b6f (diff) |
Warn on access/modify of $SAFE, and remove effects of modifying $SAFE
This removes the security features added by $SAFE = 1, and warns for access
or modification of $SAFE from Ruby-level, as well as warning when calling
all public C functions related to $SAFE.
This modifies some internal functions that took a safe level argument
to no longer take the argument.
rb_require_safe now warns, rb_require_string has been added as a
version that takes a VALUE and does not warn.
One public C function that still takes a safe level argument and that
this doesn't warn for is rb_eval_cmd. We may want to consider
adding an alternative method that does not take a safe level argument,
and warn for rb_eval_cmd.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2476
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/constants.c | 1 | ||||
-rw-r--r-- | ext/socket/raddrinfo.c | 8 | ||||
-rw-r--r-- | ext/socket/unixsocket.c | 1 |
3 files changed, 2 insertions, 8 deletions
diff --git a/ext/socket/constants.c b/ext/socket/constants.c index 6fc862777e..1bbb53b173 100644 --- a/ext/socket/constants.c +++ b/ext/socket/constants.c @@ -28,7 +28,6 @@ constant_arg(VALUE arg, int (*str_to_int)(const char*, long, int*), const char * else if (!NIL_P(tmp = rb_check_string_type(arg))) { arg = tmp; str: - rb_check_safe_obj(arg); ptr = RSTRING_PTR(arg); if (str_to_int(ptr, RSTRING_LEN(arg), &ret) == -1) rb_raise(rb_eSocket, "%s: %s", errmsg, ptr); diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c index 0499b845b5..cc296749b0 100644 --- a/ext/socket/raddrinfo.c +++ b/ext/socket/raddrinfo.c @@ -503,10 +503,6 @@ str_is_number(const char *p) #define str_equal(ptr, len, name) \ ((ptr)[0] == name[0] && \ rb_strlen_lit(name) == (len) && memcmp(ptr, name, len) == 0) -#define SafeStringValueCStr(v) do {\ - StringValueCStr(v);\ - rb_check_safe_obj(v);\ -} while(0) static char* host_str(VALUE host, char *hbuf, size_t hbuflen, int *flags_ptr) @@ -525,7 +521,7 @@ host_str(VALUE host, char *hbuf, size_t hbuflen, int *flags_ptr) const char *name; size_t len; - SafeStringValueCStr(host); + StringValueCStr(host); RSTRING_GETMEM(host, name, len); if (!len || str_equal(name, len, "<any>")) { make_inetaddr(INADDR_ANY, hbuf, hbuflen); @@ -564,7 +560,7 @@ port_str(VALUE port, char *pbuf, size_t pbuflen, int *flags_ptr) const char *serv; size_t len; - SafeStringValueCStr(port); + StringValueCStr(port); RSTRING_GETMEM(port, serv, len); if (len >= pbuflen) { rb_raise(rb_eArgError, "service name too long (%"PRIuSIZE")", diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c index 8bdfc84575..0c3a01d21e 100644 --- a/ext/socket/unixsocket.c +++ b/ext/socket/unixsocket.c @@ -39,7 +39,6 @@ unixsock_path_value(VALUE path) #endif if (isstr) { if (RSTRING_LEN(name) == 0 || RSTRING_PTR(name)[0] == '\0') { - rb_check_safe_obj(name); return name; /* ignore encoding */ } } |