about summary refs log tree commit diff
path: root/Src/builtin.c
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2016-01-02 13:57:35 -0800
committerBarton E. Schaefer <schaefer@zsh.org>2016-01-02 13:57:35 -0800
commit63c6d1746c5bbe67a4f78517b3a0f532d50672f6 (patch)
treea0f971a220e1450cfd414917b9d97c31bb937b1e /Src/builtin.c
parent03adf524140dce211372124895fa4356376329a8 (diff)
downloadzsh-63c6d1746c5bbe67a4f78517b3a0f532d50672f6.tar.gz
zsh-63c6d1746c5bbe67a4f78517b3a0f532d50672f6.tar.xz
zsh-63c6d1746c5bbe67a4f78517b3a0f532d50672f6.zip
37497: handle NUL bytes in "printf -v".
Diffstat (limited to 'Src/builtin.c')
-rw-r--r--Src/builtin.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 557487c87..04d8f11d9 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4872,17 +4872,20 @@ bin_print(char *name, char **args, Options ops, int func)
 
     if (OPT_ISSET(ops,'z') || OPT_ISSET(ops,'s') || OPT_ISSET(ops,'v')) {
 #ifdef HAVE_OPEN_MEMSTREAM
-	putc(0, fout);
+	putc(0, fout);		/* not needed?  open_memstream() maintains? */
 	fclose(fout);
 	fout = NULL;
+	rcount = mcount;	/* now includes the trailing NUL we added */
 #else
 	rewind(fout);
 	buf = (char *)zalloc(count + 1);
-	fread(buf, count, 1, fout);
-	buf[count] = '\0';
+	rcount = fread(buf, count, 1, fout);
+	if (rcount < count)
+	    zwarnnam(name, "i/o error: %e", errno);
+	buf[rcount] = '\0';
 #endif
 	queue_signals();
-	stringval = metafy(buf, -1, META_REALLOC);
+	stringval = metafy(buf, rcount - 1, META_REALLOC);
 	if (OPT_ISSET(ops,'z')) {
 	    zpushnode(bufstack, stringval);
 	} else if (OPT_ISSET(ops,'v')) {