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 3221117D6C89 for ; Wed, 17 Jun 2015 11:39:05 +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 5347EB5D961 for ; Wed, 17 Jun 2015 12:01:32 +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 A1A0197A827 for ; Wed, 17 Jun 2015 12:01:33 +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 XMpHzqu88Rao for ; Wed, 17 Jun 2015 12:01:33 +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 5C88797A826 for ; Wed, 17 Jun 2015 12:01:33 +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 DB186952441 for ; Wed, 17 Jun 2015 12:01:30 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id B7B1D120462; Wed, 17 Jun 2015 12:01:29 +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 C1885120450 for ; Wed, 17 Jun 2015 12:01: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=nn7s8MbHjUXw0sLZ3ofgps3RTEU=; b=Zy30WVFBmiQPvwEzuO E9yHdxln1+caKmUAiAR9NPWDw2jLjHW4j8csF67RYPTcFA00GLoJvfjItkTqvTx2 nupyOJM4VemspXS2nsqMa1wTQ5devIduauSLefup0aBmhDIOynRqR1KEUdu5o7zk tE4OifbflUIQqssrOQXw2Je6g= Received: by filter0533p1mdw1.sendgrid.net with SMTP id filter0533p1mdw1.25469.5580E2FE1D 2015-06-17 03:01:19.048701472 +0000 UTC Received: from herokuapp.com (ec2-54-163-170-90.compute-1.amazonaws.com [54.163.170.90]) by ismtpd-035 (SG) with ESMTP id 14dff76b3c5.117a.20cad9 Wed, 17 Jun 2015 03:01:18 +0000 (UTC) Date: Wed, 17 Jun 2015 03:01:18 +0000 From: kosaki.motohiro@gmail.com 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: 44160 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11269 X-Redmine-Issue-Author: apoikos X-Redmine-Issue-Assignee: kosaki X-Redmine-Sender: kosaki 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS54bJXxvp/651Vf6cl3jblkD0UbzaYBbwOUUf IuZFDGcvqyX1Uq4gaZUr445vlVPy1ZXGxhJX/e8zLzC4stVQEVkAHvAQhsrx7DGhBKkqdsMrm8QpMy kj3nEF/tYx8JDxQFZEVTSBQY1izcOJWp1bkN X-ML-Name: ruby-core X-Mail-Count: 69626 Subject: [ruby-core:69626] [Ruby trunk - Bug #11269] [Assigned] 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 updated by Motohiro KOSAKI. Status changed from Open to Assigned Assignee set to Motohiro KOSAKI I agree. I'll take a look. ---------------------------------------- Bug #11269: ruby_init_setproctitle() should be called before require_libraries() https://bugs.ruby-lang.org/issues/11269#change-52973 * Author: Apollon Oikonomopoulos * Status: Assigned * Priority: Low * Assignee: Motohiro KOSAKI * 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/