From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 7C30B17DEE4A for ; Tue, 16 Jun 2015 23:38:09 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 31E92B5D954 for ; Wed, 17 Jun 2015 00:00:29 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 0D55F97A83F for ; Wed, 17 Jun 2015 00:00:32 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=sendgrid.me Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ci4qVRQTjUXQ for ; Wed, 17 Jun 2015 00:00:31 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 8E10197A82B for ; Wed, 17 Jun 2015 00:00:31 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 8C7BB952439 for ; Wed, 17 Jun 2015 00:00:28 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id BF7E712045B; Wed, 17 Jun 2015 00:00:27 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id 95CDD12044C for ; Wed, 17 Jun 2015 00:00:23 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=f66mUiXlUgM5H3zi/jZ0JAEAI8c=; b=GLzyMeJWCY25aVz3B2 YvVAVzHEQpJhwXADji4wHsoDIUnqes0Wj9NDVC3BSc6sxc1yI7CPd0bwqiBpCeo/ FaHzCkYQojGuD/kRUXRPZpPvDfK5vNMFwY6GVqPxYVmBBivwa9Fq0R8xtnCVOe1n 1mjvgxVnA0Z0FqpKqF0knXAuM= Received: by filter0629p1mdw1.sendgrid.net with SMTP id filter0629p1mdw1.28264.55803A0282 2015-06-16 15:00:18.917451542 +0000 UTC Received: from herokuapp.com (ec2-54-234-168-41.compute-1.amazonaws.com [54.234.168.41]) by ismtpd-052 (SG) with ESMTP id 14dfce29b18.23ee.1a6a9b for ; Tue, 16 Jun 2015 15:00:18 +0000 (UTC) Date: Tue, 16 Jun 2015 15:00:18 +0000 From: apollon+ruby@skroutz.gr To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 44136 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11269 X-Redmine-Issue-Author: apoikos X-Redmine-Sender: apoikos X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS5zOuCjealq/Z7t+3yoxu7gpU7FU+U9PYNQLc yvAw7WeBGRrfDL0VptLrM7gtEDK82DRw0WXb20+7w++4MmqlW09LZsx1jBscjQnnCMum5nJhyej4ZX K/4VWWhFtG3cMKJMRn/Hik0M+gBnwSrc3TQU X-SendGrid-Contentd-ID: {"test_id":"1434466820"} X-ML-Name: ruby-core X-Mail-Count: 69610 Subject: [ruby-core:69610] [Ruby trunk - Bug #11269] [Open] ruby_init_setproctitle() should be called before require_libraries() X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #11269 has been reported by Apollon Oikonomopoulos. ---------------------------------------- Bug #11269: ruby_init_setproctitle() should be called before require_libraries() https://bugs.ruby-lang.org/issues/11269 * Author: Apollon Oikonomopoulos * Status: Open * Priority: Low * Assignee: * ruby -v: ruby 2.1.5p273 * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- We have come across an issue where `setproctitle` fails to use the whole length of the process's initial environment. It turns out that this is because modules loaded using `-r` are processed before `ruby_init_setproctitle()`. This is easily reproducible using bundler, given the following test script under Linux: ~~~ File.open('/proc/self/cmdline') do |f| @argv_len = f.read.size end File.open('/proc/self/environ') do |f| @env_len = f.read.size end total = @argv_len + @env_len $0 = 'a' * (total + 2) # should not overflow File.open('/proc/self/environ') do |f| env = f.read puts env puts env.size end ~~~ Calling the script directly, we see that setproctitle works correctly: ~~~ $ env -i A_VAR=some_value PATH=/bin:/usr/bin ruby test.rb aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 36 ~~~ In this case setproctitle correctly overwrites the whole environment space available. However, if we require `bundler/setup` (which is what `bundle exec` essentially does), the following happens: ~~~ $ env -i A_VAR=some_value PATH=/bin:/usr/bin ruby -rbundler/setup test.rb aaaaaaaaaaaaaaaPATH=/bin:/usr/bin 36 ~~~ This is because `require 'bundler/setup'` is processed before `ruby_init_setproctitle()` is called and attempts to manipulate `PATH`. While doing so, the new `PATH` string is allocated on the heap and the original pointer in `environ` replaced, thus breaking `ruby_init_setproctitle()`'s expectation to find a contiguous environment block. Perhaps `ruby_init_setproctitle()` can be called before `process_options()`, so that it can process the environment block before a library gets a chance of modifying it. -- https://bugs.ruby-lang.org/