From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#24206: 25.1; Curly quotes generate invalid strings, leading to a segfault Date: Mon, 15 Aug 2016 11:43:16 -0700 Organization: UCLA Computer Science Department Message-ID: References: <8337m7h1dp.fsf@gnu.org> <83zioffew5.fsf@gnu.org> <83popaf1yz.fsf@gnu.org> <87bn0u3rqc.fsf@linux-m68k.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------37754B6665D14531A11850BB" X-Trace: blaine.gmane.org 1471286662 15578 195.159.176.226 (15 Aug 2016 18:44:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 15 Aug 2016 18:44:22 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 Cc: p.stephani2@gmail.com, johnw@gnu.org, nicolas@petton.fr, 24206@debbugs.gnu.org To: Andreas Schwab , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Aug 15 20:44:17 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZMrw-0003mJ-BM for geb-bug-gnu-emacs@m.gmane.org; Mon, 15 Aug 2016 20:44:16 +0200 Original-Received: from localhost ([::1]:38466 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZMrt-0008BR-Hb for geb-bug-gnu-emacs@m.gmane.org; Mon, 15 Aug 2016 14:44:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZMrn-00088m-7u for bug-gnu-emacs@gnu.org; Mon, 15 Aug 2016 14:44:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bZMri-0007WU-42 for bug-gnu-emacs@gnu.org; Mon, 15 Aug 2016 14:44:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60817) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZMri-0007WQ-18 for bug-gnu-emacs@gnu.org; Mon, 15 Aug 2016 14:44:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bZMrh-0003QY-Pj for bug-gnu-emacs@gnu.org; Mon, 15 Aug 2016 14:44:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 15 Aug 2016 18:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24206 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24206-submit@debbugs.gnu.org id=B24206.147128661313129 (code B ref 24206); Mon, 15 Aug 2016 18:44:01 +0000 Original-Received: (at 24206) by debbugs.gnu.org; 15 Aug 2016 18:43:33 +0000 Original-Received: from localhost ([127.0.0.1]:58529 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZMrF-0003Ph-5G for submit@debbugs.gnu.org; Mon, 15 Aug 2016 14:43:33 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:58098) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZMrD-0003PT-5p for 24206@debbugs.gnu.org; Mon, 15 Aug 2016 14:43:31 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 5DEE216114A; Mon, 15 Aug 2016 11:43:25 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id icsGi8hl4kAz; Mon, 15 Aug 2016 11:43:24 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 2A1B71611D9; Mon, 15 Aug 2016 11:43:24 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Huaw36BTTXY3; Mon, 15 Aug 2016 11:43:24 -0700 (PDT) Original-Received: from [192.168.1.9] (unknown [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id EFD51161109; Mon, 15 Aug 2016 11:43:23 -0700 (PDT) In-Reply-To: <87bn0u3rqc.fsf@linux-m68k.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.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" Xref: news.gmane.org gmane.emacs.bugs:122250 Archived-At: This is a multi-part message in MIME format. --------------37754B6665D14531A11850BB Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Andreas Schwab wrote: > Unibyte strings should not be used for anything but pre-decoding / > post-encoding situations directly after / before doing the actual I/O > operation. Thus substitute-command-keys should never be called with an > undecoded unibyte string. IMHO it would be ok to return something > useless in this case (but it shouldn't cause Emacs to crash, of course)= . Yes. This is in the Elisp manual, which says "We recommend that you never use unibyte buffers and strings except for manipulating encoded text or binary non-text data." Eli Zaretskii wrote: > as the original string is > unibyte, the output of "\200=E2=89=A0", which is multibyte, might not b= e what > the users expect. They might expect "\200\342\211\240" instead. No, as per Andreas's comment and the Elisp reference manual, users should= not=20 expect substitute-command-keys to do that. As long as it doesn't crash on= =20 non-ASCII unibyte data we needn't sweat the details about whether it retu= rns=20 unibyte or multibyte strings for such data. That being said, it shouldn't hurt to return the original string if there= is no=20 substitution. Although I think your first patch in=20 should work, it'd be safer and simpler to=20 backport that part of master, as in the attached patch to emacs-25. --------------37754B6665D14531A11850BB Content-Type: text/x-diff; name="0001-Fix-core-dump-with-unibyte-substitute-command-keys.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-Fix-core-dump-with-unibyte-substitute-command-keys.patc"; filename*1="h" =46rom c4cdebc78783f337cb504b6fea71295cfcaaa516 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 15 Aug 2016 11:34:57 -0700 Subject: [PATCH] Fix core dump with unibyte substitute-command-keys Backport from master (Bug#24206). * src/doc.c (Fsubstitute_command_keys): Convert string to multibyte first, but return the original if there is no substitution. --- src/doc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/doc.c b/src/doc.c index 7cdb0d0..4f5f7a4 100644 --- a/src/doc.c +++ b/src/doc.c @@ -763,6 +763,8 @@ Otherwise, return a new string. */) =20 enum text_quoting_style quoting_style =3D text_quoting_style (); =20 + Lisp_Object orig_string =3D string; + string =3D Fstring_make_multibyte (string); multibyte =3D STRING_MULTIBYTE (string); nchars =3D 0; =20 @@ -1024,7 +1026,7 @@ Otherwise, return a new string. */) } } else - tem =3D string; + tem =3D orig_string; xfree (buf); return tem; } --=20 2.7.4 --------------37754B6665D14531A11850BB--