zsh-workers
 help / color / mirror / code / Atom feed
From: Jun T <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: Memory error on exporting XPC_SERVICE_NAME from a subshell
Date: Thu, 21 Jul 2022 18:40:17 +0900	[thread overview]
Message-ID: <5B18DF64-99E1-4110-90B4-AEA5D56D62EB@kba.biglobe.ne.jp> (raw)
In-Reply-To: <CAH+w=7YUxvT0w3oETEFc-PHqZ+=qRbW=KX2sqOWzi9S3y1Ra8Q@mail.gmail.com>


> 2022/07/20 9:11, Bart Schaefer <schaefer@brasslantern.com> wrote:
> 
> On Mon, Jul 18, 2022 at 11:46 AM Varun Gandhi <varun@cutcul.us> wrote:
>> 
>> While bisecting my shell configuration for an unrelated issue, I ran into what looks like a use-after-free on exporting XPC_SERVICE_NAME from a subshell.
> 
> This is an error in a MacOS library routine.  Previously seen in zsh
> with constructs like
> % XPC_SERVICE_NAME=0 somecommand

The error occurs at line 5263 in params.c.

I din't know why the problem occurs only with XPC_SERVER_NAME, but
I think we can fix it (at least for relatively new macOS).

On macOS, USE_SET_UNSET_ENV is not defined because setenv(3) had a
strange feature that it removed a leading '=' from the value
(Bart's patch in workers/38432); line 786 in zsh_system.h.

But on my Macs setenv() behaves normally. I've looked into the
source (setenv.c) and manpage (getenv.3) of older macOS (now on
GitHub), and found that Apple has fixed this in macOS Sierra (10.12).
El Capitan (10.11) is the last version with this problem, but Apple
has stopped supporting El Capitan on Oct. 2018. There are very few
Macs still running El Captain or older OS X now (about 2% of Macs?).

So the simplest solution is to ignore El Capitan and older, and
remove !defined(__APPLE__) from the line 786 in zsh_system.h.

Or we can check the macOS version in configure.ac, as in the
patch below (I don't know the way to get the macOS version
from C preprocessor macro).

Or we can use the Peter's patch in workers/38433⁩ (with some fixes?).



diff --git a/Src/zsh_system.h b/Src/zsh_system.h
index 6f4efce96..16f724401 100644
--- a/Src/zsh_system.h
+++ b/Src/zsh_system.h
@@ -783,7 +783,8 @@ extern char **environ;
  * We always need setenv and unsetenv in pairs, because
  * we don't know how to do memory management on the values set.
  */
-#if defined(HAVE_SETENV) && defined(HAVE_UNSETENV) && !defined(__APPLE__)
+#if defined(HAVE_SETENV) && defined(HAVE_UNSETENV) \
+    && !defined(SETENV_MANGLES_EQUAL)
 # define USE_SET_UNSET_ENV
 #endif
 
diff --git a/configure.ac b/configure.ac
index 77e381f50..890ef8dd2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1515,6 +1515,14 @@ else
 zsh_cv_use_xattr=no
 fi])
 
+dnl We don't want to use setenv(3) on El Capitan or older OS X because it
+dnl removes a leading '=' from the value of the environment variable
+AH_TEMPLATE([SETENV_MANGLES_EQUAL],
+[Define to 1 if setenv removes a leading =])
+case $host_os in
+  darwin1[0-5]*) AC_DEFINE(SETENV_MANGLES_EQUAL) ;;
+esac
+
 dnl -------------
 dnl CHECK SIGNALS
 dnl -------------





  reply	other threads:[~2022-07-21  9:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18 18:45 Varun Gandhi
2022-07-20  0:11 ` Bart Schaefer
2022-07-21  9:40   ` Jun T [this message]
2022-07-21 21:11     ` Bart Schaefer

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=5B18DF64-99E1-4110-90B4-AEA5D56D62EB@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).