ruby-changes:46749
From: normal <ko1@a...>
Date: Wed, 24 May 2017 12:01:49 +0900 (JST)
Subject: [ruby-changes:46749] normal:r58864 (trunk): string.c (rb_str_crypt): fix excessive stack use with crypt_r
normal 2017-05-24 12:01:44 +0900 (Wed, 24 May 2017) New Revision: 58864 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58864 Log: string.c (rb_str_crypt): fix excessive stack use with crypt_r "struct crypt_data" is 131232 bytes on x86-64 GNU/Linux, making it unsafe to use tiny Fiber stack sizes. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 58863) +++ string.c (revision 58864) @@ -8713,7 +8713,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L8713 rb_str_crypt(VALUE str, VALUE salt) { #ifdef HAVE_CRYPT_R - struct crypt_data data; + struct crypt_data *data = ALLOC(struct crypt_data); #else extern char *crypt(const char *, const char *); #endif @@ -8745,16 +8745,24 @@ rb_str_crypt(VALUE str, VALUE salt) https://github.com/ruby/ruby/blob/trunk/string.c#L8745 #endif #ifdef HAVE_CRYPT_R # ifdef HAVE_STRUCT_CRYPT_DATA_INITIALIZED - data.initialized = 0; + data->initialized = 0; # endif - res = crypt_r(s, saltp, &data); + res = crypt_r(s, saltp, data); #else res = crypt(s, saltp); #endif if (!res) { +#ifdef HAVE_CRYPT_R + int err = errno; + xfree(data); + errno = err; +#endif rb_sys_fail("crypt"); } result = rb_str_new_cstr(res); +#ifdef HAVE_CRYPT_R + xfree(data); +#endif FL_SET_RAW(result, OBJ_TAINTED_RAW(str) | OBJ_TAINTED_RAW(salt)); return result; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/