Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: printf %q segfault



On Tue, 18 Oct 2016 20:57:15 +0100
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> On Sun, 16 Oct 2016 16:03:12 +0000
> Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> 
> > lolilolicon wrote on Sun, Oct 16, 2016 at 22:58:14 +0800:
> > > The following produces segmentation fault:
> > > 
> > >     printf '%q' 你
> > 
> > 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.
>
> mumble

I don't think we need the utils.c hunk.  We shouldn't meet an unmetafied
token when the input is handled properly, unless the input actually is
still tokenised.  There's at least one place where this does happen, I
think down in completion.

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 = curarg ?
-		    quotestring(curarg, QT_BACKSLASH_SHOWNULL) : &nullstr;
+		    quotestring(metafy(curarg, curlen, META_USEHEAP),
+				QT_BACKSLASH_SHOWNULL) : &nullstr;
 		*d = 's';
-		print_val(stringval);
+		print_val(unmetafy(stringval, &curlen));
 		break;
 	    case 'd':
 	    case 'i':
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 ą b c ć d e ę f
 >a ą b c ć d e ę f
+
+  printf '%q%q\n' 你你
+0:printf %q and quotestring and general metafy / token madness
+>你你



Messages sorted by: Reverse Date, Date, Thread, Author