From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 316 invoked by alias); 18 Oct 2016 20:02:52 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 39676 Received: (qmail 19312 invoked from network); 18 Oct 2016 20:02:52 -0000 X-Qmail-Scanner-Diagnostics: from know-smtprelay-omc-7.server.virginmedia.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(80.0.253.71):SA:0(-0.0/5.0):. Processed in 0.530267 secs); 18 Oct 2016 20:02:52 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _smtprelay.virginmedia.com designates 80.0.253.71 as permitted sender) X-Originating-IP: [86.21.219.59] X-Spam: 0 X-Authority: v=2.1 cv=KKyndwxo c=1 sm=1 tr=0 a=utowdAHh8RITBM/6U1BPxA==:117 a=utowdAHh8RITBM/6U1BPxA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=IkcTkHD0fZMA:10 a=ofJ0r1gK3GoDyV5mjvQA:9 a=QEXdDO2ut3YA:10 Date: Tue, 18 Oct 2016 20:57:15 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: printf %q segfault Message-ID: <20161018205715.09036030@ntlworld.com> In-Reply-To: <20161016160312.GA695@fujitsu.shahaf.local2> References: <20161016160312.GA695@fujitsu.shahaf.local2> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sun, 16 Oct 2016 16:03:12 +0000 Daniel Shahaf wrote: > lolilolicon wrote on Sun, Oct 16, 2016 at 22:58:14 +0800: > > The following produces segmentation fault: > >=20 > > printf '%q' =E4=BD=A0 >=20 > The reason 0xA0 is output literally is that the code takes the "if (itok(= *u))" > branch in quotestring(); if it didn't take that branch, it'd behave > correctly. hmm... mumble mumble metafy mumble bin_print mumble mumble total madness mumble metafy shmetafy token shmoken grmph. pws diff --git a/Src/builtin.c b/Src/builtin.c index 8b8b217..2db739f 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -4874,9 +4874,10 @@ bin_print(char *name, char **args, Options ops, int = func) break; case 'q': stringval =3D curarg ? - quotestring(curarg, QT_BACKSLASH_SHOWNULL) : &nullstr; + quotestring(metafy(curarg, curlen, META_USEHEAP), + QT_BACKSLASH_SHOWNULL) : &nullstr; *d =3D 's'; - print_val(stringval); + print_val(unmetafy(stringval, &curlen)); break; case 'd': case 'i': diff --git a/Src/utils.c b/Src/utils.c index db43529..e2657de 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -5916,7 +5916,24 @@ quotestring(const char *s, int instring) } } =20 - if (itok(*u) || instring !=3D QT_BACKSLASH) { + /* + * Now check if the output is unprintable in the + * current character set. + */ + uend =3D u + MB_METACHARLENCONV(u, &cc); + if ( +#ifdef MULTIBYTE_SUPPORT + cc !=3D WEOF && +#endif + WC_ISPRINT(cc)) { + if (dobackslash) + *v++ =3D '\\'; + while (u < uend) { + if (*u =3D=3D Meta) + *v++ =3D *u++; + *v++ =3D *u++; + } + } else if (itok(*u) || instring !=3D QT_BACKSLASH) { /* Needs to be passed straight through. */ if (dobackslash) *v++ =3D '\\'; @@ -5940,25 +5957,6 @@ quotestring(const char *s, int instring) } else *v++ =3D *u++; continue; - } - - /* - * Now check if the output is unprintable in the - * current character set. - */ - uend =3D u + MB_METACHARLENCONV(u, &cc); - if ( -#ifdef MULTIBYTE_SUPPORT - cc !=3D WEOF && -#endif - WC_ISPRINT(cc)) { - if (dobackslash) - *v++ =3D '\\'; - while (u < uend) { - if (*u =3D=3D Meta) - *v++ =3D *u++; - *v++ =3D *u++; - } } else { /* Not printable */ *v++ =3D '$'; diff --git a/Test/D07multibyte.ztst b/Test/D07multibyte.ztst index 1b1d042..3a6e955 100644 --- a/Test/D07multibyte.ztst +++ b/Test/D07multibyte.ztst @@ -579,3 +579,7 @@ 0:Sorting of metafied Polish characters >a =C4=85 b c =C4=87 d e =C4=99 f >a =C4=85 b c =C4=87 d e =C4=99 f + + printf '%q%q\n' =E4=BD=A0=E4=BD=A0 +0:printf %q and quotestring and general metafy / token madness +>=E4=BD=A0=E4=BD=A0