From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.bugs Subject: bug#9412: sprintf-related integer and memory overflow issues Date: Wed, 31 Aug 2011 12:14:13 -0400 Message-ID: <871uw136ei.fsf@stupidchicken.com> References: <4E5D6772.7060208@cs.ucla.edu> <87vcteib8y.fsf@stupidchicken.com> <4E5DCE9B.9060903@cs.ucla.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1314807299 666 80.91.229.12 (31 Aug 2011 16:14:59 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 31 Aug 2011 16:14:59 +0000 (UTC) Cc: 9412@debbugs.gnu.org To: Paul Eggert Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Aug 31 18:14:54 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QynRF-0000ml-HX for geb-bug-gnu-emacs@m.gmane.org; Wed, 31 Aug 2011 18:14:53 +0200 Original-Received: from localhost ([::1]:49107 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QynRE-0001TD-TA for geb-bug-gnu-emacs@m.gmane.org; Wed, 31 Aug 2011 12:14:52 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:52620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QynRB-0001Sx-LN for bug-gnu-emacs@gnu.org; Wed, 31 Aug 2011 12:14:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QynRA-0001K4-HU for bug-gnu-emacs@gnu.org; Wed, 31 Aug 2011 12:14:49 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:34532) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QynRA-0001K0-DR for bug-gnu-emacs@gnu.org; Wed, 31 Aug 2011 12:14:48 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QynUI-0004lG-1o; Wed, 31 Aug 2011 12:18:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Chong Yidong Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 31 Aug 2011 16:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 9412 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 9412-submit@debbugs.gnu.org id=B9412.131480745318267 (code B ref 9412); Wed, 31 Aug 2011 16:18:01 +0000 Original-Received: (at 9412) by debbugs.gnu.org; 31 Aug 2011 16:17:33 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QynTo-0004kZ-ET for submit@debbugs.gnu.org; Wed, 31 Aug 2011 12:17:33 -0400 Original-Received: from vm-emlprdomr-02.its.yale.edu ([130.132.50.143]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QynTl-0004kR-HE for 9412@debbugs.gnu.org; Wed, 31 Aug 2011 12:17:30 -0400 Original-Received: from furball (dhcp-128-36-14-41.central.yale.edu [128.36.14.41]) (authenticated bits=0) by vm-emlprdomr-02.its.yale.edu (8.14.4/8.14.4) with ESMTP id p7VGEDNY005223 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Wed, 31 Aug 2011 12:14:13 -0400 In-Reply-To: <4E5DCE9B.9060903@cs.ucla.edu> (Paul Eggert's message of "Tue, 30 Aug 2011 23:03:07 -0700") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-Scanned-By: MIMEDefang 2.71 on 130.132.50.143 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Wed, 31 Aug 2011 12:18:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:50480 Archived-At: Paul Eggert writes: > In code that is formatting buffers or strings that might be longer > than 2 GiB, we cannot use sprintf etc. We need to fix these issues > somehow. If there's a better way than esprintf etc. please let me > know. > > Anyway, I don't quite follow why using esprintf etc. makes the calling > code much less clear. esprintf is like sprintf, except that on 64-bit > hosts esprintf doesn't have sprintf's 2 GiB limit. If the use of > esprintf is unclear, then surely the use of sprintf is just as > unclear. sprintf (and snprintf) is a well-known function; when someone comes across it in the code, it's not necessary to look it up to know what it's doing. But I'm not clear on this issue of sprintf etc being restricted to 2GB. Could you explain further? Surely such a limitation is a bug in the C library, not Emacs? If so, it should be fixed there, not in Emacs. > Although that used to be true, I expect that platforms lacking > snprintf (e.g., Solaris 2.5.1, IRIX 5.3, OSF/1 4.0) are no longer of > practical importance as Emacs porting targets. > > That being said, it's easy to allay this concern, by using esnprintf > instead of snprintf in all areas of the code that might run on ancient > platforms. The following further patch does this. I think we should add a stub for snprintf in sysdep.c for the !HAVE_SNPRINTF case (which will need configure to set up HAVE_SNPRINTF).