mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 13:04:13 +02:00
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.
This commit is contained in:
parent
7b6a8b5b54
commit
c5c05460ac
Notes:
git
2019-11-18 08:01:15 +09:00
59 changed files with 283 additions and 751 deletions
|
@ -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")",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue