zsh-workers
 help / color / mirror / code / Atom feed
From: Jun T <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: [BUG] Misplaced quote in %d printf format crashes Zsh
Date: Tue, 11 Jun 2024 11:24:08 +0900	[thread overview]
Message-ID: <4C5DD888-4539-4910-B633-A7A299AD3320@kba.biglobe.ne.jp> (raw)
In-Reply-To: <CAA=-s3wETNCz5gc7+v0RMxSMzKe9-ogoK-ferwV7XV8G87wUJw@mail.gmail.com>


> 2024/06/09 9:23, Mark J. Reed <markjreed@gmail.com> wrote:
> 
> Duplicated on my Macs; /bin/zsh (5.9) exhibits the crash on both x86_64 and ARM (M2). 
> 
> My locally-built 5.9.0.1-dev does not exhibit the symptom. To see if it was a build thing or the result of a code change, I checked out the zsh-5.9 tag and built that... and it also did not crash. So it seems to be something about Apple's build environment.

Which version of macOS are you using?
I tested on Ventura (13.6.3) and got the same crash with my local build
of both zsh-5.9 and the current git HEAD.

Valgrind (on Linux) tells me that the memory allocated at line 4877 in
builtin.c is lost:
        ASSIGN_MSTREAM(buf,fout);

free(buf) _is_ called at line 5863, but it seems we need fclose(fout)
before freeing the memory. But the macro CLOSE_CLEANLY(fout) does not close
fout since CLOSE_FOUT() does nothing if HAVE_OPEN_MEMSTREAM is defined.

As the comment /* Why do we care about a clean close here? */ suggests,
I guess we can simply close fout if it is not stdout, just like lines
5228, 5265, 5299.



diff --git a/Src/builtin.c b/Src/builtin.c
index 7bfb1ce1d..cd0ee7522 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5455,9 +5455,8 @@ bin_print(char *name, char **args, Options ops, int func)
 		}
 		zwarnnam(name, "%s: invalid directive", start);
 		if (*c) c[1] = save;
-		/* Why do we care about a clean close here? */
-		if (!CLOSE_CLEANLY(fout))
-		    zwarnnam(name, "write error: %e", errno);
+		if (fout != stdout)
+		    fclose(fout);
 #ifdef HAVE_OPEN_MEMSTREAM
 		if (buf)
 		    free(buf);

--
Jun

      reply	other threads:[~2024-06-11  2:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-08 21:12 Philippe Altherr
2024-06-08 23:04 ` Mark J. Reed
2024-06-09  0:23   ` Mark J. Reed
2024-06-11  2:24     ` Jun T [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C5DD888-4539-4910-B633-A7A299AD3320@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).